crypto: Use a native Rust sha2 implementation to calculate the commitment
parent
b5c61af472
commit
d9e5a17ab0
|
@ -14,9 +14,10 @@
|
||||||
|
|
||||||
use std::{collections::BTreeMap, convert::TryInto};
|
use std::{collections::BTreeMap, convert::TryInto};
|
||||||
|
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
use tracing::{trace, warn};
|
use tracing::{trace, warn};
|
||||||
|
|
||||||
use olm_rs::{sas::OlmSas, utility::OlmUtility};
|
use olm_rs::sas::OlmSas;
|
||||||
|
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::to_device::DeviceIdOrAllDevices,
|
api::r0::to_device::DeviceIdOrAllDevices,
|
||||||
|
@ -33,6 +34,7 @@ use matrix_sdk_common::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
identities::{ReadOnlyDevice, UserIdentities},
|
identities::{ReadOnlyDevice, UserIdentities},
|
||||||
|
utilities::encode,
|
||||||
ReadOnlyAccount, ToDeviceRequest,
|
ReadOnlyAccount, ToDeviceRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,8 +61,11 @@ pub fn calculate_commitment(public_key: &str, content: &StartToDeviceEventConten
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("Can't canonicalize content");
|
.expect("Can't canonicalize content");
|
||||||
|
|
||||||
let utility = OlmUtility::new();
|
encode(
|
||||||
utility.sha256_utf8_msg(&format!("{}{}", public_key, json_content))
|
Sha256::new()
|
||||||
|
.chain(&format!("{}{}", public_key, json_content))
|
||||||
|
.finalize(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a tuple of an emoji and a description of the emoji using a number.
|
/// Get a tuple of an emoji and a description of the emoji using a number.
|
||||||
|
|
Loading…
Reference in New Issue