From 567cbce8a8b55b6104ff4c913a76920c51208abe Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Mon, 14 Oct 2024 17:17:27 +0000 Subject: [PATCH] rust/crypto: Implement `From for Nid` Implement `From for Nid`. This makes it easier to implement generalized functions. Reviewed-by: Steffen Eiden Signed-off-by: Marc Hartmayer Signed-off-by: Steffen Eiden --- rust/pv/src/crypto.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rust/pv/src/crypto.rs b/rust/pv/src/crypto.rs index 6d9e14c5..10cce1e2 100644 --- a/rust/pv/src/crypto.rs +++ b/rust/pv/src/crypto.rs @@ -41,6 +41,15 @@ pub enum SymKeyType { Aes256Xts, } +impl From 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!( + >::into(SymKeyType::Aes256), + Nid::AES_256_GCM + ); + assert_eq!( + >::into(SymKeyType::Aes256Xts), + Nid::AES_256_XTS + ); + } }