mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 09:09:17 +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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4392,9 +4392,9 @@ mod tests {
|
||||
|
||||
// find the smallest peer_id, which should be a center node
|
||||
let mut all_route = [r_a.clone(), r_b.clone(), r_c.clone(), r_d.clone()];
|
||||
all_route.sort_by(|a, b| a.my_peer_id.cmp(&b.my_peer_id));
|
||||
all_route.sort_by_key(|r| r.my_peer_id);
|
||||
let mut all_peer_mgr = [p_a.clone(), p_b.clone(), p_c.clone(), p_d.clone()];
|
||||
all_peer_mgr.sort_by_key(|a| a.my_peer_id());
|
||||
all_peer_mgr.sort_by_key(|p| p.my_peer_id());
|
||||
|
||||
wait_for_condition(
|
||||
|| async { all_route[0].service_impl.sessions.len() == 3 },
|
||||
|
||||
Reference in New Issue
Block a user