Skip to content

Commit a572335

Browse files
authored
Merge pull request #396 from Superhepper/tpm-resource-manager-tests
Tests RESMGR TPM layer response codes.
2 parents 2822921 + ccedc36 commit a572335

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tss-esapi/tests/integration_tests/error_tests/return_code_tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod esapi_tests;
55
mod fapi_tests;
66
mod muapi_tests;
77
mod resource_manager_tests;
8+
mod resource_manager_tpm_tests;
89
mod sapi_tests;
910
mod tcti_tests;
1011
mod tpm_tests;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2023 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
use std::convert::TryFrom;
4+
use tss_esapi::{
5+
constants::tss::{TPM2_RC_ASYMMETRIC, TPM2_RC_SEQUENCE, TSS2_RESMGR_TPM_RC_LAYER},
6+
error::{ReturnCode, TpmResponseCode},
7+
};
8+
9+
#[test]
10+
fn test_valid_tpm_resmgr_format_zero_response_code() {
11+
let expected_tss_rc = TSS2_RESMGR_TPM_RC_LAYER | TPM2_RC_SEQUENCE;
12+
let actual_rc = ReturnCode::try_from(expected_tss_rc)
13+
.expect("Failed to convert TPM2_RC_SEQUENCE in the TPM RESMGR layer to a ReturnCode.");
14+
15+
if let ReturnCode::TpmResourceManager(actual_tpm_response_code) = actual_rc {
16+
assert!(
17+
matches!(actual_tpm_response_code,TpmResponseCode::FormatZero(_)),
18+
"TPM2_RC_SEQUENCE in the TPM RESMGR layer did not convert into the expected TpmResponseCode"
19+
);
20+
} else {
21+
panic!("The TPM RESMGR layer did not convert into the expected ReturnCode");
22+
}
23+
24+
assert_eq!(
25+
expected_tss_rc,
26+
actual_rc.into(),
27+
"ReturnCode::TpmResourceManager did not convert into the expected TSS2_RC value"
28+
);
29+
}
30+
31+
#[test]
32+
fn test_valid_tpm_resmgr_format_one_response_code() {
33+
let expected_tss_rc = TSS2_RESMGR_TPM_RC_LAYER | TPM2_RC_ASYMMETRIC;
34+
let actual_rc = ReturnCode::try_from(expected_tss_rc)
35+
.expect("Failed to convert TPM2_RC_ASYMMETRIC in the TPM RESMGR layer to a ReturnCode.");
36+
37+
if let ReturnCode::TpmResourceManager(actual_tpm_response_code) = actual_rc {
38+
assert!(
39+
matches!(actual_tpm_response_code, TpmResponseCode::FormatOne(_)),
40+
"TPM2_RC_ASYMMETRIC in the TPM RESMGR layer did not convert into the expected TpmResponseCode"
41+
);
42+
} else {
43+
panic!("The TPM RESMGR layer did not convert into the expected ReturnCode");
44+
}
45+
46+
assert_eq!(
47+
expected_tss_rc,
48+
actual_rc.into(),
49+
"ReturnCode::TpmResourceManager did not convert into the expected TSS2_RC value"
50+
);
51+
}

0 commit comments

Comments
 (0)