Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store-encryption): Remove an unwrap that snuck in #4506

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/matrix-sdk-store-encryption/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.

## [Unreleased] - ReleaseDate

### Bug Fixes

- Remove the usage of an unwrap in the `StoreCipher::import_with_key` method.
This could have lead to panics if the second argument was an invalid
`StoreCipher` export.
([#4506](https://github.com/matrix-org/matrix-rust-sdk/pull/4506))

## [0.9.0] - 2024-12-18

No notable changes in this release.
Expand Down
8 changes: 7 additions & 1 deletion crates/matrix-sdk-store-encryption/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl StoreCipher {
/// # anyhow::Ok(()) };
/// ```
pub fn import_with_key(key: &[u8; 32], encrypted: &[u8]) -> Result<Self, Error> {
let encrypted: EncryptedStoreCipher = rmp_serde::from_slice(encrypted).unwrap();
let encrypted: EncryptedStoreCipher = rmp_serde::from_slice(encrypted)?;

if let KdfInfo::Pbkdf2ToChaCha20Poly1305 { .. } = encrypted.kdf_info {
return Err(Error::KdfMismatch);
Expand Down Expand Up @@ -903,6 +903,12 @@ mod tests {
Ok(())
}

#[test]
fn test_importing_invalid_store_cipher_does_not_panic() {
// This used to panic, we're testing that we're getting a real error.
assert!(StoreCipher::import_with_key(&[0; 32], &[0; 64]).is_err())
}

#[test]
fn encrypting_values() -> Result<(), Error> {
let event = json!({
Expand Down
Loading