From 96e26651bc77a8998a46dbff5725f46d18f826db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 19 Jul 2021 13:18:25 +0200 Subject: [PATCH] crypto: Bump the olm-rs version --- matrix_sdk_crypto/Cargo.toml | 2 +- .../src/olm/group_sessions/outbound.rs | 2 +- matrix_sdk_crypto/src/olm/signing/pk_signing.rs | 17 ++++++++--------- matrix_sdk_crypto/src/olm/utility.rs | 9 +++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/matrix_sdk_crypto/Cargo.toml b/matrix_sdk_crypto/Cargo.toml index 6aae90c5..587e420e 100644 --- a/matrix_sdk_crypto/Cargo.toml +++ b/matrix_sdk_crypto/Cargo.toml @@ -24,7 +24,7 @@ matrix-qrcode = { version = "0.1.0", path = "../matrix_qrcode" } matrix-sdk-common = { version = "0.3.0", path = "../matrix_sdk_common" } ruma = { version = "0.3.0", features = ["client-api-c", "unstable-pre-spec"] } -olm-rs = { version = "1.0.1", features = ["serde"] } +olm-rs = { version = "2.0", features = ["serde"] } getrandom = "0.2.3" serde = { version = "1.0.126", features = ["derive", "rc"] } serde_json = "1.0.64" diff --git a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs index b432e44e..733f91c1 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs @@ -249,7 +249,7 @@ impl OutboundGroupSession { pub(crate) async fn encrypt_helper(&self, plaintext: String) -> String { let session = self.inner.lock().await; self.message_count.fetch_add(1, Ordering::SeqCst); - session.encrypt(plaintext) + session.encrypt(&plaintext) } /// Encrypt a room message for the given room. diff --git a/matrix_sdk_crypto/src/olm/signing/pk_signing.rs b/matrix_sdk_crypto/src/olm/signing/pk_signing.rs index 61ba5bcd..b96628bd 100644 --- a/matrix_sdk_crypto/src/olm/signing/pk_signing.rs +++ b/matrix_sdk_crypto/src/olm/signing/pk_signing.rs @@ -108,13 +108,6 @@ pub struct PickledSelfSigning { public_key: CrossSigningKey, } -impl Signature { - #[cfg(test)] - pub fn as_str(&self) -> &str { - &self.0 - } -} - impl PickledSigning { pub fn as_str(&self) -> &str { &self.0 @@ -288,6 +281,12 @@ pub struct PickledSignings { #[derive(Debug, Clone)] pub struct Signature(String); +impl std::fmt::Display for Signature { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PickledSigning(String); @@ -298,7 +297,7 @@ impl Signing { } pub fn from_seed(seed: Vec) -> Self { - let inner = OlmPkSigning::new(seed.clone()).expect("Unable to create pk signing object"); + let inner = OlmPkSigning::new(&seed).expect("Unable to create pk signing object"); let public_key = PublicSigningKey(inner.public_key().into()); Signing { @@ -366,7 +365,7 @@ impl Signing { signature: &Signature, ) -> Result { let utility = OlmUtility::new(); - utility.ed25519_verify(self.public_key.as_str(), message, signature.as_str()) + utility.ed25519_verify(self.public_key.as_str(), message, signature.to_string()) } pub async fn sign_json(&self, mut json: Value) -> Result { diff --git a/matrix_sdk_crypto/src/olm/utility.rs b/matrix_sdk_crypto/src/olm/utility.rs index 49922d18..32a76991 100644 --- a/matrix_sdk_crypto/src/olm/utility.rs +++ b/matrix_sdk_crypto/src/olm/utility.rs @@ -75,10 +75,11 @@ impl Utility { signature.get(key_id.to_string()).ok_or(SignatureError::NoSignatureFound)?; let signature = signature.as_str().ok_or(SignatureError::NoSignatureFound)?; - let ret = match self.inner.ed25519_verify(signing_key, &canonical_json, signature) { - Ok(_) => Ok(()), - Err(_) => Err(SignatureError::VerificationError), - }; + let ret = + match self.inner.ed25519_verify(signing_key, &canonical_json, signature.to_owned()) { + Ok(_) => Ok(()), + Err(_) => Err(SignatureError::VerificationError), + }; let json_object = json.as_object_mut().ok_or(SignatureError::NotAnObject)?;