mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
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:
committed by
Steffen Eiden
parent
eee29e0399
commit
567cbce8a8
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user