Skip to content

Commit f41e572

Browse files
committed
Fixest lint errors for the 7.x.y branch.
This commit addresses most of the problems reported by the Clippy lint tool when building with rust version 1.80 for the code in the 7.x.y branch. Signed-off-by: Jesper Brynolf <[email protected]>
1 parent c825820 commit f41e572

File tree

25 files changed

+121
-77
lines changed

25 files changed

+121
-77
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@
422422
**Implemented enhancements:**
423423

424424
- Add evict\_control API to context [\#135](https://github.com/parallaxsecond/rust-tss-esapi/issues/135)
425-
- Depoly Session [\#126](https://github.com/parallaxsecond/rust-tss-esapi/issues/126)
425+
- Deploy Session [\#126](https://github.com/parallaxsecond/rust-tss-esapi/issues/126)
426426
- No private key analog to `load\_external\_rsa\_public\_key` [\#123](https://github.com/parallaxsecond/rust-tss-esapi/issues/123)
427427
- Have two builds with two different TSS lib versions in CI [\#110](https://github.com/parallaxsecond/rust-tss-esapi/issues/110)
428428
- Split between tss-esapi and tss-esapi-sys [\#75](https://github.com/parallaxsecond/rust-tss-esapi/issues/75)

tss-esapi/src/abstraction/pcr/data.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ impl PcrData {
101101
}
102102
}
103103

104+
impl Default for PcrData {
105+
fn default() -> Self {
106+
Self::new()
107+
}
108+
}
109+
104110
impl IntoIterator for PcrData {
105111
type Item = (HashingAlgorithm, PcrBank);
106112
type IntoIter = ::std::vec::IntoIter<(HashingAlgorithm, PcrBank)>;

tss-esapi/src/abstraction/transient/key_attestation.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::convert::TryFrom;
3131
///
3232
/// * it includes all the public parameters of the attested key
3333
/// * can be hashed (in its marshaled form) with the name hash
34-
/// (found by unmarshaling it) to obtain `name`
34+
/// (found by unmarshaling it) to obtain `name`
3535
pub struct MakeCredParams {
3636
/// TPM name of the object being attested
3737
pub name: Vec<u8>,
@@ -47,10 +47,8 @@ impl TransientKeyContext {
4747
///
4848
/// # Parameters
4949
///
50-
/// * `object` - the object whose TPM name will be included in
51-
/// the credential
52-
/// * `key` - the key to be used to encrypt the secret that wraps
53-
/// the credential
50+
/// * `object` - the object whose TPM name will be included in the credential
51+
/// * `key` - the key to be used to encrypt the secret that wraps the credential
5452
///
5553
/// **Note**: If no `key` is given, the default Endorsement Key
5654
/// will be used.
@@ -87,8 +85,7 @@ impl TransientKeyContext {
8785
///
8886
/// * `object` - the object whose TPM name is included in the credential
8987
/// * `key` - the key used to encrypt the secret that wraps the credential
90-
/// * `credential_blob` - encrypted credential that will be returned by the
91-
/// TPM
88+
/// * `credential_blob` - encrypted credential that will be returned by the TPM
9289
/// * `secret` - encrypted secret that was used to encrypt the credential
9390
///
9491
/// **Note**: if no `key` is given, the default Endorsement Key

tss-esapi/src/abstraction/transient/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ impl KeyMaterial {
9595
/// Structure containing all the defining elements of a TPM key
9696
///
9797
/// - `material` identifies the numeric value of the key object
98-
/// - `params` identifies the algorithm to use on the key and other relevant
99-
/// parameters
100-
/// - `auth` identifies the optional authentication value to be used with the
101-
/// key
98+
/// - `params` identifies the algorithm to use on the key and other relevant parameters
99+
/// - `auth` identifies the optional authentication value to be used with the key
102100
#[derive(Debug, Clone)]
103101
pub struct ObjectWrapper {
104102
pub material: KeyMaterial,
@@ -662,10 +660,10 @@ impl TransientKeyContextBuilder {
662660
///
663661
/// # Errors
664662
/// * errors are returned if any method calls return an error: `Context::start_auth_session`
665-
/// `Context::create_primary`, `Context::flush_context`, `Context::set_handle_auth`
666-
/// or if an internal error occurs when getting random numbers from the local machine
663+
/// `Context::create_primary`, `Context::flush_context`, `Context::set_handle_auth`
664+
/// or if an internal error occurs when getting random numbers from the local machine
667665
/// * if the root key authentication size is given greater than 32 or if the root key size is
668-
/// not 1024, 2048, 3072 or 4096, a `InvalidParam` wrapper error is returned
666+
/// not 1024, 2048, 3072 or 4096, a `InvalidParam` wrapper error is returned
669667
pub fn build(mut self) -> Result<TransientKeyContext> {
670668
if self.root_key_auth_size > 32 {
671669
return Err(Error::local_error(ErrorKind::WrongParamSize));

tss-esapi/src/attributes/command_code.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ impl CommandCodeAttributesBuilder {
143143
self.command_code_attributes.0.try_into()
144144
}
145145
}
146+
147+
impl Default for CommandCodeAttributesBuilder {
148+
fn default() -> Self {
149+
Self::new()
150+
}
151+
}

tss-esapi/src/attributes/locality.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,9 @@ impl LocalityAttributesBuilder {
125125
Ok(locality_attributes)
126126
}
127127
}
128+
129+
impl Default for LocalityAttributesBuilder {
130+
fn default() -> Self {
131+
Self::new()
132+
}
133+
}

tss-esapi/src/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ use std::ptr::null_mut;
3333
///
3434
/// Code safety-wise, the methods should cover the two kinds of problems that might arise:
3535
/// * in terms of memory safety, all parameters passed down to the TSS are verified and the library
36-
/// stack is then trusted to provide back valid outputs
36+
/// stack is then trusted to provide back valid outputs
3737
/// * in terms of thread safety, all methods require a mutable reference to the context object,
38-
/// ensuring that no two threads can use the context at the same time for an operation (barring use
39-
/// of `unsafe` constructs on the client side)
40-
/// More testing and verification will be added to ensure this.
38+
/// ensuring that no two threads can use the context at the same time for an operation (barring use
39+
/// of `unsafe` constructs on the client side)
40+
/// More testing and verification will be added to ensure this.
4141
///
4242
/// For most methods, if the wrapped TSS call fails and returns a non-zero `TPM2_RC`, a
4343
/// corresponding `Tss2ResponseCode` will be created and returned as an `Error`. Wherever this is
@@ -86,7 +86,7 @@ impl Context {
8686
///
8787
/// # Errors
8888
/// * if either `Tss2_TctiLdr_Initiialize` or `Esys_Initialize` fail, a corresponding
89-
/// Tss2ResponseCode will be returned
89+
/// Tss2ResponseCode will be returned
9090
pub fn new(tcti_name_conf: TctiNameConf) -> Result<Self> {
9191
let mut esys_context = null_mut();
9292

@@ -122,7 +122,7 @@ impl Context {
122122
///
123123
/// # Errors
124124
/// * if either `Tss2_TctiLdr_Initiialize` or `Esys_Initialize` fail, a corresponding
125-
/// Tss2ResponseCode will be returned
125+
/// Tss2ResponseCode will be returned
126126
pub fn new_with_tabrmd(tabrmd_conf: TabrmdConfig) -> Result<Self> {
127127
Context::new(TctiNameConf::Tabrmd(tabrmd_conf))
128128
}

tss-esapi/src/context/tpm_commands/capability_commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Context {
7979
///
8080
/// # Errors
8181
/// * if any of the public parameters is not compatible with the TPM,
82-
/// an `Err` containing the specific unmarshalling error will be returned.
82+
/// an `Err` containing the specific unmarshalling error will be returned.
8383
pub fn test_parms(&mut self, public_parmeters: PublicParameters) -> Result<()> {
8484
let ret = unsafe {
8585
Esys_TestParms(

tss-esapi/src/context/tpm_commands/context_management.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Context {
1717
///
1818
/// # Errors
1919
/// * if conversion from `TPMS_CONTEXT` to `TpmsContext` fails, a `WrongParamSize` error will
20-
/// be returned
20+
/// be returned
2121
pub fn context_save(&mut self, handle: ObjectHandle) -> Result<TpmsContext> {
2222
let mut context_ptr = null_mut();
2323
let ret = unsafe { Esys_ContextSave(self.mut_context(), handle.into(), &mut context_ptr) };
@@ -34,7 +34,7 @@ impl Context {
3434
///
3535
/// # Errors
3636
/// * if conversion from `TpmsContext` to the native `TPMS_CONTEXT` fails, a `WrongParamSize`
37-
/// error will be returned
37+
/// error will be returned
3838
pub fn context_load(&mut self, context: TpmsContext) -> Result<ObjectHandle> {
3939
let mut loaded_handle = ObjectHandle::None.into();
4040
let ret = unsafe {

tss-esapi/src/context/tpm_commands/hierarchy_commands.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ use crate::{
1515
Context, Error, Result,
1616
};
1717
use log::error;
18-
use std::convert::{TryFrom, TryInto};
19-
use std::ptr::null_mut;
18+
use std::{
19+
convert::{TryFrom, TryInto},
20+
mem::size_of,
21+
ptr::null_mut,
22+
};
2023

2124
impl Context {
2225
/// Create a primary key and return the handle.
@@ -26,7 +29,7 @@ impl Context {
2629
///
2730
/// # Errors
2831
/// * if either of the slices is larger than the maximum size of the native objects, a
29-
/// `WrongParamSize` wrapper error is returned
32+
/// `WrongParamSize` wrapper error is returned
3033
// TODO: Fix when compacting the arguments into a struct
3134
#[allow(clippy::too_many_arguments)]
3235
pub fn create_primary(
@@ -39,9 +42,7 @@ impl Context {
3942
creation_pcrs: Option<PcrSelectionList>,
4043
) -> Result<CreatePrimaryKeyResult> {
4144
let sensitive_create = TPM2B_SENSITIVE_CREATE {
42-
size: std::mem::size_of::<TPMS_SENSITIVE_CREATE>()
43-
.try_into()
44-
.unwrap(),
45+
size: size_of::<TPMS_SENSITIVE_CREATE>().try_into().unwrap(),
4546
sensitive: TPMS_SENSITIVE_CREATE {
4647
userAuth: auth_value.unwrap_or_default().into(),
4748
data: initial_data.unwrap_or_default().into(),

0 commit comments

Comments
 (0)