From 6bc6f0f5563a57de8f3a95e63d357febd6c1e959 Mon Sep 17 00:00:00 2001 From: Ionut Mihalcea Date: Wed, 6 Jan 2021 12:08:44 +0000 Subject: [PATCH] Fix clippy lint and disable Travis Signed-off-by: Ionut Mihalcea --- .travis.yml => .travis.yml.disabled | 0 psa-crypto/src/types/algorithm.rs | 69 ++++++++++++++--------------- psa-crypto/src/types/key.rs | 48 ++++++-------------- 3 files changed, 47 insertions(+), 70 deletions(-) rename .travis.yml => .travis.yml.disabled (100%) diff --git a/.travis.yml b/.travis.yml.disabled similarity index 100% rename from .travis.yml rename to .travis.yml.disabled diff --git a/psa-crypto/src/types/algorithm.rs b/psa-crypto/src/types/algorithm.rs index 8c2f8c2..975e716 100644 --- a/psa-crypto/src/types/algorithm.rs +++ b/psa-crypto/src/types/algorithm.rs @@ -155,19 +155,17 @@ pub enum Mac { impl Mac { /// Check if the MAC algorithm is a HMAC algorithm, truncated or not pub fn is_hmac(self) -> bool { - match self { + matches!( + self, Mac::FullLength(FullLengthMac::Hmac { .. }) - | Mac::Truncated { - mac_alg: FullLengthMac::Hmac { .. }, - .. - } => true, - _ => false, - } + | Mac::Truncated { mac_alg: FullLengthMac::Hmac { .. }, .. } + ) } /// Check if the MAC algorithm is a construction over a block cipher pub fn is_block_cipher_needed(self) -> bool { - match self { + matches!( + self, Mac::FullLength(FullLengthMac::CbcMac) | Mac::FullLength(FullLengthMac::Cmac) | Mac::Truncated { @@ -177,9 +175,8 @@ impl Mac { | Mac::Truncated { mac_alg: FullLengthMac::Cmac, .. - } => true, - _ => false, - } + } + ) } } @@ -209,16 +206,16 @@ pub enum Cipher { impl Cipher { /// Check is the cipher algorithm is a mode of a block cipher. pub fn is_block_cipher_mode(self) -> bool { - match self { + matches!( + self, Cipher::Ctr - | Cipher::Cfb - | Cipher::Ofb - | Cipher::Xts - | Cipher::EcbNoPadding - | Cipher::CbcNoPadding - | Cipher::CbcPkcs7 => true, - _ => false, - } + | Cipher::Cfb + | Cipher::Ofb + | Cipher::Xts + | Cipher::EcbNoPadding + | Cipher::CbcNoPadding + | Cipher::CbcPkcs7 + ) } } @@ -251,7 +248,8 @@ pub enum Aead { impl Aead { /// Check if the Aead algorithm needs a block cipher pub fn is_aead_on_block_cipher(self) -> bool { - match self { + matches!( + self, Aead::AeadWithDefaultLengthTag(AeadWithDefaultLengthTag::Ccm) | Aead::AeadWithDefaultLengthTag(AeadWithDefaultLengthTag::Gcm) | Aead::AeadWithShortenedTag { @@ -261,21 +259,20 @@ impl Aead { | Aead::AeadWithShortenedTag { aead_alg: AeadWithDefaultLengthTag::Gcm, .. - } => true, - _ => false, - } + } + ) } /// Check if this AEAD algorithm is the (truncated or not) Chacha20-Poly1305 AEAD algorithm. pub fn is_chacha20_poly1305_alg(self) -> bool { - match self { + matches!( + self, Aead::AeadWithDefaultLengthTag(AeadWithDefaultLengthTag::Chacha20Poly1305) | Aead::AeadWithShortenedTag { aead_alg: AeadWithDefaultLengthTag::Chacha20Poly1305, .. - } => true, - _ => false, - } + } + ) } } @@ -406,22 +403,22 @@ impl AsymmetricSignature { /// Check if this is a RSA algorithm pub fn is_rsa_alg(self) -> bool { - match self { + matches!( + self, AsymmetricSignature::RsaPkcs1v15Sign { .. } | AsymmetricSignature::RsaPkcs1v15SignRaw - | AsymmetricSignature::RsaPss { .. } => true, - _ => false, - } + | AsymmetricSignature::RsaPss { .. } + ) } /// Check if this is an ECC algorithm pub fn is_ecc_alg(self) -> bool { - match self { + matches!( + self, AsymmetricSignature::Ecdsa { .. } | AsymmetricSignature::EcdsaAny - | AsymmetricSignature::DeterministicEcdsa { .. } => true, - _ => false, - } + | AsymmetricSignature::DeterministicEcdsa { .. } + ) } /// Determines if the given hash length is compatible with the asymmetric signature scheme diff --git a/psa-crypto/src/types/key.rs b/psa-crypto/src/types/key.rs index 5d54745..bff62ba 100644 --- a/psa-crypto/src/types/key.rs +++ b/psa-crypto/src/types/key.rs @@ -229,11 +229,7 @@ impl Attributes { Type::RawData => false, Type::Hmac => alg.is_hmac(), Type::Derive => { - if let Algorithm::KeyDerivation(_) = alg { - true - } else { - false - } + matches!(alg, Algorithm::KeyDerivation(_)) } Type::Aes | Type::Camellia => { if let Algorithm::Mac(mac_alg) = alg { @@ -268,10 +264,8 @@ impl Attributes { Type::RsaPublicKey | Type::RsaKeyPair => { if let Algorithm::AsymmetricSignature(sign_alg) = alg { sign_alg.is_rsa_alg() - } else if let Algorithm::AsymmetricEncryption(_) = alg { - true } else { - false + matches!(alg, Algorithm::AsymmetricEncryption(_)) } } Type::EccKeyPair { .. } | Type::EccPublicKey { .. } => match alg { @@ -284,16 +278,14 @@ impl Attributes { _ => false, }, Type::DhKeyPair { .. } | Type::DhPublicKey { .. } => { - if let Algorithm::KeyAgreement(KeyAgreement::Raw(RawKeyAgreement::Ffdh)) - | Algorithm::KeyAgreement(KeyAgreement::WithKeyDerivation { - ka_alg: RawKeyAgreement::Ffdh, - .. - }) = alg - { - true - } else { - false - } + matches!( + alg, + Algorithm::KeyAgreement(KeyAgreement::Raw(RawKeyAgreement::Ffdh)) + | Algorithm::KeyAgreement(KeyAgreement::WithKeyDerivation { + ka_alg: RawKeyAgreement::Ffdh, + .. + }) + ) } } } @@ -552,10 +544,7 @@ pub enum Type { impl Type { /// Checks if a key type is ECC key pair with any curve family inside. pub fn is_ecc_key_pair(self) -> bool { - match self { - Type::EccKeyPair { .. } => true, - _ => false, - } + matches!( self, Type::EccKeyPair { .. }) } /// Checks if a key type is ECC public key with any curve family inside. @@ -568,26 +557,17 @@ impl Type { /// assert!(Type::EccPublicKey { curve_family: EccFamily::SecpK1}.is_ecc_public_key()); /// ``` pub fn is_ecc_public_key(self) -> bool { - match self { - Type::EccPublicKey { .. } => true, - _ => false, - } + matches!(self, Type::EccPublicKey { .. }) } /// Checks if a key type is DH public key with any group family inside. pub fn is_dh_public_key(self) -> bool { - match self { - Type::DhPublicKey { .. } => true, - _ => false, - } + matches!( self, Type::DhPublicKey { .. } ) } /// Checks if a key type is DH key pair with any group family inside. pub fn is_dh_key_pair(self) -> bool { - match self { - Type::DhKeyPair { .. } => true, - _ => false, - } + matches!( self, Type::DhKeyPair { .. } ) } /// If key is public or key pair, returns the corresponding public key type.