From d9e5a17ab08b0386bbb32c1f0cbdeae876829be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 16:17:41 +0100 Subject: [PATCH] crypto: Use a native Rust sha2 implementation to calculate the commitment --- matrix_sdk_crypto/src/verification/sas/helpers.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/matrix_sdk_crypto/src/verification/sas/helpers.rs b/matrix_sdk_crypto/src/verification/sas/helpers.rs index 5a85e958..37974d14 100644 --- a/matrix_sdk_crypto/src/verification/sas/helpers.rs +++ b/matrix_sdk_crypto/src/verification/sas/helpers.rs @@ -14,9 +14,10 @@ use std::{collections::BTreeMap, convert::TryInto}; +use sha2::{Digest, Sha256}; use tracing::{trace, warn}; -use olm_rs::{sas::OlmSas, utility::OlmUtility}; +use olm_rs::sas::OlmSas; use matrix_sdk_common::{ api::r0::to_device::DeviceIdOrAllDevices, @@ -33,6 +34,7 @@ use matrix_sdk_common::{ use crate::{ identities::{ReadOnlyDevice, UserIdentities}, + utilities::encode, ReadOnlyAccount, ToDeviceRequest, }; @@ -59,8 +61,11 @@ pub fn calculate_commitment(public_key: &str, content: &StartToDeviceEventConten .try_into() .expect("Can't canonicalize content"); - let utility = OlmUtility::new(); - utility.sha256_utf8_msg(&format!("{}{}", public_key, json_content)) + encode( + Sha256::new() + .chain(&format!("{}{}", public_key, json_content)) + .finalize(), + ) } /// Get a tuple of an emoji and a description of the emoji using a number.