Skip to content

Commit

Permalink
fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
uhoreg committed Nov 30, 2024
1 parent a8aa227 commit 4fbc6c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
38 changes: 18 additions & 20 deletions src/olm/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -462,23 +461,22 @@ impl Account {

let pickle_key = expand_pickle_key(key, curve25519key);

if cfg!(feature = "libolm-compat") {
unpickle_libolm::<Pickle, _>(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, 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, pickle_key.as_ref(), PICKLE_VERSION)
}
_ => Err(err),
}
},
);
#[cfg(not(feature = "libolm-compat"))]
unpickle_libolm::<Pickle, _>(pickle, pickle_key.as_ref(), PICKLE_VERSION)
}
}

Expand Down Expand Up @@ -861,12 +859,12 @@ mod dehydrated_device {

pub fn expand_pickle_key(key: &[u8; 32], identity_key: &str) -> Box<[u8; 32]> {
let kdf: Hkdf<Sha256> = 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)
}
}

Expand Down
1 change: 0 additions & 1 deletion src/olm/account/one_time_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyId, Curve25519SecretKey> {
&self.private_keys
}
Expand Down
1 change: 0 additions & 1 deletion src/types/curve25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +21,10 @@ use base64::{
engine::{general_purpose, GeneralPurpose},
Engine,
};
#[cfg(feature = "libolm-compat")]
pub(crate) use libolm_compat::{pickle_libolm, unpickle_libolm, LibolmEd25519Keypair};
#[cfg(not(feature = "libolm-compat"))]
pub(crate) use libolm_compat::{pickle_libolm, unpickle_libolm};

const STANDARD_NO_PAD: GeneralPurpose = GeneralPurpose::new(
&alphabet::STANDARD,
Expand Down

0 comments on commit 4fbc6c6

Please sign in to comment.