crypto: Add a hack so e2ee support works under WASM again

This commit is contained in:
Damir Jelić 2021-01-22 18:40:08 +01:00
parent d10b85a05d
commit 077050efb4
3 changed files with 36 additions and 0 deletions

View file

@ -56,6 +56,8 @@ use crate::{
Sas, ToDeviceRequest, Sas, ToDeviceRequest,
}; };
use super::{atomic_bool_deserializer, atomic_bool_serializer};
/// A read-only version of a `Device`. /// A read-only version of a `Device`.
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReadOnlyDevice { pub struct ReadOnlyDevice {
@ -65,6 +67,10 @@ pub struct ReadOnlyDevice {
keys: Arc<BTreeMap<DeviceKeyId, String>>, keys: Arc<BTreeMap<DeviceKeyId, String>>,
pub(crate) signatures: Arc<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>, pub(crate) signatures: Arc<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>,
display_name: Arc<Option<String>>, display_name: Arc<Option<String>>,
#[serde(
serialize_with = "atomic_bool_serializer",
deserialize_with = "atomic_bool_deserializer"
)]
deleted: Arc<AtomicBool>, deleted: Arc<AtomicBool>,
#[serde( #[serde(
serialize_with = "local_trust_serializer", serialize_with = "local_trust_serializer",

View file

@ -50,3 +50,27 @@ pub use user::{
MasterPubkey, OwnUserIdentity, SelfSigningPubkey, UserIdentities, UserIdentity, MasterPubkey, OwnUserIdentity, SelfSigningPubkey, UserIdentities, UserIdentity,
UserSigningPubkey, UserSigningPubkey,
}; };
use serde::{Deserialize, Deserializer, Serializer};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
// These methods are only here because Serialize and Deserialize don't seem to
// be implemented for WASM.
fn atomic_bool_serializer<S>(x: &AtomicBool, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let value = x.load(Ordering::SeqCst);
s.serialize_some(&value)
}
fn atomic_bool_deserializer<'de, D>(deserializer: D) -> Result<Arc<AtomicBool>, D::Error>
where
D: Deserializer<'de>,
{
let value = bool::deserialize(deserializer)?;
Ok(Arc::new(AtomicBool::new(value)))
}

View file

@ -33,6 +33,8 @@ use matrix_sdk_common::{
use crate::olm::PrivateCrossSigningIdentity; use crate::olm::PrivateCrossSigningIdentity;
use crate::{error::SignatureError, olm::Utility, ReadOnlyDevice}; use crate::{error::SignatureError, olm::Utility, ReadOnlyDevice};
use super::{atomic_bool_deserializer, atomic_bool_serializer};
/// Wrapper for a cross signing key marking it as the master key. /// Wrapper for a cross signing key marking it as the master key.
/// ///
/// Master keys are used to sign other cross signing keys, the self signing and /// Master keys are used to sign other cross signing keys, the self signing and
@ -573,6 +575,10 @@ pub struct OwnUserIdentity {
master_key: MasterPubkey, master_key: MasterPubkey,
self_signing_key: SelfSigningPubkey, self_signing_key: SelfSigningPubkey,
user_signing_key: UserSigningPubkey, user_signing_key: UserSigningPubkey,
#[serde(
serialize_with = "atomic_bool_serializer",
deserialize_with = "atomic_bool_deserializer"
)]
verified: Arc<AtomicBool>, verified: Arc<AtomicBool>,
} }