crypto: Handle key export decyrption errors
This commit is contained in:
parent
6af8041fb4
commit
10c7f5b989
@ -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)]
|
||||
|
@ -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,
|
||||
|
@ -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<dyn ProgressListener>,
|
||||
) -> Result<KeysImportResult, CryptoStoreError> {
|
||||
) -> Result<KeysImportResult, KeyImportError> {
|
||||
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))?;
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user