mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2026-02-04 15:51:23 +01:00
Remove useless re-serialization
There's no reason to construct a serde_json::Value in the first place, a CanonicalJsonObject is all we ever need.
This commit is contained in:
parent
7a7a839862
commit
96b0f9ca34
1 changed files with 6 additions and 11 deletions
|
|
@ -12,7 +12,7 @@ use ruma::{
|
||||||
},
|
},
|
||||||
serde::Base64,
|
serde::Base64,
|
||||||
server_util::authorization::XMatrix,
|
server_util::authorization::XMatrix,
|
||||||
OwnedServerName, OwnedSigningKeyId, ServerName,
|
CanonicalJsonObject, OwnedServerName, OwnedSigningKeyId, ServerName,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::{debug, error, field, warn};
|
use tracing::{debug, error, field, warn};
|
||||||
|
|
@ -94,7 +94,7 @@ fn create_request_signature(
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
destination: OwnedServerName,
|
destination: OwnedServerName,
|
||||||
) -> Result<Authorization<XMatrix>, RequestSignError> {
|
) -> Result<Authorization<XMatrix>, RequestSignError> {
|
||||||
let mut request_map = serde_json::Map::new();
|
let mut request_map = CanonicalJsonObject::new();
|
||||||
|
|
||||||
if !http_request.body().is_empty() {
|
if !http_request.body().is_empty() {
|
||||||
request_map.insert(
|
request_map.insert(
|
||||||
|
|
@ -120,22 +120,17 @@ fn create_request_signature(
|
||||||
);
|
);
|
||||||
request_map.insert("destination".to_owned(), destination.as_str().into());
|
request_map.insert("destination".to_owned(), destination.as_str().into());
|
||||||
|
|
||||||
let mut request_json = serde_json::from_value(request_map.into())
|
|
||||||
.expect("valid JSON is valid BTreeMap");
|
|
||||||
|
|
||||||
ruma::signatures::sign_json(
|
ruma::signatures::sign_json(
|
||||||
services().globals.server_name().as_str(),
|
services().globals.server_name().as_str(),
|
||||||
services().globals.keypair(),
|
services().globals.keypair(),
|
||||||
&mut request_json,
|
&mut request_map,
|
||||||
)
|
)
|
||||||
.expect("our request json is what ruma expects");
|
.expect("our request json is what ruma expects");
|
||||||
|
|
||||||
let request_json: serde_json::Map<String, serde_json::Value> =
|
|
||||||
serde_json::from_slice(&serde_json::to_vec(&request_json).unwrap())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// There's exactly the one signature we just created, fish it back out again
|
// There's exactly the one signature we just created, fish it back out again
|
||||||
let (key_id, signature) = request_json["signatures"]
|
let (key_id, signature) = request_map["signatures"]
|
||||||
|
.as_object()
|
||||||
|
.unwrap()
|
||||||
.get(services().globals.server_name().as_str())
|
.get(services().globals.server_name().as_str())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_object()
|
.as_object()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue