Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixest lint errors for the 7.x.y branch. #547

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
**Implemented enhancements:**

- Add evict\_control API to context [\#135](https://github.com/parallaxsecond/rust-tss-esapi/issues/135)
- Depoly Session [\#126](https://github.com/parallaxsecond/rust-tss-esapi/issues/126)
- Deploy Session [\#126](https://github.com/parallaxsecond/rust-tss-esapi/issues/126)
- No private key analog to `load\_external\_rsa\_public\_key` [\#123](https://github.com/parallaxsecond/rust-tss-esapi/issues/123)
- Have two builds with two different TSS lib versions in CI [\#110](https://github.com/parallaxsecond/rust-tss-esapi/issues/110)
- Split between tss-esapi and tss-esapi-sys [\#75](https://github.com/parallaxsecond/rust-tss-esapi/issues/75)
Expand Down
6 changes: 6 additions & 0 deletions tss-esapi/src/abstraction/pcr/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ impl PcrData {
}
}

impl Default for PcrData {
fn default() -> Self {
Self::new()
}
}

impl IntoIterator for PcrData {
type Item = (HashingAlgorithm, PcrBank);
type IntoIter = ::std::vec::IntoIter<(HashingAlgorithm, PcrBank)>;
Expand Down
11 changes: 4 additions & 7 deletions tss-esapi/src/abstraction/transient/key_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use std::convert::TryFrom;
///
/// * it includes all the public parameters of the attested key
/// * can be hashed (in its marshaled form) with the name hash
/// (found by unmarshaling it) to obtain `name`
/// (found by unmarshaling it) to obtain `name`
pub struct MakeCredParams {
/// TPM name of the object being attested
pub name: Vec<u8>,
Expand All @@ -47,10 +47,8 @@ impl TransientKeyContext {
///
/// # Parameters
///
/// * `object` - the object whose TPM name will be included in
/// the credential
/// * `key` - the key to be used to encrypt the secret that wraps
/// the credential
/// * `object` - the object whose TPM name will be included in the credential
/// * `key` - the key to be used to encrypt the secret that wraps the credential
///
/// **Note**: If no `key` is given, the default Endorsement Key
/// will be used.
Expand Down Expand Up @@ -87,8 +85,7 @@ impl TransientKeyContext {
///
/// * `object` - the object whose TPM name is included in the credential
/// * `key` - the key used to encrypt the secret that wraps the credential
/// * `credential_blob` - encrypted credential that will be returned by the
/// TPM
/// * `credential_blob` - encrypted credential that will be returned by the TPM
/// * `secret` - encrypted secret that was used to encrypt the credential
///
/// **Note**: if no `key` is given, the default Endorsement Key
Expand Down
12 changes: 5 additions & 7 deletions tss-esapi/src/abstraction/transient/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ impl KeyMaterial {
/// Structure containing all the defining elements of a TPM key
///
/// - `material` identifies the numeric value of the key object
/// - `params` identifies the algorithm to use on the key and other relevant
/// parameters
/// - `auth` identifies the optional authentication value to be used with the
/// key
/// - `params` identifies the algorithm to use on the key and other relevant parameters
/// - `auth` identifies the optional authentication value to be used with the key
#[derive(Debug, Clone)]
pub struct ObjectWrapper {
pub material: KeyMaterial,
Expand Down Expand Up @@ -662,10 +660,10 @@ impl TransientKeyContextBuilder {
///
/// # Errors
/// * errors are returned if any method calls return an error: `Context::start_auth_session`
/// `Context::create_primary`, `Context::flush_context`, `Context::set_handle_auth`
/// or if an internal error occurs when getting random numbers from the local machine
/// `Context::create_primary`, `Context::flush_context`, `Context::set_handle_auth`
/// or if an internal error occurs when getting random numbers from the local machine
/// * if the root key authentication size is given greater than 32 or if the root key size is
/// not 1024, 2048, 3072 or 4096, a `InvalidParam` wrapper error is returned
/// not 1024, 2048, 3072 or 4096, a `InvalidParam` wrapper error is returned
pub fn build(mut self) -> Result<TransientKeyContext> {
if self.root_key_auth_size > 32 {
return Err(Error::local_error(ErrorKind::WrongParamSize));
Expand Down
6 changes: 6 additions & 0 deletions tss-esapi/src/attributes/command_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,9 @@ impl CommandCodeAttributesBuilder {
self.command_code_attributes.0.try_into()
}
}

impl Default for CommandCodeAttributesBuilder {
fn default() -> Self {
Self::new()
}
}
6 changes: 6 additions & 0 deletions tss-esapi/src/attributes/locality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,9 @@ impl LocalityAttributesBuilder {
Ok(locality_attributes)
}
}

impl Default for LocalityAttributesBuilder {
fn default() -> Self {
Self::new()
}
}
12 changes: 6 additions & 6 deletions tss-esapi/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ use std::ptr::null_mut;
///
/// Code safety-wise, the methods should cover the two kinds of problems that might arise:
/// * in terms of memory safety, all parameters passed down to the TSS are verified and the library
/// stack is then trusted to provide back valid outputs
/// stack is then trusted to provide back valid outputs
/// * in terms of thread safety, all methods require a mutable reference to the context object,
/// ensuring that no two threads can use the context at the same time for an operation (barring use
/// of `unsafe` constructs on the client side)
/// More testing and verification will be added to ensure this.
/// ensuring that no two threads can use the context at the same time for an operation (barring use
/// of `unsafe` constructs on the client side)
/// More testing and verification will be added to ensure this.
///
/// For most methods, if the wrapped TSS call fails and returns a non-zero `TPM2_RC`, a
/// corresponding `Tss2ResponseCode` will be created and returned as an `Error`. Wherever this is
Expand Down Expand Up @@ -86,7 +86,7 @@ impl Context {
///
/// # Errors
/// * if either `Tss2_TctiLdr_Initiialize` or `Esys_Initialize` fail, a corresponding
/// Tss2ResponseCode will be returned
/// Tss2ResponseCode will be returned
pub fn new(tcti_name_conf: TctiNameConf) -> Result<Self> {
let mut esys_context = null_mut();

Expand Down Expand Up @@ -122,7 +122,7 @@ impl Context {
///
/// # Errors
/// * if either `Tss2_TctiLdr_Initiialize` or `Esys_Initialize` fail, a corresponding
/// Tss2ResponseCode will be returned
/// Tss2ResponseCode will be returned
pub fn new_with_tabrmd(tabrmd_conf: TabrmdConfig) -> Result<Self> {
Context::new(TctiNameConf::Tabrmd(tabrmd_conf))
}
Expand Down
2 changes: 1 addition & 1 deletion tss-esapi/src/context/tpm_commands/capability_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Context {
///
/// # Errors
/// * if any of the public parameters is not compatible with the TPM,
/// an `Err` containing the specific unmarshalling error will be returned.
/// an `Err` containing the specific unmarshalling error will be returned.
pub fn test_parms(&mut self, public_parmeters: PublicParameters) -> Result<()> {
let ret = unsafe {
Esys_TestParms(
Expand Down
4 changes: 2 additions & 2 deletions tss-esapi/src/context/tpm_commands/context_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Context {
///
/// # Errors
/// * if conversion from `TPMS_CONTEXT` to `TpmsContext` fails, a `WrongParamSize` error will
/// be returned
/// be returned
pub fn context_save(&mut self, handle: ObjectHandle) -> Result<TpmsContext> {
let mut context_ptr = null_mut();
let ret = unsafe { Esys_ContextSave(self.mut_context(), handle.into(), &mut context_ptr) };
Expand All @@ -34,7 +34,7 @@ impl Context {
///
/// # Errors
/// * if conversion from `TpmsContext` to the native `TPMS_CONTEXT` fails, a `WrongParamSize`
/// error will be returned
/// error will be returned
pub fn context_load(&mut self, context: TpmsContext) -> Result<ObjectHandle> {
let mut loaded_handle = ObjectHandle::None.into();
let ret = unsafe {
Expand Down
13 changes: 7 additions & 6 deletions tss-esapi/src/context/tpm_commands/hierarchy_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ use crate::{
Context, Error, Result,
};
use log::error;
use std::convert::{TryFrom, TryInto};
use std::ptr::null_mut;
use std::{
convert::{TryFrom, TryInto},
mem::size_of,
ptr::null_mut,
};

impl Context {
/// Create a primary key and return the handle.
Expand All @@ -26,7 +29,7 @@ impl Context {
///
/// # Errors
/// * if either of the slices is larger than the maximum size of the native objects, a
/// `WrongParamSize` wrapper error is returned
/// `WrongParamSize` wrapper error is returned
// TODO: Fix when compacting the arguments into a struct
#[allow(clippy::too_many_arguments)]
pub fn create_primary(
Expand All @@ -39,9 +42,7 @@ impl Context {
creation_pcrs: Option<PcrSelectionList>,
) -> Result<CreatePrimaryKeyResult> {
let sensitive_create = TPM2B_SENSITIVE_CREATE {
size: std::mem::size_of::<TPMS_SENSITIVE_CREATE>()
.try_into()
.unwrap(),
size: size_of::<TPMS_SENSITIVE_CREATE>().try_into().unwrap(),
sensitive: TPMS_SENSITIVE_CREATE {
userAuth: auth_value.unwrap_or_default().into(),
data: initial_data.unwrap_or_default().into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Context {
///
/// # Arguments
/// * `pcr_selection_list` - A [PcrSelectionList] that contains pcr slots in
/// different banks that is going to be read.
/// different banks that is going to be read.
///
/// # Details
/// The provided [PcrSelectionList] contains the pcr slots in the different
Expand Down
16 changes: 10 additions & 6 deletions tss-esapi/src/context/tpm_commands/object_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ use crate::{
Context, Error, Result,
};
use log::error;
use std::convert::{TryFrom, TryInto};
use std::ptr::{null, null_mut};
use std::{
convert::{TryFrom, TryInto},
mem::size_of,
ptr::{null, null_mut},
};

impl Context {
/// Create a key and return the handle.
Expand All @@ -37,7 +40,7 @@ impl Context {
///
/// # Errors
/// * if either of the slices is larger than the maximum size of the native objects, a
/// `WrongParamSize` wrapper error is returned
/// `WrongParamSize` wrapper error is returned
// TODO: Fix when compacting the arguments into a struct
#[allow(clippy::too_many_arguments)]
pub fn create(
Expand All @@ -50,9 +53,8 @@ impl Context {
creation_pcrs: Option<PcrSelectionList>,
) -> Result<CreateKeyResult> {
let sensitive_create = TPM2B_SENSITIVE_CREATE {
size: std::mem::size_of::<TPMS_SENSITIVE_CREATE>()
.try_into()
.unwrap(), // will not fail on targets of at least 16 bits
#[allow(unused_qualifications)]
size: size_of::<TPMS_SENSITIVE_CREATE>().try_into().unwrap(), // will not fail on targets of at least 16 bits
sensitive: TPMS_SENSITIVE_CREATE {
userAuth: auth_value.unwrap_or_default().into(),
data: sensitive_data.unwrap_or_default().into(),
Expand Down Expand Up @@ -146,6 +148,7 @@ impl Context {
) -> Result<KeyHandle> {
let mut object_handle = ObjectHandle::None.into();
let ret = unsafe {
#[allow(unexpected_cfgs)]
Esys_LoadExternal(
self.mut_context(),
self.optional_session_1(),
Expand Down Expand Up @@ -183,6 +186,7 @@ impl Context {
) -> Result<KeyHandle> {
let mut object_handle = ObjectHandle::None.into();
let ret = unsafe {
#[allow(unexpected_cfgs)]
Esys_LoadExternal(
self.mut_context(),
self.optional_session_1(),
Expand Down
3 changes: 2 additions & 1 deletion tss-esapi/src/context/tpm_commands/symmetric_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ impl Context {
let mut out_hash_ptr = null_mut();
let mut validation_ptr = null_mut();
let ret = unsafe {
#[allow(unexpected_cfgs)]
Esys_Hash(
self.mut_context(),
self.optional_session_1(),
Expand Down Expand Up @@ -345,7 +346,7 @@ impl Context {
///
/// # Errors
/// * if any of the public parameters is not compatible with the TPM,
/// an `Err` containing the specific unmarshalling error will be returned.
/// an `Err` containing the specific unmarshalling error will be returned.
pub fn hmac(
&mut self,
handle: ObjectHandle,
Expand Down
4 changes: 2 additions & 2 deletions tss-esapi/src/handles/tpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use std::stringify;
/// Enum representing the different types of tpm handles
/// of a TPM handle.
///
/// * Details
/// # Details
/// The TPM handles are used
/// to reference shielded locations of various
/// types within the TPM.
///
/// * OBS
/// N.B:
/// Do not confuse the TpmHandles with the
/// ESYS [ObjectHandle](crate::handles::ObjectHandle).
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
Expand Down
22 changes: 11 additions & 11 deletions tss-esapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@
//!
//! # Notes on code safety:
//! * thread safety is ensured by the required mutability of the `Context` structure within the
//! methods implemented on it; thus, in an otherwise safe app commands cannot be dispatched in
//! parallel for the same context; whether multithreading with multiple context objects is possible
//! depends on the TCTI used and this is the responsibility of the crate client to establish.
//! methods implemented on it; thus, in an otherwise safe app commands cannot be dispatched in
//! parallel for the same context; whether multithreading with multiple context objects is possible
//! depends on the TCTI used and this is the responsibility of the crate client to establish.
//! * the `unsafe` keyword is used to denote methods that could panic, crash or cause undefined
//! behaviour. Whenever this is the case, the properties that need to be checked against
//! parameters before passing them in will be stated in the documentation of the method.
//! behaviour. Whenever this is the case, the properties that need to be checked against
//! parameters before passing them in will be stated in the documentation of the method.
//! * `unsafe` blocks within this crate need to be documented through code comments if they
//! are not covered by the points of trust described here.
//! are not covered by the points of trust described here.
//! * the TSS2.0 library that this crate links to is trusted to return consistent values and to
//! not crash or lead to undefined behaviour when presented with valid arguments.
//! not crash or lead to undefined behaviour when presented with valid arguments.
//! * the `Mbox` crate is trusted to perform operations safely on the pointers provided to it, if
//! the pointers are trusted to be valid.
//! the pointers are trusted to be valid.
//! * methods not marked `unsafe` are trusted to behave safely, potentially returning appropriate
//! error messages when encountering any problems.
//! error messages when encountering any problems.
//! * whenever `unwrap`, `expect`, `panic` or derivatives of these are used, they need to be
//! thoroughly documented and justified - preferably `unwrap` and `expect` should *never* fail
//! during normal operation.
//! thoroughly documented and justified - preferably `unwrap` and `expect` should *never* fail
//! during normal operation.
//! * these rules can be broken in test-only code and in tests.
//!
//! # Logging
Expand Down
7 changes: 5 additions & 2 deletions tss-esapi/src/structures/attestation/attest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use crate::{
Error, Result, WrapperErrorKind,
};
use log::error;
use std::convert::{TryFrom, TryInto};
use std::{
convert::{TryFrom, TryInto},
mem::size_of,
};

/// Type for holding attestation data
///
Expand Down Expand Up @@ -119,7 +122,7 @@ impl TryFrom<TPMS_ATTEST> for Attest {
}

impl Marshall for Attest {
const BUFFER_SIZE: usize = std::mem::size_of::<TPMS_ATTEST>();
const BUFFER_SIZE: usize = size_of::<TPMS_ATTEST>();

/// Produce a marshalled [`TPMS_ATTEST`]
fn marshall(&self) -> Result<Vec<u8>> {
Expand Down
6 changes: 4 additions & 2 deletions tss-esapi/src/structures/buffers/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
use log::error;
use std::{
convert::{TryFrom, TryInto},
mem::size_of,
ops::Deref,
};
use zeroize::Zeroize;
Expand All @@ -25,7 +26,8 @@ use zeroize::Zeroize;
pub struct PublicBuffer(Vec<u8>);

impl PublicBuffer {
pub const MAX_SIZE: usize = std::mem::size_of::<TPMT_PUBLIC>();
#[allow(unused_qualifications)]
pub const MAX_SIZE: usize = size_of::<TPMT_PUBLIC>();

pub fn value(&self) -> &[u8] {
&self.0
Expand Down Expand Up @@ -117,7 +119,7 @@ impl TryFrom<Public> for PublicBuffer {
}

impl Marshall for PublicBuffer {
const BUFFER_SIZE: usize = std::mem::size_of::<TPM2B_PUBLIC>();
const BUFFER_SIZE: usize = size_of::<TPM2B_PUBLIC>();

/// Produce a marshalled [`TPM2B_PUBLIC`]
fn marshall(&self) -> Result<Vec<u8>> {
Expand Down
5 changes: 3 additions & 2 deletions tss-esapi/src/structures/buffers/sensitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
use log::error;
use std::{
convert::{TryFrom, TryInto},
mem::size_of,
ops::Deref,
};
use zeroize::Zeroize;
Expand All @@ -24,7 +25,7 @@ use zeroize::Zeroize;
pub struct SensitiveBuffer(Vec<u8>);

impl SensitiveBuffer {
pub const MAX_SIZE: usize = std::mem::size_of::<TPMT_SENSITIVE>();
pub const MAX_SIZE: usize = size_of::<TPMT_SENSITIVE>();

pub fn value(&self) -> &[u8] {
&self.0
Expand Down Expand Up @@ -116,7 +117,7 @@ impl TryFrom<Sensitive> for SensitiveBuffer {
}

impl Marshall for SensitiveBuffer {
const BUFFER_SIZE: usize = std::mem::size_of::<TPM2B_SENSITIVE>();
const BUFFER_SIZE: usize = size_of::<TPM2B_SENSITIVE>();

/// Produce a marshalled [`TPM2B_SENSITIVE`]
fn marshall(&self) -> Result<Vec<u8>> {
Expand Down
Loading
Loading