mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 17:15:43 +00:00
chore: update Rust to 1.95; replace cfg_if with cfg_select (#2121)
This commit is contained in:
@@ -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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user