Skip to content

Commit

Permalink
Format the dehydration pickling code a bit prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Jan 29, 2025
1 parent 9370eb2 commit 96bfe8d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/olm/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,19 +516,22 @@ impl Account {
let cipher = ChaCha20Poly1305::new(key.into());
let ciphertext = base64_decode(ciphertext)?;
let nonce = base64_decode(nonce)?;

if nonce.len() != 12 {
return Err(crate::DehydratedDeviceError::InvalidNonce);
}
let mut plaintext = cipher.decrypt(nonce.as_slice().into(), ciphertext.as_slice())?;
let version =
get_pickle_version(&plaintext).ok_or(crate::DehydratedDeviceError::MissingVersion)?;
if version != PICKLE_VERSION {
return Err(crate::DehydratedDeviceError::Version(PICKLE_VERSION, version));
}
Err(crate::DehydratedDeviceError::InvalidNonce)
} else {
let mut plaintext = cipher.decrypt(nonce.as_slice().into(), ciphertext.as_slice())?;
let version = get_pickle_version(&plaintext)
.ok_or(crate::DehydratedDeviceError::MissingVersion)?;

let pickle = Self::from_decrypted_dehydrated_device(&plaintext);
plaintext.zeroize();
pickle
if version != PICKLE_VERSION {
Err(crate::DehydratedDeviceError::Version(PICKLE_VERSION, version))
} else {
let pickle = Self::from_decrypted_dehydrated_device(&plaintext);
plaintext.zeroize();
pickle
}
}
}

// This function is public for fuzzing, but should not be used by anything
Expand Down

0 comments on commit 96bfe8d

Please sign in to comment.