mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-07 23:44:53 -04:00
refactor(sled)!: Rename SledCryptoStore::{open_with_passphrase => open}
`open_with_db` also has the passphrase parameter without mentioning it in its name. The old name also sounded like the passphrase was required when it's actually optional.
This commit is contained in:
committed by
Jonas Platte
parent
262fe5630f
commit
d0609822bc
@@ -71,9 +71,7 @@ pub fn keys_query(c: &mut Criterion) {
|
||||
});
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = Arc::new(
|
||||
runtime.block_on(SledCryptoStore::open_with_passphrase(dir.path(), None)).unwrap(),
|
||||
);
|
||||
let store = Arc::new(runtime.block_on(SledCryptoStore::open(dir.path(), None)).unwrap());
|
||||
let machine =
|
||||
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
|
||||
|
||||
@@ -120,11 +118,8 @@ pub fn keys_claiming(c: &mut Criterion) {
|
||||
b.iter_batched(
|
||||
|| {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = Arc::new(
|
||||
runtime
|
||||
.block_on(SledCryptoStore::open_with_passphrase(dir.path(), None))
|
||||
.unwrap(),
|
||||
);
|
||||
let store =
|
||||
Arc::new(runtime.block_on(SledCryptoStore::open(dir.path(), None)).unwrap());
|
||||
|
||||
let machine = runtime
|
||||
.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store))
|
||||
@@ -186,9 +181,7 @@ pub fn room_key_sharing(c: &mut Criterion) {
|
||||
})
|
||||
});
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = Arc::new(
|
||||
runtime.block_on(SledCryptoStore::open_with_passphrase(dir.path(), None)).unwrap(),
|
||||
);
|
||||
let store = Arc::new(runtime.block_on(SledCryptoStore::open(dir.path(), None)).unwrap());
|
||||
|
||||
let machine =
|
||||
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
|
||||
@@ -243,9 +236,7 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
|
||||
});
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = Arc::new(
|
||||
runtime.block_on(SledCryptoStore::open_with_passphrase(dir.path(), None)).unwrap(),
|
||||
);
|
||||
let store = Arc::new(runtime.block_on(SledCryptoStore::open(dir.path(), None)).unwrap());
|
||||
|
||||
let machine =
|
||||
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
|
||||
|
||||
@@ -196,8 +196,7 @@ pub fn migrate(
|
||||
};
|
||||
|
||||
let runtime = Runtime::new()?;
|
||||
let store =
|
||||
runtime.block_on(SledCryptoStore::open_with_passphrase(path, passphrase.as_deref()))?;
|
||||
let store = runtime.block_on(SledCryptoStore::open(path, passphrase.as_deref()))?;
|
||||
|
||||
processed_steps += 1;
|
||||
listener(processed_steps, total_steps);
|
||||
|
||||
@@ -158,23 +158,20 @@ impl OlmMachine {
|
||||
|
||||
let store = Arc::new(
|
||||
runtime
|
||||
.block_on(matrix_sdk_sled::SledCryptoStore::open_with_passphrase(
|
||||
path,
|
||||
passphrase.as_deref(),
|
||||
))
|
||||
.block_on(matrix_sdk_sled::SledCryptoStore::open(path, passphrase.as_deref()))
|
||||
.map_err(|e| {
|
||||
match e {
|
||||
// This is a bit of an error in the sled store, the
|
||||
// CryptoStore returns an `OpenStoreError` which has a
|
||||
// variant for the state store. Not sure what to do about
|
||||
// this.
|
||||
matrix_sdk_sled::OpenStoreError::Crypto(r) => r.into(),
|
||||
matrix_sdk_sled::OpenStoreError::Sled(s) => CryptoStoreError::CryptoStore(
|
||||
matrix_sdk_crypto::store::CryptoStoreError::backend(s),
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
})?,
|
||||
match e {
|
||||
// This is a bit of an error in the sled store, the
|
||||
// CryptoStore returns an `OpenStoreError` which has a
|
||||
// variant for the state store. Not sure what to do about
|
||||
// this.
|
||||
matrix_sdk_sled::OpenStoreError::Crypto(r) => r.into(),
|
||||
matrix_sdk_sled::OpenStoreError::Sled(s) => CryptoStoreError::CryptoStore(
|
||||
matrix_sdk_crypto::store::CryptoStoreError::backend(s),
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
})?,
|
||||
);
|
||||
|
||||
passphrase.zeroize();
|
||||
|
||||
@@ -65,13 +65,10 @@ impl OlmMachine {
|
||||
|
||||
let store = if let Some(store_path) = store_path {
|
||||
Some(
|
||||
matrix_sdk_sled::SledCryptoStore::open_with_passphrase(
|
||||
store_path,
|
||||
store_passphrase.as_deref(),
|
||||
)
|
||||
.await
|
||||
.map(Arc::new)
|
||||
.map_err(into_err)?,
|
||||
matrix_sdk_sled::SledCryptoStore::open(store_path, store_passphrase.as_deref())
|
||||
.await
|
||||
.map(Arc::new)
|
||||
.map_err(into_err)?,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -208,7 +208,7 @@ impl std::fmt::Debug for SledCryptoStore {
|
||||
impl SledCryptoStore {
|
||||
/// Open the sled-based crypto store at the given path using the given
|
||||
/// passphrase to encrypt private data.
|
||||
pub async fn open_with_passphrase(
|
||||
pub async fn open(
|
||||
path: impl AsRef<Path>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<Self, OpenStoreError> {
|
||||
@@ -1061,7 +1061,7 @@ mod tests {
|
||||
async fn get_store(name: &str, passphrase: Option<&str>) -> SledCryptoStore {
|
||||
let tmpdir_path = TMP_DIR.path().join(name);
|
||||
|
||||
SledCryptoStore::open_with_passphrase(tmpdir_path.to_str().unwrap(), passphrase)
|
||||
SledCryptoStore::open(tmpdir_path.to_str().unwrap(), passphrase)
|
||||
.await
|
||||
.expect("Can't create a passphrase protected store")
|
||||
}
|
||||
@@ -1083,7 +1083,7 @@ mod encrypted_tests {
|
||||
let tmpdir_path = TMP_DIR.path().join(name);
|
||||
let pass = passphrase.unwrap_or("default_test_password");
|
||||
|
||||
SledCryptoStore::open_with_passphrase(tmpdir_path.to_str().unwrap(), Some(pass))
|
||||
SledCryptoStore::open(tmpdir_path.to_str().unwrap(), Some(pass))
|
||||
.await
|
||||
.expect("Can't create a passphrase protected store")
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ pub async fn make_store_config(
|
||||
|
||||
#[cfg(all(feature = "crypto-store", not(feature = "state-store")))]
|
||||
{
|
||||
let crypto_store = SledCryptoStore::open_with_passphrase(path, passphrase).await?;
|
||||
let crypto_store = SledCryptoStore::open(path, passphrase).await?;
|
||||
Ok(StoreConfig::new().crypto_store(crypto_store))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user