diff --git a/crates/matrix-sdk-crypto/src/machine/mod.rs b/crates/matrix-sdk-crypto/src/machine/mod.rs index fc79eea1631..bef19dd510b 100644 --- a/crates/matrix-sdk-crypto/src/machine/mod.rs +++ b/crates/matrix-sdk-crypto/src/machine/mod.rs @@ -304,6 +304,13 @@ impl OlmMachine { }); } + // The own device data is always created and saved when the account is created. + // So we expect the own device to exist here. Checking for consistency. + let own_device = store.get_own_device().await; + if own_device.is_err() { + return Err(CryptoStoreError::IncompleteAccountNoOwnDevice); + } + Span::current() .record("ed25519_key", display(account.identity_keys().ed25519)) .record("curve25519_key", display(account.identity_keys().curve25519)); diff --git a/crates/matrix-sdk-crypto/src/store/error.rs b/crates/matrix-sdk-crypto/src/store/error.rs index e40126a5c0d..ba11a1784f9 100644 --- a/crates/matrix-sdk-crypto/src/store/error.rs +++ b/crates/matrix-sdk-crypto/src/store/error.rs @@ -31,6 +31,10 @@ pub enum CryptoStoreError { #[error("can't save/load sessions or group sessions in the store before an account is stored")] AccountUnset, + /// An account was saved but no own device was found. + #[error("Incomplete account, account data was saved but no own device was found")] + IncompleteAccountNoOwnDevice, + /// The store doesn't support multiple accounts and data from another device /// was discovered. #[error(