Implement use of Zeroizing struct for string

This commit is contained in:
multi prise
2025-09-09 23:04:03 +02:00
committed by Damir Jelić
parent 0d0e2aa472
commit 5a1bd54bb1
3 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased] - ReleaseDate
### Features
- Implement a new constructrot that allow to open SqliteCryptoStore with a Key
- Implement a new constructor that allows to open SqliteCryptoStore with a cryptographic key
([#5472](https://github.com/matrix-org/matrix-rust-sdk/pull/5472))
### Refactor
+5 -4
View File
@@ -33,7 +33,7 @@ use std::{
};
use deadpool_sqlite::PoolConfig;
use zeroize::{Zeroize, ZeroizeOnDrop};
use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
#[cfg(feature = "crypto-store")]
pub use self::crypto_store::SqliteCryptoStore;
@@ -51,7 +51,7 @@ matrix_sdk_test_utils::init_tracing_for_tests!();
#[derive(Clone, Debug, PartialEq, Zeroize, ZeroizeOnDrop)]
pub enum Secret {
Key(Box<[u8; 32]>),
PassPhrase(String),
PassPhrase(Zeroizing<String>),
}
/// A configuration structure used for opening a store.
@@ -132,7 +132,8 @@ impl SqliteStoreConfig {
/// Define the passphrase if the store is encoded.
pub fn passphrase(mut self, passphrase: Option<&str>) -> Self {
self.secret = passphrase.map(|passphrase| Secret::PassPhrase(passphrase.to_owned()));
self.secret =
passphrase.map(|passphrase| Secret::PassPhrase(Zeroizing::new(passphrase.to_owned())));
self
}
@@ -274,7 +275,7 @@ mod tests {
.journal_size_limit(44);
assert_eq!(store_config.path, PathBuf::from("foo"));
assert_eq!(store_config.secret, Some(Secret::PassPhrase("bar".to_owned())));
assert_eq!(store_config.secret, Some(Secret::PassPhrase("bar".to_owned().into())));
assert_eq!(store_config.pool_config.max_size, 42);
assert!(store_config.runtime_config.optimize.not());
assert_eq!(store_config.runtime_config.cache_size, 43);
+4 -1
View File
@@ -2370,6 +2370,7 @@ mod migration_tests {
use serde_json::json;
use tempfile::{tempdir, TempDir};
use tokio::fs;
use zeroize::Zeroizing;
use super::{init, keys, SqliteStateStore, DATABASE_NAME};
use crate::{
@@ -2399,7 +2400,9 @@ mod migration_tests {
init(&conn).await?;
let store_cipher = Some(Arc::new(
conn.get_or_create_store_cipher(Secret::PassPhrase(SECRET.to_owned())).await.unwrap(),
conn.get_or_create_store_cipher(Secret::PassPhrase(Zeroizing::new(SECRET.to_owned())))
.await
.unwrap(),
));
let this = SqliteStateStore { store_cipher, pool };
this.run_migrations(&conn, 1, Some(version)).await?;