mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 11:05:32 -04:00
Remove an unnecessary unwrap in the crypto crate (#2226)
This commit is contained in:
@@ -1222,8 +1222,10 @@ impl OlmMachine {
|
||||
///
|
||||
/// This method returns `None` if we don't have any private cross signing
|
||||
/// keys.
|
||||
pub fn export_cross_signing_keys(&self) -> Option<CrossSigningKeyExport> {
|
||||
self.runtime.block_on(self.inner.export_cross_signing_keys()).map(|e| e.into())
|
||||
pub fn export_cross_signing_keys(
|
||||
&self,
|
||||
) -> Result<Option<CrossSigningKeyExport>, CryptoStoreError> {
|
||||
Ok(self.runtime.block_on(self.inner.export_cross_signing_keys())?.map(|e| e.into()))
|
||||
}
|
||||
|
||||
/// Import our private cross signing keys.
|
||||
|
||||
@@ -407,7 +407,7 @@ impl OlmMachine {
|
||||
let me = self.inner.clone();
|
||||
|
||||
future_to_promise(async move {
|
||||
Ok(me.export_cross_signing_keys().await.map(store::CrossSigningKeyExport::from))
|
||||
Ok(me.export_cross_signing_keys().await?.map(store::CrossSigningKeyExport::from))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# v0.7.0
|
||||
|
||||
- The `OlmMachine::export_cross_signing_keys()` method now returns a `Result`.
|
||||
This removes an `unwrap()` from the codebase.
|
||||
|
||||
- Add support for the `hkdf-hmac-sha256.v2` SAS message authentication code.
|
||||
|
||||
- Ensure that the correct short authentication strings are used when accepting a
|
||||
|
||||
@@ -269,7 +269,7 @@ impl GossipMachine {
|
||||
}
|
||||
};
|
||||
|
||||
let content = if let Some(secret) = self.inner.store.export_secret(secret_name).await {
|
||||
let content = if let Some(secret) = self.inner.store.export_secret(secret_name).await? {
|
||||
SecretSendContent::new(event.content.request_id.to_owned(), secret)
|
||||
} else {
|
||||
info!(?secret_name, "Can't serve a secret request, secret isn't found");
|
||||
|
||||
@@ -1674,18 +1674,18 @@ impl OlmMachine {
|
||||
///
|
||||
/// This method returns `None` if we don't have any private cross signing
|
||||
/// keys.
|
||||
pub async fn export_cross_signing_keys(&self) -> Option<CrossSigningKeyExport> {
|
||||
let master_key = self.store().export_secret(&SecretName::CrossSigningMasterKey).await;
|
||||
pub async fn export_cross_signing_keys(&self) -> StoreResult<Option<CrossSigningKeyExport>> {
|
||||
let master_key = self.store().export_secret(&SecretName::CrossSigningMasterKey).await?;
|
||||
let self_signing_key =
|
||||
self.store().export_secret(&SecretName::CrossSigningSelfSigningKey).await;
|
||||
self.store().export_secret(&SecretName::CrossSigningSelfSigningKey).await?;
|
||||
let user_signing_key =
|
||||
self.store().export_secret(&SecretName::CrossSigningUserSigningKey).await;
|
||||
self.store().export_secret(&SecretName::CrossSigningUserSigningKey).await?;
|
||||
|
||||
if master_key.is_none() && self_signing_key.is_none() && user_signing_key.is_none() {
|
||||
Ok(if master_key.is_none() && self_signing_key.is_none() && user_signing_key.is_none() {
|
||||
None
|
||||
} else {
|
||||
Some(CrossSigningKeyExport { master_key, self_signing_key, user_signing_key })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Import our private cross signing keys.
|
||||
|
||||
@@ -640,8 +640,11 @@ impl Store {
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `secret_name` - The name of the secret that should be exported.
|
||||
pub(crate) async fn export_secret(&self, secret_name: &SecretName) -> Option<String> {
|
||||
match secret_name {
|
||||
pub async fn export_secret(
|
||||
&self,
|
||||
secret_name: &SecretName,
|
||||
) -> Result<Option<String>, CryptoStoreError> {
|
||||
Ok(match secret_name {
|
||||
SecretName::CrossSigningMasterKey
|
||||
| SecretName::CrossSigningUserSigningKey
|
||||
| SecretName::CrossSigningSelfSigningKey => {
|
||||
@@ -649,7 +652,7 @@ impl Store {
|
||||
}
|
||||
SecretName::RecoveryKey => {
|
||||
#[cfg(feature = "backups_v1")]
|
||||
if let Some(key) = self.load_backup_keys().await.unwrap().recovery_key {
|
||||
if let Some(key) = self.load_backup_keys().await?.recovery_key {
|
||||
let exported = key.to_base64();
|
||||
Some(exported)
|
||||
} else {
|
||||
@@ -663,7 +666,7 @@ impl Store {
|
||||
warn!(secret = ?name, "Unknown secret was requested");
|
||||
None
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Import the Cross Signing Keys
|
||||
|
||||
Reference in New Issue
Block a user