Abstract and simplify serde_json round-trip to Ruma Raw.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -17,7 +17,9 @@ use ruma::{
|
|||||||
serde::Raw,
|
serde::Raw,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tuwunel_core::{Err, Result, debug, debug_error, debug_warn, err, result::NotFound};
|
use tuwunel_core::{
|
||||||
|
Err, Result, debug, debug_error, debug_warn, err, result::NotFound, utils::json,
|
||||||
|
};
|
||||||
use tuwunel_service::{Services, users::parse_master_key};
|
use tuwunel_service::{Services, users::parse_master_key};
|
||||||
|
|
||||||
use crate::{Ruma, router::auth_uiaa};
|
use crate::{Ruma, router::auth_uiaa};
|
||||||
@@ -537,16 +539,16 @@ where
|
|||||||
.signatures
|
.signatures
|
||||||
.append(&mut our_master_key.signatures);
|
.append(&mut our_master_key.signatures);
|
||||||
}
|
}
|
||||||
let json = serde_json::to_value(master_key).expect("to_value always works");
|
|
||||||
let raw = serde_json::from_value(json).expect("Raw::from_value always works");
|
// Dont notify. A notification would trigger another key request resulting in
|
||||||
|
// an endless loop.
|
||||||
|
let notify = false;
|
||||||
|
let raw = Some(json::to_raw(master_key)?);
|
||||||
services
|
services
|
||||||
.users
|
.users
|
||||||
.add_cross_signing_keys(
|
.add_cross_signing_keys(&user, &raw, &None, &None, notify)
|
||||||
&user, &raw, &None, &None,
|
|
||||||
false, /* Dont notify. A notification would trigger another key
|
|
||||||
* request resulting in an endless loop */
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(raw) = raw {
|
if let Some(raw) = raw {
|
||||||
master_keys.insert(user.clone(), raw);
|
master_keys.insert(user.clone(), raw);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
use std::{fmt, marker::PhantomData, str::FromStr};
|
use std::{fmt, marker::PhantomData, str::FromStr};
|
||||||
|
|
||||||
use ruma::{CanonicalJsonError, CanonicalJsonObject, canonical_json::try_from_json_map};
|
use ruma::{
|
||||||
|
CanonicalJsonError, CanonicalJsonObject, canonical_json::try_from_json_map, serde::Raw,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
|
/// Perform a round-trip through serde_json starting with a native type T and
|
||||||
|
/// ending with a Ruma Raw<U> which is usually just T.
|
||||||
|
pub fn to_raw<T: serde::Serialize, U>(input: T) -> Result<Raw<U>> {
|
||||||
|
Ok(serde_json::from_value(serde_json::to_value(input)?)?)
|
||||||
|
}
|
||||||
|
|
||||||
/// Fallible conversion from any value that implements `Serialize` to a
|
/// Fallible conversion from any value that implements `Serialize` to a
|
||||||
/// `CanonicalJsonObject`.
|
/// `CanonicalJsonObject`.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user