From d867b2191a68a4892b1c97d8f39805e536c0a61e Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Fri, 29 Nov 2024 19:05:52 -0500 Subject: [PATCH] fix clippy issues --- src/olm/account/mod.rs | 38 +++++++++++++++----------------- src/olm/account/one_time_keys.rs | 1 - src/types/curve25519.rs | 1 - src/utilities/mod.rs | 4 +++- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/olm/account/mod.rs b/src/olm/account/mod.rs index 83a8e453..d47a5131 100644 --- a/src/olm/account/mod.rs +++ b/src/olm/account/mod.rs @@ -451,7 +451,6 @@ impl Account { } /// Create an [`Account`] object by rehydrating a device. - #[cfg(feature = "libolm-compat")] pub fn from_dehydrated_device( pickle: &str, curve25519key: &str, @@ -462,23 +461,22 @@ impl Account { let pickle_key = expand_pickle_key(key, curve25519key); - if cfg!(feature = "libolm-compat") { - unpickle_libolm::(pickle, pickle_key.as_ref(), PICKLE_VERSION).or_else( - |err| { - match err { - // If it failed as a dehydrated device due to a bad - // version, we try decoding it as a libolm pickle, which - // some older dehydrated devices used. - crate::LibolmPickleError::Version(..) => { - Self::from_libolm_pickle(pickle, pickle_key.as_ref()) - } - _ => Err(err), + #[cfg(feature = "libolm-compat")] + return unpickle_libolm::(pickle, pickle_key.as_ref(), PICKLE_VERSION).or_else( + |err| { + match err { + // If it failed as a dehydrated device due to a bad + // version, we try decoding it as a libolm pickle, which + // some older dehydrated devices used. + crate::LibolmPickleError::Version(..) => { + Self::from_libolm_pickle(pickle, pickle_key.as_ref()) } - }, - ) - } else { - unpickle_libolm::(pickle, pickle_key.as_ref(), PICKLE_VERSION) - } + _ => Err(err), + } + }, + ); + #[cfg(not(feature = "libolm-compat"))] + unpickle_libolm::(pickle, pickle_key.as_ref(), PICKLE_VERSION) } } @@ -861,12 +859,12 @@ mod dehydrated_device { pub fn expand_pickle_key(key: &[u8; 32], identity_key: &str) -> Box<[u8; 32]> { let kdf: Hkdf = Hkdf::new(Some(identity_key.as_bytes()), key); - let mut key = Box::new([0u8; 32]); + let mut key = [0u8; 32]; - kdf.expand(b"dehydrated-device-pickle-key", key.as_mut_slice()) + kdf.expand(b"dehydrated-device-pickle-key", &mut key) .expect("We should be able to expand the 32 byte pickle key"); - key + Box::new(key) } } diff --git a/src/olm/account/one_time_keys.rs b/src/olm/account/one_time_keys.rs index 83c3c92a..893c2449 100644 --- a/src/olm/account/one_time_keys.rs +++ b/src/olm/account/one_time_keys.rs @@ -118,7 +118,6 @@ impl OneTimeKeys { self.insert_secret_key(key_id, key, false) } - #[cfg(feature = "libolm-compat")] pub(crate) const fn secret_keys(&self) -> &BTreeMap { &self.private_keys } diff --git a/src/types/curve25519.rs b/src/types/curve25519.rs index 21f12b1d..31ad6053 100644 --- a/src/types/curve25519.rs +++ b/src/types/curve25519.rs @@ -87,7 +87,6 @@ impl Curve25519Keypair { Self { secret_key, public_key } } - #[cfg(feature = "libolm-compat")] pub fn from_secret_key(key: &[u8; 32]) -> Self { let secret_key = Curve25519SecretKey::from_slice(key); let public_key = Curve25519PublicKey::from(&secret_key); diff --git a/src/utilities/mod.rs b/src/utilities/mod.rs index a72dbe23..86aef882 100644 --- a/src/utilities/mod.rs +++ b/src/utilities/mod.rs @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(feature = "libolm-compat")] mod libolm_compat; pub use base64::DecodeError; @@ -22,6 +21,9 @@ use base64::{ engine::{general_purpose, GeneralPurpose}, Engine, }; +#[cfg(not(feature = "libolm-compat"))] +pub(crate) use libolm_compat::{pickle_libolm, unpickle_libolm}; +#[cfg(feature = "libolm-compat")] pub(crate) use libolm_compat::{pickle_libolm, unpickle_libolm, LibolmEd25519Keypair}; const STANDARD_NO_PAD: GeneralPurpose = GeneralPurpose::new(