diff --git a/rust-sdk/src/error.rs b/rust-sdk/src/error.rs index ec2e2c07ac..8e66539131 100644 --- a/rust-sdk/src/error.rs +++ b/rust-sdk/src/error.rs @@ -1,5 +1,7 @@ use matrix_sdk_common::identifiers::Error as RumaIdentifierError; -use matrix_sdk_crypto::{store::CryptoStoreError as InnerStoreError, MegolmError, OlmError}; +use matrix_sdk_crypto::{ + store::CryptoStoreError as InnerStoreError, KeyExportError, MegolmError, OlmError, +}; #[derive(Debug, thiserror::Error)] pub enum MachineCreationError { @@ -9,6 +11,14 @@ pub enum MachineCreationError { CryptoStore(#[from] InnerStoreError), } +#[derive(Debug, thiserror::Error)] +pub enum KeyImportError { + #[error(transparent)] + Export(#[from] KeyExportError), + #[error(transparent)] + CryptoStore(#[from] InnerStoreError), +} + #[derive(Debug, thiserror::Error)] pub enum CryptoStoreError { #[error(transparent)] diff --git a/rust-sdk/src/lib.rs b/rust-sdk/src/lib.rs index 2f22012c78..e6799e9801 100644 --- a/rust-sdk/src/lib.rs +++ b/rust-sdk/src/lib.rs @@ -2,7 +2,7 @@ mod error; mod logger; mod machine; -pub use error::{CryptoStoreError, DecryptionError, MachineCreationError}; +pub use error::{CryptoStoreError, DecryptionError, KeyImportError, MachineCreationError}; pub use logger::{set_logger, Logger}; pub use machine::{ DecryptedEvent, Device, DeviceLists, KeysImportResult, OlmMachine, Request, RequestType, Sas, diff --git a/rust-sdk/src/machine.rs b/rust-sdk/src/machine.rs index d7dc13ca1f..1ef9a30379 100644 --- a/rust-sdk/src/machine.rs +++ b/rust-sdk/src/machine.rs @@ -30,8 +30,10 @@ use matrix_sdk_crypto::{ OlmMachine as InnerMachine, OutgoingRequest, ToDeviceRequest, }; -use crate::error::{CryptoStoreError, DecryptionError, MachineCreationError}; -use crate::ProgressListener; +use crate::{ + error::{CryptoStoreError, DecryptionError, MachineCreationError}, + KeyImportError, ProgressListener, +}; pub struct OlmMachine { inner: InnerMachine, @@ -440,9 +442,9 @@ impl OlmMachine { keys: &str, passphrase: &str, _: Box, - ) -> Result { + ) -> Result { let keys = Cursor::new(keys); - let keys = decrypt_key_export(keys, passphrase).unwrap(); + let keys = decrypt_key_export(keys, passphrase)?; // TODO use the progress listener let result = self.runtime.block_on(self.inner.import_keys(keys))?; diff --git a/rust-sdk/src/olm.udl b/rust-sdk/src/olm.udl index 7c61cdfb60..1d32503e15 100644 --- a/rust-sdk/src/olm.udl +++ b/rust-sdk/src/olm.udl @@ -16,6 +16,12 @@ enum MachineCreationError { "CryptoStore", }; +[Error] +enum KeyImportError { + "Export", + "CryptoStore", +}; + [Error] enum CryptoStoreError { "CryptoStore", @@ -115,7 +121,7 @@ interface OlmMachine { [Throws=CryptoStoreError] string export_keys([ByRef] string passphrase, i32 rounds); - [Throws=CryptoStoreError] + [Throws=KeyImportError] KeysImportResult import_keys( [ByRef] string keys, [ByRef] string passphrase,