Skip to content

Commit

Permalink
Fixes lint errors reported in rust 1.75.
Browse files Browse the repository at this point in the history
Signed-off-by: Jesper Brynolf <[email protected]>
  • Loading branch information
Superhepper committed Dec 31, 2023
1 parent 2dfc315 commit 1bdc1cf
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Context {
)
},
|ret| {
error!("Error when generating ECDH keypair: {:#010X}", ret);
error!("Error when generating ECDH key pair: {:#010X}", ret);
},
)?;

Expand Down
4 changes: 2 additions & 2 deletions tss-esapi/src/context/tpm_commands/symmetric_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Context {
/// # context
/// # .tr_set_auth(primary_key_handle.into(), primary_key_auth)
/// # .expect("Failed to set auth from primary key handle.");
/// # // Create symmetric key objhect attributes
/// # // Create symmetric key object attributes
/// # let symmetric_key_object_attributes = ObjectAttributesBuilder::new()
/// # .with_user_with_auth(true)
/// # .with_sign_encrypt(true)
Expand Down Expand Up @@ -162,7 +162,7 @@ impl Context {
/// false, // false, indicates that the data should be encrypted.
/// SymmetricMode::Cfb, // The symmetric mode of the encryption.
/// data.clone(), // The data that is to be encrypted.
/// initial_value.clone(), // Initial value needed by the algorithmen.
/// initial_value.clone(), // Initial value needed by the algorithm.
/// )
/// .expect("Call to encrypt_decrypt_2 failed when encrypting data")
/// });
Expand Down
12 changes: 4 additions & 8 deletions tss-esapi/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@ impl TryFrom<TPMS_CONTEXT> for TpmsContext {
hierarchy: tss2_context.hierarchy,
context_blob: tss2_context.contextBlob.buffer.to_vec(),
};
context.context_blob.truncate(
tss2_context
.contextBlob
.size
.try_into()
.map_err(|_| Error::local_error(WrapperErrorKind::WrongParamSize))?,
);
context
.context_blob
.truncate(tss2_context.contextBlob.size.into());
Ok(context)
}
}
Expand Down Expand Up @@ -321,7 +317,7 @@ pub fn get_tpm_vendor(context: &mut Context) -> Result<String> {
]
.iter()
// Retrieve property values
.map(|propid| context.get_tpm_property(*propid))
.map(|prop_id| context.get_tpm_property(*prop_id))
// Collect and return an error if we got one
.collect::<Result<Vec<Option<u32>>>>()?
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
mod test_policy_signed {
use crate::common::{create_ctx_with_session, signing_key_pub};
use std::{
convert::{TryFrom, TryInto},
time::Duration,
};
use std::{convert::TryFrom, time::Duration};
use tss_esapi::{
attributes::SessionAttributesBuilder,
constants::SessionType,
Expand Down Expand Up @@ -70,7 +67,7 @@ mod test_policy_signed {
context
.policy_signed(
trial_policy_session,
key_handle.try_into().unwrap(),
key_handle.into(),
nonce_tpm,
cp_hash_a,
policy_ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ fn test_certify_into_tpm_type_conversions() {
let expected_tpms_certify_info = TPMS_CERTIFY_INFO {
name: Name::try_from(vec![0xffu8; 64])
.expect("Failed to create name")
.try_into()
.expect("Failed to convert name to tss type"),
.into(),
qualifiedName: Name::try_from(vec![0x0fu8; 64])
.expect("Failed to create qualified name")
.try_into()
.expect("failed to convert qualified name to tss type"),
.into(),
};

let tpmu_attest: TPMU_ATTEST = AttestInfo::Certify {
Expand Down Expand Up @@ -55,7 +53,7 @@ fn test_quote_into_tpm_type_conversions() {
],
)
.build()
.expect("Failed to createm PcrSelectionList")
.expect("Failed to create PcrSelectionList")
.into(),
pcrDigest: Digest::try_from(vec![0xffu8; 32])
.expect("Failed to create digest")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ fn test_attest_with_certify_info_into_tpm_type_conversions() {
Name::try_from(vec![0x0fu8; 64]).expect("Failed to create qualified name");
let expected_attest_info = AttestInfo::Certify {
info: TPMS_CERTIFY_INFO {
name: expected_certify_info_name
.clone()
.try_into()
.expect("Failed to convert name to tss type"),
qualifiedName: expected_certify_info_qualified_name
.clone()
.try_into()
.expect("failed to convert qualified name to tss type"),
name: expected_certify_info_name.clone().into(),
qualifiedName: expected_certify_info_qualified_name.clone().into(),
}
.try_into()
.expect("Failed to convert TPMS_CERTIFY_INFO to CertifyInfo"),
Expand Down Expand Up @@ -74,7 +68,7 @@ fn test_attest_with_quote_info_into_tpm_type_conversions() {
],
)
.build()
.expect("Failed to createm PcrSelectionList");
.expect("Failed to create PcrSelectionList");
let expected_pcr_digest = Digest::try_from(vec![0xffu8; 32]).expect("Failed to create digest");
let expected_attest_info = AttestInfo::Quote {
info: TPMS_QUOTE_INFO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const ATTEST_BUFFER_MAX_SIZE: usize = 2304;

#[test]
fn test_max_sized_data() {
let _ = AttestBuffer::try_from(vec![0xffu8; ATTEST_BUFFER_MAX_SIZE])
let _ = AttestBuffer::try_from(vec![0xFFu8; ATTEST_BUFFER_MAX_SIZE])
.expect("Failed to parse buffer if maximum size as AttestBuffer");
}

#[test]
fn test_to_large_data() {
assert_eq!(
AttestBuffer::try_from(vec![0xffu8; ATTEST_BUFFER_MAX_SIZE + 1])
AttestBuffer::try_from(vec![0xFFu8; ATTEST_BUFFER_MAX_SIZE + 1])
.expect_err("Converting a buffer that is to large did not produce an error"),
Error::WrapperError(WrapperErrorKind::WrongParamSize),
"Wrong kind of error when converting a buffer with size {} to AttestBuffer",
Expand All @@ -28,7 +28,7 @@ fn test_default() {
{
let attest_buffer: AttestBuffer = Default::default();
let expected: TPM2B_ATTEST = Default::default();
let actual = TPM2B_ATTEST::try_from(attest_buffer).unwrap();
let actual = TPM2B_ATTEST::from(attest_buffer);
assert_eq!(expected.size, actual.size);
assert_eq!(
expected.attestationData.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod test_auth {
{
let auth: Auth = Default::default();
let expected: TPM2B_AUTH = Default::default();
let actual = TPM2B_AUTH::try_from(auth).unwrap();
let actual = TPM2B_AUTH::from(auth);
assert_eq!(expected.size, actual.size);
assert_eq!(
expected.buffer.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::convert::TryFrom;
use tss_esapi::structures::Data;
use tss_esapi::tss2_esys::TPM2B_DATA;
// The TPM2B_DATA has aisze of 64 bytes
// The TPM2B_DATA has a size of 64 bytes
mod test_data {
use super::*;

Expand All @@ -27,7 +27,7 @@ mod test_data {
{
let data: Data = Default::default();
let expected: TPM2B_DATA = Default::default();
let actual = TPM2B_DATA::try_from(data).unwrap();
let actual = TPM2B_DATA::from(data);
assert_eq!(expected.size, actual.size);
assert_eq!(
expected.buffer.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod test_auth {
{
let max_buffer: MaxBuffer = Default::default();
let expected: TPM2B_MAX_BUFFER = Default::default();
let actual = TPM2B_MAX_BUFFER::try_from(max_buffer).unwrap();
let actual = TPM2B_MAX_BUFFER::from(max_buffer);
assert_eq!(expected.size, actual.size);
assert_eq!(
expected.buffer.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn test_default() {
{
let nonce: Nonce = Default::default();
let expected: TPM2B_NONCE = Default::default();
let actual = TPM2B_NONCE::try_from(nonce).unwrap();
let actual = TPM2B_NONCE::from(nonce);
assert_eq!(expected.size, actual.size);
assert_eq!(
expected.buffer.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SENSITIVE_CREATE_BUFFER_MAX_SIZE: usize = 324;

#[test]
fn test_byte_conversions() {
let expected_buffer = vec![0xffu8; SENSITIVE_CREATE_BUFFER_MAX_SIZE];
let expected_buffer = vec![0xFFu8; SENSITIVE_CREATE_BUFFER_MAX_SIZE];
let sensitive_create_buffer_from_slice =
SensitiveCreateBuffer::try_from(expected_buffer.as_slice())
.expect("Failed to create SensitiveCreateBuffer from byte slice");
Expand All @@ -34,7 +34,7 @@ fn test_byte_conversions() {

#[test]
fn test_conversions_of_over_sized_byte_data() {
let over_sized_buffer = vec![0xffu8; SENSITIVE_CREATE_BUFFER_MAX_SIZE + 1];
let over_sized_buffer = vec![0xFFu8; SENSITIVE_CREATE_BUFFER_MAX_SIZE + 1];

assert_eq!(
SensitiveCreateBuffer::try_from(over_sized_buffer.as_slice())
Expand Down Expand Up @@ -94,14 +94,14 @@ fn test_tpm_types_conversions() {
.expect("Failed to create SensitiveCreate from SensitiveCreateBuffer");
assert_eq!(
expected_sensitive_create, actual_sensitive_create,
"SensitiveCreate converted from SensiticeCreateBuffer did not contain expected values."
"SensitiveCreate converted from SensitiveCreateBuffer did not contain expected values."
);
let actual_tpm2b_senstive_create_buffer =
let actual_tpm2b_sensitive_create_buffer =
TPM2B_SENSITIVE_CREATE::try_from(actual_sensitive_create_buffer)
.expect("Failed to create TPM2B_SENSITIVE_CREATE from SensitiveCreateBuffer");
crate::common::ensure_tpm2b_sensitive_create_equality(
&expected_tpm2b_sensitive_create,
&actual_tpm2b_senstive_create_buffer,
&actual_tpm2b_sensitive_create_buffer,
);
}

Expand All @@ -121,6 +121,6 @@ fn test_marshall_unmarshall() {
expected_sensitive_create,
SensitiveCreate::try_from(expected_sensitive_create_buffer)
.expect("Failed to convert from SensitiveCreateBuffer to SensitiveCreate"),
"SensitiveCreate converted from SenstiveCreateBuffer did not contain the expected values"
"SensitiveCreate converted from SensitiveCreateBuffer did not contain the expected values"
);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0

use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;
use tss_esapi::{
structures::{CertifyInfo, Name},
tss2_esys::TPMS_CERTIFY_INFO,
};

#[test]
fn test_conversion() {
let expected_name = Name::try_from(vec![0xffu8; 64]).expect("Failed to create name");
let expected_name = Name::try_from(vec![0xFFu8; 64]).expect("Failed to create name");
let expected_qualified_name =
Name::try_from(vec![0x0fu8; 64]).expect("Failed to create qualified name");
let expected_tpms_certify_info = TPMS_CERTIFY_INFO {
name: expected_name
.clone()
.try_into()
.expect("Failed to convert name to tss type"),
qualifiedName: expected_qualified_name
.clone()
.try_into()
.expect("failed to convert qualified name to tss type"),
name: expected_name.clone().into(),
qualifiedName: expected_qualified_name.clone().into(),
};

let certify_info = CertifyInfo::try_from(expected_tpms_certify_info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ fn test_conversions() {
)
});

let tpml_cc: TPML_CC = command_code_list
.try_into()
.expect("Failed to convert CommandCodeList into TPML_CC");
let tpml_cc: TPML_CC = command_code_list.into();

assert_eq!(
expected_command_codes.len(),
Expand Down Expand Up @@ -111,9 +109,7 @@ fn test_valid_conversion_vector() {
)
});

let actual_command_codes: Vec<CommandCode> = command_code_list
.try_into()
.expect("Failed to convert CommandCodeList to Vec<CommandCode>");
let actual_command_codes: Vec<CommandCode> = command_code_list.into();

assert_eq!(
expected_command_codes.len(),
Expand Down Expand Up @@ -157,7 +153,7 @@ fn test_invalid_conversion_from_tpml_cc() {
assert_eq!(
Error::WrapperError(WrapperErrorKind::InvalidParam),
CommandCodeList::try_from(invalid_value).expect_err(
"Converting a TPML_CC with invalid values to ComandCodeList did not produce an error"
"Converting a TPML_CC with invalid values to CommandCodeList did not produce an error"
),
"Converting invalid TPML_CC did not produce the expected error",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ fn test_conversions() {
);
});

let tpml_ecc_curve =
TPML_ECC_CURVE::try_from(ecc_curve_list).expect("failed to convert to TPML_ECC_CURVE");
let tpml_ecc_curve = TPML_ECC_CURVE::from(ecc_curve_list);
assert_eq!(
expected_ecc_curves.len(),
tpml_ecc_curve.count as usize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn test_conversions() {
);
});

let tpml_handle = TPML_HANDLE::try_from(handle_list).expect("failed to convert to TPML_HANDLE");
let tpml_handle = TPML_HANDLE::from(handle_list);
assert_eq!(
expected_handles.len(),
tpml_handle.count as usize,
Expand Down
Loading

0 comments on commit 1bdc1cf

Please sign in to comment.