crypto: Add a hack so e2ee support works under WASM again
This commit is contained in:
parent
d10b85a05d
commit
077050efb4
3 changed files with 36 additions and 0 deletions
|
@ -56,6 +56,8 @@ use crate::{
|
|||
Sas, ToDeviceRequest,
|
||||
};
|
||||
|
||||
use super::{atomic_bool_deserializer, atomic_bool_serializer};
|
||||
|
||||
/// A read-only version of a `Device`.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ReadOnlyDevice {
|
||||
|
@ -65,6 +67,10 @@ pub struct ReadOnlyDevice {
|
|||
keys: Arc<BTreeMap<DeviceKeyId, String>>,
|
||||
pub(crate) signatures: Arc<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>,
|
||||
display_name: Arc<Option<String>>,
|
||||
#[serde(
|
||||
serialize_with = "atomic_bool_serializer",
|
||||
deserialize_with = "atomic_bool_deserializer"
|
||||
)]
|
||||
deleted: Arc<AtomicBool>,
|
||||
#[serde(
|
||||
serialize_with = "local_trust_serializer",
|
||||
|
|
|
@ -50,3 +50,27 @@ pub use user::{
|
|||
MasterPubkey, OwnUserIdentity, SelfSigningPubkey, UserIdentities, UserIdentity,
|
||||
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)))
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ use matrix_sdk_common::{
|
|||
use crate::olm::PrivateCrossSigningIdentity;
|
||||
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.
|
||||
///
|
||||
/// Master keys are used to sign other cross signing keys, the self signing and
|
||||
|
@ -573,6 +575,10 @@ pub struct OwnUserIdentity {
|
|||
master_key: MasterPubkey,
|
||||
self_signing_key: SelfSigningPubkey,
|
||||
user_signing_key: UserSigningPubkey,
|
||||
#[serde(
|
||||
serialize_with = "atomic_bool_serializer",
|
||||
deserialize_with = "atomic_bool_deserializer"
|
||||
)]
|
||||
verified: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue