From 69ab6f96c5bb4782466e82c1db2383d227136102 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 27 Nov 2023 09:30:37 -0500 Subject: [PATCH] Simplify code (#9925) --- src/rust/src/backend/aead.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/rust/src/backend/aead.rs b/src/rust/src/backend/aead.rs index 0965b71a7005..7ae93ff06b11 100644 --- a/src/rust/src/backend/aead.rs +++ b/src/rust/src/backend/aead.rs @@ -235,30 +235,30 @@ impl AesSiv { } }; - #[cfg(not(CRYPTOGRAPHY_OPENSSL_300_OR_GREATER))] - { - return Err(CryptographyError::from( - exceptions::UnsupportedAlgorithm::new_err(( - "AES-SIV is not supported by this version of OpenSSL", - exceptions::Reasons::UNSUPPORTED_CIPHER, - )), - )); - } - #[cfg(CRYPTOGRAPHY_OPENSSL_300_OR_GREATER)] - { - if cryptography_openssl::fips::is_enabled() { + cfg_if::cfg_if! { + if #[cfg(CRYPTOGRAPHY_OPENSSL_300_OR_GREATER)] { + if cryptography_openssl::fips::is_enabled() { + return Err(CryptographyError::from( + exceptions::UnsupportedAlgorithm::new_err(( + "AES-SIV is not supported by this version of OpenSSL", + exceptions::Reasons::UNSUPPORTED_CIPHER, + )), + )); + } + + let cipher = openssl::cipher::Cipher::fetch(None, cipher_name, None)?; + Ok(AesSiv { + ctx: EvpCipherAead::new(&cipher, key_buf.as_bytes(), 16, true)?, + }) + } else { return Err(CryptographyError::from( exceptions::UnsupportedAlgorithm::new_err(( "AES-SIV is not supported by this version of OpenSSL", exceptions::Reasons::UNSUPPORTED_CIPHER, )), )); - } - let cipher = openssl::cipher::Cipher::fetch(None, cipher_name, None)?; - Ok(AesSiv { - ctx: EvpCipherAead::new(&cipher, key_buf.as_bytes(), 16, true)?, - }) + } } }