Skip to content

Commit

Permalink
chore: apply linter recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsastrix committed Aug 22, 2024
1 parent dd2ac34 commit 4b33e00
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 60 deletions.
12 changes: 6 additions & 6 deletions src/token/cose/encrypted/encrypt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub trait CoseEncryptBuilderExt: Sized {
/// # Examples
///
/// Refer to [the documentation for the CoseEncrypt extensions](CoseEncryptExt) for examples.
fn try_encrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_encrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -84,7 +84,7 @@ pub trait CoseEncryptBuilderExt: Sized {
}

impl CoseEncryptBuilderExt for CoseEncryptBuilder {
fn try_encrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_encrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -342,7 +342,7 @@ pub trait CoseEncryptExt {
/// )
/// );
/// ```
fn try_decrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_decrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -427,7 +427,7 @@ pub trait CoseEncryptExt {
fn try_decrypt_with_recipients<
B: KeyDistributionCryptoBackend + EncryptCryptoBackend,
CKP: KeyProvider,
CAP: AadProvider + ?Sized,
CAP: AadProvider,
>(
&self,
backend: &mut B,
Expand All @@ -437,7 +437,7 @@ pub trait CoseEncryptExt {
}

impl CoseEncryptExt for CoseEncrypt {
fn try_decrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_decrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -468,7 +468,7 @@ impl CoseEncryptExt for CoseEncrypt {
fn try_decrypt_with_recipients<
B: KeyDistributionCryptoBackend + EncryptCryptoBackend,
CKP: KeyProvider,
CAP: AadProvider + ?Sized,
CAP: AadProvider,
>(
&self,
backend: &mut B,
Expand Down
4 changes: 2 additions & 2 deletions src/token/cose/encrypted/encrypt/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<B: CryptoBackend + EncryptCryptoBackend + KeyDistributionCryptoBackend> Cos
if let Some(partial_iv) = determine_header_param(
encrypt_cfg.protected.as_ref(),
encrypt_cfg.unprotected.as_ref(),
|v| (!v.partial_iv.is_empty()).then(|| &v.partial_iv),
|v| (!v.partial_iv.is_empty()).then_some(&v.partial_iv),
) {
enc_key.base_iv = calculate_base_iv(
encrypt_cfg
Expand Down Expand Up @@ -169,7 +169,7 @@ impl<B: CryptoBackend + EncryptCryptoBackend + KeyDistributionCryptoBackend> Cos
if let Some(partial_iv) = determine_header_param(
test_case.protected.as_ref(),
test_case.unprotected.as_ref(),
|v| (!v.partial_iv.is_empty()).then(|| &v.partial_iv),
|v| (!v.partial_iv.is_empty()).then_some(&v.partial_iv),
) {
key_with_alg.base_iv = calculate_base_iv(
test_case
Expand Down
8 changes: 4 additions & 4 deletions src/token/cose/encrypted/encrypt0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub trait CoseEncrypt0BuilderExt: Sized {
/// # Examples
///
/// Refer to [the documentation for the CoseEncrypt0 extensions](CoseEncrypt0Ext) for examples.
fn try_encrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_encrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -74,7 +74,7 @@ pub trait CoseEncrypt0BuilderExt: Sized {
}

impl CoseEncrypt0BuilderExt for CoseEncrypt0Builder {
fn try_encrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_encrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -256,7 +256,7 @@ pub trait CoseEncrypt0Ext {
/// )
/// );
/// ```
fn try_decrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_decrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -266,7 +266,7 @@ pub trait CoseEncrypt0Ext {
}

impl CoseEncrypt0Ext for CoseEncrypt0 {
fn try_decrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_decrypt<B: EncryptCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down
8 changes: 4 additions & 4 deletions src/token/cose/encrypted/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub fn aes_ccm_algorithm_tag_len<BE: Display>(
}
}

fn determine_and_check_aes_params<'a, 'b, BE: Display>(
fn determine_and_check_aes_params<'a, BE: Display>(
alg: iana::Algorithm,
parsed_key: CoseParsedKey<'a, BE>,
protected: Option<&Header>,
Expand All @@ -351,11 +351,11 @@ fn determine_and_check_aes_params<'a, 'b, BE: Display>(
let symm_key = key::ensure_valid_aes_key::<BE>(alg, parsed_key)?;

let iv = header_util::determine_header_param(protected, unprotected, |v| {
(!v.iv.is_empty()).then(|| &v.iv)
(!v.iv.is_empty()).then_some(&v.iv)
});

let partial_iv = header_util::determine_header_param(protected, unprotected, |v| {
(!v.partial_iv.is_empty()).then(|| &v.partial_iv)
(!v.partial_iv.is_empty()).then_some(&v.partial_iv)
});

let expected_iv_len = aes_algorithm_iv_len(alg)?;
Expand Down Expand Up @@ -392,7 +392,7 @@ fn determine_and_check_aes_params<'a, 'b, BE: Display>(
let mut message_iv = vec![0u8; expected_iv_len];

// Left-pad the Partial IV with zeros to the length of IV
message_iv[(expected_iv_len - partial_iv.len())..].copy_from_slice(&partial_iv);
message_iv[(expected_iv_len - partial_iv.len())..].copy_from_slice(partial_iv);
// XOR the padded Partial IV with the Context IV.
message_iv
.iter_mut()
Expand Down
12 changes: 6 additions & 6 deletions src/token/cose/maced/mac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub trait CoseMacBuilderExt: Sized {
/// # Examples
///
/// Refer to [the documentation for the CoseMac extensions](CoseMacExt) for examples.
fn try_compute<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_compute<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -73,7 +73,7 @@ pub trait CoseMacBuilderExt: Sized {
}

impl CoseMacBuilderExt for CoseMacBuilder {
fn try_compute<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_compute<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -303,7 +303,7 @@ pub trait CoseMacExt {
/// )
/// );
/// ```
fn try_verify<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_verify<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -384,7 +384,7 @@ pub trait CoseMacExt {
fn try_verify_with_recipients<
B: KeyDistributionCryptoBackend + MacCryptoBackend,
CKP: KeyProvider,
CAP: AadProvider + ?Sized,
CAP: AadProvider,
>(
&self,
backend: &mut B,
Expand All @@ -395,7 +395,7 @@ pub trait CoseMacExt {
}

impl CoseMacExt for CoseMac {
fn try_verify<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_verify<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -423,7 +423,7 @@ impl CoseMacExt for CoseMac {
fn try_verify_with_recipients<
B: KeyDistributionCryptoBackend + MacCryptoBackend,
CKP: KeyProvider,
CAP: AadProvider + ?Sized,
CAP: AadProvider,
>(
&self,
backend: &mut B,
Expand Down
8 changes: 4 additions & 4 deletions src/token/cose/maced/mac0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait CoseMac0BuilderExt: Sized {
/// # Examples
///
/// Refer to [the documentation for the CoseMac0 extensions](CoseMac0Ext) for examples.
fn try_compute<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_compute<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -69,7 +69,7 @@ pub trait CoseMac0BuilderExt: Sized {
}

impl CoseMac0BuilderExt for CoseMac0Builder {
fn try_compute<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_compute<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -228,7 +228,7 @@ pub trait CoseMac0Ext {
/// )
/// );
/// ```
fn try_verify<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_verify<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -237,7 +237,7 @@ pub trait CoseMac0Ext {
}

impl CoseMac0Ext for CoseMac0 {
fn try_verify<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_verify<B: MacCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down
8 changes: 4 additions & 4 deletions src/token/cose/recipient/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ pub trait CoseRecipientBuilderExt: Sized {
// Integration into coset will allow reducing the number of algorithms, but for now this will
// have to make do.
#[allow(clippy::too_many_arguments)]
fn try_encrypt<B: KeyDistributionCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_encrypt<B: KeyDistributionCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -551,7 +551,7 @@ pub trait CoseRecipientBuilderExt: Sized {
}

impl CoseRecipientBuilderExt for CoseRecipientBuilder {
fn try_encrypt<B: KeyDistributionCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_encrypt<B: KeyDistributionCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -757,7 +757,7 @@ pub trait CoseRecipientExt {
/// # Examples
///
/// Refer to the trait-level documentation for an example.
fn try_decrypt<B: KeyDistributionCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_decrypt<B: KeyDistributionCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -768,7 +768,7 @@ pub trait CoseRecipientExt {
}

impl CoseRecipientExt for CoseRecipient {
fn try_decrypt<B: KeyDistributionCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_decrypt<B: KeyDistributionCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down
16 changes: 8 additions & 8 deletions src/token/cose/signed/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub trait CoseSignBuilderExt: Sized {
/// # Examples
///
/// Refer to [the documentation for the CoseSign extensions](CoseSignExt) for examples.
fn try_add_sign<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_add_sign<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -91,7 +91,7 @@ pub trait CoseSignBuilderExt: Sized {
/// # Examples
///
/// Refer to [the documentation for the CoseSign extensions](CoseSignExt) for examples.
fn try_add_sign_detached<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_add_sign_detached<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -102,7 +102,7 @@ pub trait CoseSignBuilderExt: Sized {
}

impl CoseSignBuilderExt for CoseSignBuilder {
fn try_add_sign<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_add_sign<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -125,7 +125,7 @@ impl CoseSignBuilderExt for CoseSignBuilder {
},
)
}
fn try_add_sign_detached<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_add_sign_detached<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -301,7 +301,7 @@ pub trait CoseSignExt {
/// )
/// );
/// ```
fn try_verify<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_verify<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -346,7 +346,7 @@ pub trait CoseSignExt {
/// # Examples
///
/// Refer to the trait-level documentation for examples.
fn try_verify_detached<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_verify_detached<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand All @@ -357,7 +357,7 @@ pub trait CoseSignExt {
}

impl CoseSignExt for CoseSign {
fn try_verify<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_verify<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down Expand Up @@ -399,7 +399,7 @@ impl CoseSignExt for CoseSign {
.collect(),
))
}
fn try_verify_detached<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider + ?Sized>(
fn try_verify_detached<B: SignCryptoBackend, CKP: KeyProvider, CAP: AadProvider>(
&self,
backend: &mut B,
key_provider: &CKP,
Expand Down
Loading

0 comments on commit 4b33e00

Please sign in to comment.