chore: update Rust to 1.95; replace cfg_if with cfg_select (#2121)

This commit is contained in:
Luna Yao
2026-04-17 23:41:31 +08:00
committed by GitHub
parent bcb2e512d4
commit fae32361f2
16 changed files with 66 additions and 94 deletions
+11 -31
View File
@@ -62,9 +62,6 @@ pub fn create_encryptor(
key_128: [u8; 16],
#[allow(unused_variables)] key_256: [u8; 32],
) -> Arc<dyn Encryptor> {
#[cfg(any(feature = "aes-gcm", feature = "wireguard", feature = "openssl-crypto"))]
use cfg_if::cfg_if;
let algorithm = match EncryptionAlgorithm::try_from(algorithm) {
Ok(algorithm) => algorithm,
Err(_) => {
@@ -83,44 +80,27 @@ pub fn create_encryptor(
#[cfg(any(feature = "aes-gcm", feature = "wireguard", feature = "openssl-crypto"))]
EncryptionAlgorithm::AesGcm => {
cfg_if! {
if #[cfg(feature = "openssl-crypto")] {
Arc::new(openssl::OpenSslCipher::new_aes128_gcm(key_128))
} else if #[cfg(feature = "wireguard")] {
Arc::new(ring::RingCipher::new_aes128_gcm(key_128))
} else if #[cfg(feature = "aes-gcm")] {
Arc::new(aes_gcm::AesGcmCipher::new_128(key_128))
} else {
compile_error!("unreachable!");
}
cfg_select! {
feature = "openssl-crypto" => Arc::new(openssl::OpenSslCipher::new_aes128_gcm(key_128)),
feature = "wireguard" => Arc::new(ring::RingCipher::new_aes128_gcm(key_128)),
feature = "aes-gcm" => Arc::new(aes_gcm::AesGcmCipher::new_128(key_128)),
}
}
#[cfg(any(feature = "aes-gcm", feature = "wireguard", feature = "openssl-crypto"))]
EncryptionAlgorithm::Aes256Gcm => {
cfg_if! {
if #[cfg(feature = "openssl-crypto")] {
Arc::new(openssl::OpenSslCipher::new_aes256_gcm(key_256))
} else if #[cfg(feature = "wireguard")] {
Arc::new(ring::RingCipher::new_aes256_gcm(key_256))
} else if #[cfg(feature = "aes-gcm")] {
Arc::new(aes_gcm::AesGcmCipher::new_256(key_256))
} else {
compile_error!("unreachable!");
}
cfg_select! {
feature = "openssl-crypto" => Arc::new(openssl::OpenSslCipher::new_aes256_gcm(key_256)),
feature = "wireguard" => Arc::new(ring::RingCipher::new_aes256_gcm(key_256)),
feature = "aes-gcm" => Arc::new(aes_gcm::AesGcmCipher::new_256(key_256)),
}
}
#[cfg(any(feature = "wireguard", feature = "openssl-crypto"))]
EncryptionAlgorithm::ChaCha20 => {
cfg_if! {
if #[cfg(feature = "openssl-crypto")] {
Arc::new(openssl::OpenSslCipher::new_chacha20(key_256))
} else if #[cfg(feature = "wireguard")] {
Arc::new(ring::RingCipher::new_chacha20(key_256))
} else {
compile_error!("unreachable!");
}
cfg_select! {
feature = "openssl-crypto" => Arc::new(openssl::OpenSslCipher::new_chacha20(key_256)),
feature = "wireguard" => Arc::new(ring::RingCipher::new_chacha20(key_256)),
}
}
}