Skip to content

Commit aa68349

Browse files
authored
Merge pull request #474 from Superhepper/type-ambiguity-in-tests
Fixes some causes for type ambiguity in tests.
2 parents 29b7278 + a84d3e3 commit aa68349

25 files changed

+159
-107
lines changed

tss-esapi/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
overflowing_literals,
1010
path_statements,
1111
patterns_in_fns_without_body,
12-
private_in_public,
12+
private_bounds,
13+
private_interfaces,
1314
unconditional_recursion,
1415
unused,
1516
unused_allocation,

tss-esapi/tests/integration_tests/attributes_tests/command_code_attributes_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn test_conversions_non_vendor_specific() {
9292

9393
assert_eq!(
9494
expected.0,
95-
command_code_attributes.into(),
95+
TPMA_CC::from(command_code_attributes),
9696
"CommandCodeAttributes did not convert into the expected TPMA_CC value"
9797
);
9898
}
@@ -162,7 +162,7 @@ fn test_conversions_vendor_specific() {
162162

163163
assert_eq!(
164164
expected.0,
165-
command_code_attributes.into(),
165+
TPMA_CC::from(command_code_attributes),
166166
"CommandCodeAttributes did not convert into the expected TPMA_CC value"
167167
);
168168
}
@@ -307,7 +307,7 @@ fn test_builder() {
307307

308308
assert_eq!(
309309
expected.0,
310-
actual.into(),
310+
TPMA_CC::from(actual),
311311
"CommandCodeAttributes built using the builder did not convert into the expected TPMA_CC value"
312312
);
313313
}

tss-esapi/tests/integration_tests/attributes_tests/session_attributes_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2022 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
3-
use std::convert::{TryFrom, TryInto};
3+
use std::convert::TryFrom;
44
use tss_esapi::{
55
attributes::{SessionAttributes, SessionAttributesBuilder, SessionAttributesMask},
66
tss2_esys::TPMA_SESSION,
@@ -18,7 +18,7 @@ macro_rules! test_valid_conversion {
1818
);
1919
assert_eq!(
2020
tpma_session,
21-
session_attributes.try_into().expect("Failed to convert SessionAttributes into TPMA_SESSION_ATTRIBUTE."),
21+
TPMA_SESSION::try_from(session_attributes).expect("Failed to convert SessionAttributes into TPMA_SESSION_ATTRIBUTE."),
2222
"Converting session attributes with {} set did not convert into the expected TPMA_SESSION value", std::stringify!($method),
2323
);
2424
};
@@ -30,7 +30,7 @@ macro_rules! test_valid_mask_conversion {
3030
let session_attributes_mask = SessionAttributesMask::try_from(tpma_session).expect("Failed to convert TPMA_SESSION into SessionAttributesMask");
3131
assert_eq!(
3232
tpma_session,
33-
session_attributes_mask.try_into().expect("Failed to convert SessionAttributesMask into TPMA_SESSION"),
33+
TPMA_SESSION::try_from(session_attributes_mask).expect("Failed to convert SessionAttributesMask into TPMA_SESSION"),
3434
"Converting session attributes mask with {} set did not convert into the expected TPMA_SESSION value", $attribute,
3535
);
3636
};

tss-esapi/tests/integration_tests/constants_tests/algorithm_tests.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
// Copyright 2021 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
33
use std::convert::TryFrom;
4-
use tss_esapi::constants::{
5-
tss::{
6-
TPM2_ALG_AES, TPM2_ALG_CAMELLIA, TPM2_ALG_CBC, TPM2_ALG_CFB, TPM2_ALG_CMAC, TPM2_ALG_CTR,
7-
TPM2_ALG_ECB, TPM2_ALG_ECC, TPM2_ALG_ECDAA, TPM2_ALG_ECDH, TPM2_ALG_ECDSA, TPM2_ALG_ECMQV,
8-
TPM2_ALG_ECSCHNORR, TPM2_ALG_ERROR, TPM2_ALG_HMAC, TPM2_ALG_KDF1_SP800_108,
9-
TPM2_ALG_KDF1_SP800_56A, TPM2_ALG_KDF2, TPM2_ALG_KEYEDHASH, TPM2_ALG_MGF1, TPM2_ALG_NULL,
10-
TPM2_ALG_OAEP, TPM2_ALG_OFB, TPM2_ALG_RSA, TPM2_ALG_RSAES, TPM2_ALG_RSAPSS,
11-
TPM2_ALG_RSASSA, TPM2_ALG_SHA1, TPM2_ALG_SHA256, TPM2_ALG_SHA384, TPM2_ALG_SHA3_256,
12-
TPM2_ALG_SHA3_384, TPM2_ALG_SHA3_512, TPM2_ALG_SHA512, TPM2_ALG_SM2, TPM2_ALG_SM3_256,
13-
TPM2_ALG_SM4, TPM2_ALG_SYMCIPHER, TPM2_ALG_TDES, TPM2_ALG_XOR,
4+
use tss_esapi::{
5+
constants::{
6+
tss::{
7+
TPM2_ALG_AES, TPM2_ALG_CAMELLIA, TPM2_ALG_CBC, TPM2_ALG_CFB, TPM2_ALG_CMAC,
8+
TPM2_ALG_CTR, TPM2_ALG_ECB, TPM2_ALG_ECC, TPM2_ALG_ECDAA, TPM2_ALG_ECDH,
9+
TPM2_ALG_ECDSA, TPM2_ALG_ECMQV, TPM2_ALG_ECSCHNORR, TPM2_ALG_ERROR, TPM2_ALG_HMAC,
10+
TPM2_ALG_KDF1_SP800_108, TPM2_ALG_KDF1_SP800_56A, TPM2_ALG_KDF2, TPM2_ALG_KEYEDHASH,
11+
TPM2_ALG_MGF1, TPM2_ALG_NULL, TPM2_ALG_OAEP, TPM2_ALG_OFB, TPM2_ALG_RSA,
12+
TPM2_ALG_RSAES, TPM2_ALG_RSAPSS, TPM2_ALG_RSASSA, TPM2_ALG_SHA1, TPM2_ALG_SHA256,
13+
TPM2_ALG_SHA384, TPM2_ALG_SHA3_256, TPM2_ALG_SHA3_384, TPM2_ALG_SHA3_512,
14+
TPM2_ALG_SHA512, TPM2_ALG_SM2, TPM2_ALG_SM3_256, TPM2_ALG_SM4, TPM2_ALG_SYMCIPHER,
15+
TPM2_ALG_TDES, TPM2_ALG_XOR,
16+
},
17+
AlgorithmIdentifier,
1418
},
15-
AlgorithmIdentifier,
19+
tss2_esys::TPM2_ALG_ID,
1620
};
1721
macro_rules! test_conversion {
1822
($tpm_alg_id:ident, $algorithm:ident) => {
19-
assert_eq!($tpm_alg_id, AlgorithmIdentifier::$algorithm.into());
23+
assert_eq!(
24+
$tpm_alg_id,
25+
TPM2_ALG_ID::from(AlgorithmIdentifier::$algorithm)
26+
);
2027
assert_eq!(
2128
AlgorithmIdentifier::$algorithm,
2229
AlgorithmIdentifier::try_from($tpm_alg_id).expect(&format!(

tss-esapi/tests/integration_tests/constants_tests/return_code_tests/base_return_code_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro_rules! test_valid_conversion {
3535
($tss_rc_base:ident, $base_error_item:ident) => {
3636
assert_eq!(
3737
$tss_rc_base as u16,
38-
BaseError::$base_error_item.into(),
38+
u16::from(BaseError::$base_error_item),
3939
"Failed to convert {} into the expected TSS2_RC value {}",
4040
std::stringify!(BaseError::$base_error_item),
4141
std::stringify!($tss_rc_base),

tss-esapi/tests/integration_tests/constants_tests/return_code_tests/return_code_layer_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro_rules! test_valid_conversion {
2727

2828
assert_eq!(
2929
tss_rc_layer_unshifted,
30-
ReturnCodeLayer::$return_code_layer.into(),
30+
u8::from(ReturnCodeLayer::$return_code_layer),
3131
"Conversion of {} into TSS_RC did not result in the expected {}",
3232
std::stringify!(ReturnCodeLayer::$return_code_layer),
3333
std::stringify!($tss_rc_layer)

tss-esapi/tests/integration_tests/constants_tests/return_code_tests/tpm_format_one_error_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ macro_rules! test_valid_conversion {
3030
let tpm_rc = TpmFormatOneRc($tpm_fmt1_rc as u16);
3131
assert_eq!(
3232
tpm_rc.error_number(),
33-
TpmFormatOneError::$item.into(),
33+
u8::from(TpmFormatOneError::$item),
3434
"Conversion of {} into a u16 value without TPM2_RC_FMT1 did not produce the expected value {}",
3535
std::stringify!(TpmFormatOneError::$item),
3636
tpm_rc.error_number()

tss-esapi/tests/integration_tests/constants_tests/return_code_tests/tpm_format_zero_error_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ macro_rules! test_valid_conversion {
3131
let tpm_rc = TpmFormatZeroErrorRc($tpm_ver1_rc as u16);
3232
assert_eq!(
3333
tpm_rc.error_number(),
34-
TpmFormatZeroError::$item.into(),
34+
u8::from(TpmFormatZeroError::$item),
3535
"Conversion of {} into a u16 value without TPM2_RC_VER1 did not produce the expected value {}",
3636
std::stringify!(TpmFormatZeroError::$item),
3737
tpm_rc.error_number()

tss-esapi/tests/integration_tests/constants_tests/return_code_tests/tpm_format_zero_warning_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ macro_rules! test_valid_conversion {
3030
let tpm_rc = TpmFormatZeroWarningRc($tpm_warn_rc as u16);
3131
assert_eq!(
3232
tpm_rc.error_number(),
33-
TpmFormatZeroWarning::$item.into(),
33+
u8::from(TpmFormatZeroWarning::$item),
3434
"Conversion of {} into a u16 value without TPM2_RC_VER1 did not produce the expected value {}",
3535
std::stringify!(TpmFormatZeroWarning::$item),
3636
tpm_rc.error_number()

tss-esapi/tests/integration_tests/context_tests/tpm_commands/integrity_collection_pcr_tests.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ mod test_pcr_read {
151151
use tss_esapi::{
152152
interface_types::algorithm::HashingAlgorithm,
153153
structures::{PcrSelectionListBuilder, PcrSlot},
154-
tss2_esys::{TPM2_SHA256_DIGEST_SIZE, TPML_PCR_SELECTION},
154+
tss2_esys::{TPM2_SHA256_DIGEST_SIZE, TPMI_ALG_HASH, TPML_PCR_SELECTION},
155155
};
156156

157157
#[test]
@@ -167,7 +167,10 @@ mod test_pcr_read {
167167
assert_eq!(pcr_selection_list.len(), 1);
168168
assert_eq!(input.count as usize, pcr_selection_list.len());
169169
assert_eq!(input.pcrSelections[0].sizeofSelect, 3);
170-
assert_eq!(input.pcrSelections[0].hash, HashingAlgorithm::Sha256.into());
170+
assert_eq!(
171+
input.pcrSelections[0].hash,
172+
TPMI_ALG_HASH::from(HashingAlgorithm::Sha256)
173+
);
171174
assert_eq!(input.pcrSelections[0].pcrSelect[0], 0b0000_0001);
172175
assert_eq!(input.pcrSelections[0].pcrSelect[1], 0b0000_0000);
173176
assert_eq!(input.pcrSelections[0].pcrSelect[2], 0b0000_0000);

0 commit comments

Comments
 (0)