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

Fix clippy lint and disable Travis #70

Merged
merged 1 commit into from
Jan 6, 2021
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
File renamed without changes.
69 changes: 33 additions & 36 deletions psa-crypto/src/types/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -177,9 +175,8 @@ impl Mac {
| Mac::Truncated {
mac_alg: FullLengthMac::Cmac,
..
} => true,
_ => false,
}
}
)
}
}

Expand Down Expand Up @@ -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
)
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}
)
}
}

Expand Down Expand Up @@ -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
Expand Down
48 changes: 14 additions & 34 deletions psa-crypto/src/types/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
..
})
)
}
}
}
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down