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_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)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum MachineCreationError {
|
pub enum MachineCreationError {
|
||||||
@ -9,6 +11,14 @@ pub enum MachineCreationError {
|
|||||||
CryptoStore(#[from] InnerStoreError),
|
CryptoStore(#[from] InnerStoreError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum KeyImportError {
|
||||||
|
#[error(transparent)]
|
||||||
|
Export(#[from] KeyExportError),
|
||||||
|
#[error(transparent)]
|
||||||
|
CryptoStore(#[from] InnerStoreError),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum CryptoStoreError {
|
pub enum CryptoStoreError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
@ -2,7 +2,7 @@ mod error;
|
|||||||
mod logger;
|
mod logger;
|
||||||
mod machine;
|
mod machine;
|
||||||
|
|
||||||
pub use error::{CryptoStoreError, DecryptionError, MachineCreationError};
|
pub use error::{CryptoStoreError, DecryptionError, KeyImportError, MachineCreationError};
|
||||||
pub use logger::{set_logger, Logger};
|
pub use logger::{set_logger, Logger};
|
||||||
pub use machine::{
|
pub use machine::{
|
||||||
DecryptedEvent, Device, DeviceLists, KeysImportResult, OlmMachine, Request, RequestType, Sas,
|
DecryptedEvent, Device, DeviceLists, KeysImportResult, OlmMachine, Request, RequestType, Sas,
|
||||||
|
@ -30,8 +30,10 @@ use matrix_sdk_crypto::{
|
|||||||
OlmMachine as InnerMachine, OutgoingRequest, ToDeviceRequest,
|
OlmMachine as InnerMachine, OutgoingRequest, ToDeviceRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::error::{CryptoStoreError, DecryptionError, MachineCreationError};
|
use crate::{
|
||||||
use crate::ProgressListener;
|
error::{CryptoStoreError, DecryptionError, MachineCreationError},
|
||||||
|
KeyImportError, ProgressListener,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct OlmMachine {
|
pub struct OlmMachine {
|
||||||
inner: InnerMachine,
|
inner: InnerMachine,
|
||||||
@ -440,9 +442,9 @@ impl OlmMachine {
|
|||||||
keys: &str,
|
keys: &str,
|
||||||
passphrase: &str,
|
passphrase: &str,
|
||||||
_: Box<dyn ProgressListener>,
|
_: Box<dyn ProgressListener>,
|
||||||
) -> Result<KeysImportResult, CryptoStoreError> {
|
) -> Result<KeysImportResult, KeyImportError> {
|
||||||
let keys = Cursor::new(keys);
|
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
|
// TODO use the progress listener
|
||||||
let result = self.runtime.block_on(self.inner.import_keys(keys))?;
|
let result = self.runtime.block_on(self.inner.import_keys(keys))?;
|
||||||
|
@ -16,6 +16,12 @@ enum MachineCreationError {
|
|||||||
"CryptoStore",
|
"CryptoStore",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[Error]
|
||||||
|
enum KeyImportError {
|
||||||
|
"Export",
|
||||||
|
"CryptoStore",
|
||||||
|
};
|
||||||
|
|
||||||
[Error]
|
[Error]
|
||||||
enum CryptoStoreError {
|
enum CryptoStoreError {
|
||||||
"CryptoStore",
|
"CryptoStore",
|
||||||
@ -115,7 +121,7 @@ interface OlmMachine {
|
|||||||
|
|
||||||
[Throws=CryptoStoreError]
|
[Throws=CryptoStoreError]
|
||||||
string export_keys([ByRef] string passphrase, i32 rounds);
|
string export_keys([ByRef] string passphrase, i32 rounds);
|
||||||
[Throws=CryptoStoreError]
|
[Throws=KeyImportError]
|
||||||
KeysImportResult import_keys(
|
KeysImportResult import_keys(
|
||||||
[ByRef] string keys,
|
[ByRef] string keys,
|
||||||
[ByRef] string passphrase,
|
[ByRef] string passphrase,
|
||||||
|
Loading…
Reference in New Issue
Block a user