feat(sdk): Rename OlmMachine.export_keys to .export_room_keys.

Because that's what it does :-).
This commit is contained in:
Ivan Enderlin
2022-09-21 13:03:42 +02:00
parent c0ebeee730
commit b442247946
7 changed files with 19 additions and 15 deletions

View File

@@ -583,7 +583,7 @@ mod test {
"JGgPQRuYj3ScMdPS+A0P+k/1qS9Hr3qeKXLscI+hS78"
);
let room_keys = machine.runtime.block_on(machine.inner.export_keys(|_| true))?;
let room_keys = machine.runtime.block_on(machine.inner.export_room_keys(|_| true))?;
assert_eq!(room_keys.len(), 2);
let cross_signing_status = machine.cross_signing_status();

View File

@@ -658,8 +658,12 @@ impl OlmMachine {
///
/// * `rounds` - The number of rounds that should be used when expanding the
/// passphrase into an key.
pub fn export_keys(&self, passphrase: &str, rounds: i32) -> Result<String, CryptoStoreError> {
let keys = self.runtime.block_on(self.inner.export_keys(|_| true))?;
pub fn export_room_keys(
&self,
passphrase: &str,
rounds: i32,
) -> Result<String, CryptoStoreError> {
let keys = self.runtime.block_on(self.inner.export_room_keys(|_| true))?;
let encrypted = encrypt_key_export(&keys, passphrase, rounds as u32)
.map_err(CryptoStoreError::Serialization)?;

View File

@@ -358,7 +358,7 @@ interface OlmMachine {
KeyRequestPair request_room_key([ByRef] string event, [ByRef] string room_id);
[Throws=CryptoStoreError]
string export_keys([ByRef] string passphrase, i32 rounds);
string export_room_keys([ByRef] string passphrase, i32 rounds);
[Throws=KeyImportError]
KeysImportResult import_keys(
[ByRef] string keys,

View File

@@ -125,7 +125,7 @@ pub fn decrypt_key_export(
/// * `rounds` - The number of rounds that should be used for the key
/// derivation when the passphrase gets turned into an AES key. More rounds are
/// increasingly computationally intensive and as such help against brute-force
/// attacks. Should be at least `10000`, while values in the `100000` ranges
/// attacks. Should be at least `10_000`, while values in the `100_000` ranges
/// should be preferred.
///
/// # Panics
@@ -142,7 +142,7 @@ pub fn decrypt_key_export(
/// # block_on(async {
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID")).await;
/// let room_id = room_id!("!test:localhost");
/// let exported_keys = machine.export_keys(|s| s.room_id() == room_id).await.unwrap();
/// let exported_keys = machine.export_room_keys(|s| s.room_id() == room_id).await.unwrap();
/// let encrypted_export = encrypt_key_export(&exported_keys, "1234", 1);
/// # });
/// ```
@@ -332,7 +332,7 @@ mod tests {
let room_id = room_id!("!test:localhost");
machine.create_outbound_group_session_with_defaults(room_id).await.unwrap();
let export = machine.export_keys(|s| s.room_id() == room_id).await.unwrap();
let export = machine.export_room_keys(|s| s.room_id() == room_id).await.unwrap();
assert!(!export.is_empty());

View File

@@ -1441,11 +1441,11 @@ impl OlmMachine {
/// # block_on(async {
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID")).await;
/// let room_id = room_id!("!test:localhost");
/// let exported_keys = machine.export_keys(|s| s.room_id() == room_id).await.unwrap();
/// let exported_keys = machine.export_room_keys(|s| s.room_id() == room_id).await.unwrap();
/// let encrypted_export = encrypt_key_export(&exported_keys, "1234", 1);
/// # });
/// ```
pub async fn export_keys(
pub async fn export_room_keys(
&self,
mut predicate: impl FnMut(&InboundGroupSession) -> bool,
) -> StoreResult<Vec<ExportedRoomKey>> {

View File

@@ -84,10 +84,10 @@ comes first.
Since room keys get relatively often rotated, each room key will need to be
stored, otherwise we won't be able to decrypt historical messages. The SDK
stores all room keys locally in a encrypted manner.
stores all room keys locally in an encrypted manner.
Besides storing them as part of the SDK store, users can export room keys
using the [`Encryption::export_keys`] method.
using the [`Encryption::export_room_keys`] method.
# Verification

View File

@@ -716,7 +716,7 @@ impl Encryption {
/// // Export all room keys.
/// client
/// .encryption()
/// .export_keys(path, "secret-passphrase", |_| true)
/// .export_room_keys(path, "secret-passphrase", |_| true)
/// .await?;
///
/// // Export only the room keys for a certain room.
@@ -725,12 +725,12 @@ impl Encryption {
///
/// client
/// .encryption()
/// .export_keys(path, "secret-passphrase", |s| s.room_id() == room_id)
/// .export_room_keys(path, "secret-passphrase", |s| s.room_id() == room_id)
/// .await?;
/// # anyhow::Ok(()) });
/// ```
#[cfg(not(target_arch = "wasm32"))]
pub async fn export_keys(
pub async fn export_room_keys(
&self,
path: PathBuf,
passphrase: &str,
@@ -738,7 +738,7 @@ impl Encryption {
) -> Result<()> {
let olm = self.client.olm_machine().ok_or(Error::AuthenticationRequired)?;
let keys = olm.export_keys(predicate).await?;
let keys = olm.export_room_keys(predicate).await?;
let passphrase = zeroize::Zeroizing::new(passphrase.to_owned());
let encrypt = move || -> Result<()> {