Implement use of Zeroizing struct for string
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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?;
|
||||
|
||||
Reference in New Issue
Block a user