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:
Jonas Platte
2022-12-06 16:45:38 +01:00
committed by Jonas Platte
parent 262fe5630f
commit d0609822bc
6 changed files with 27 additions and 43 deletions

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();

View File

@@ -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

View File

@@ -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")
}

View File

@@ -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))
}