rust/crypto: Implement From<SymKeyType> for Nid

Implement `From<SymKeyType> for Nid`. This makes it easier to implement
generalized functions.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2024-10-14 17:17:27 +00:00
committed by Steffen Eiden
parent eee29e0399
commit 567cbce8a8

View File

@@ -41,6 +41,15 @@ pub enum SymKeyType {
Aes256Xts,
}
impl From<SymKeyType> for Nid {
fn from(value: SymKeyType) -> Self {
match value {
SymKeyType::Aes256 => Self::AES_256_GCM,
SymKeyType::Aes256Xts => Self::AES_256_XTS,
}
}
}
/// Types of symmetric keys
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -491,4 +500,16 @@ mod tests {
assert_eq!(hmac, exp);
}
#[test]
fn from_symkeytype() {
assert_eq!(
<SymKeyType as Into<Nid>>::into(SymKeyType::Aes256),
Nid::AES_256_GCM
);
assert_eq!(
<SymKeyType as Into<Nid>>::into(SymKeyType::Aes256Xts),
Nid::AES_256_XTS
);
}
}