From d5bd6bd61d68906491ebf79c09bc33ae9d7ad3ed Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 5 Jun 2020 17:46:29 +0200 Subject: [PATCH] Rerun cargo fmt --- ruma-signatures/src/functions.rs | 63 +++++++---------------------- ruma-signatures/src/lib.rs | 15 ++----- ruma-signatures/src/signatures.rs | 6 +-- ruma-signatures/src/verification.rs | 6 +-- 4 files changed, 20 insertions(+), 70 deletions(-) diff --git a/ruma-signatures/src/functions.rs b/ruma-signatures/src/functions.rs index 1f18c23d..9fed2b33 100644 --- a/ruma-signatures/src/functions.rs +++ b/ruma-signatures/src/functions.rs @@ -139,9 +139,8 @@ where let signature = key_pair.sign(json.as_bytes()); // Insert the new signature in the map we pulled out (or created) previously. - let signature_set = signature_map - .entry(entity_id.to_string()) - .or_insert_with(|| HashMap::with_capacity(1)); + let signature_set = + signature_map.entry(entity_id.to_string()).or_insert_with(|| HashMap::with_capacity(1)); signature_set.insert(signature.id(), signature.base64()); @@ -247,10 +246,7 @@ pub fn verify_json(public_key_map: &PublicKeyMap, value: &Value) -> Result<(), E let signature_set = match signature_map.get(entity_id) { Some(set) => set, None => { - return Err(Error::new(format!( - "no signatures found for entity `{}`", - entity_id - ))) + return Err(Error::new(format!("no signatures found for entity `{}`", entity_id))) } }; @@ -275,18 +271,14 @@ pub fn verify_json(public_key_map: &PublicKeyMap, value: &Value) -> Result<(), E let signature = match maybe_signature { Some(signature) => signature, None => { - return Err(Error::new( - "event is not signed with any of the given public keys", - )) + return Err(Error::new("event is not signed with any of the given public keys")) } }; let public_key = match maybe_public_key { Some(public_key) => public_key, None => { - return Err(Error::new( - "event is not signed with any of the given public keys", - )) + return Err(Error::new("event is not signed with any of the given public keys")) } }; @@ -476,9 +468,8 @@ where _ => return Err(Error::new("JSON value must be a JSON object")), }; - let hashes_value = map - .entry("hashes") - .or_insert_with(|| Value::Object(Map::with_capacity(1))); + let hashes_value = + map.entry("hashes").or_insert_with(|| Value::Object(Map::with_capacity(1))); match hashes_value.as_object_mut() { Some(hashes) => hashes.insert("sha256".to_string(), Value::String(hash)), @@ -593,10 +584,7 @@ pub fn verify_event(public_key_map: &PublicKeyMap, value: &Value) -> Result set, None => { - return Err(Error::new(format!( - "no signatures found for entity `{}`", - entity_id - ))) + return Err(Error::new(format!("no signatures found for entity `{}`", entity_id))) } }; @@ -621,18 +609,14 @@ pub fn verify_event(public_key_map: &PublicKeyMap, value: &Value) -> Result signature, None => { - return Err(Error::new( - "event is not signed with any of the given public keys", - )) + return Err(Error::new("event is not signed with any of the given public keys")) } }; let public_key = match maybe_public_key { Some(public_key) => public_key, None => { - return Err(Error::new( - "event is not signed with any of the given public keys", - )) + return Err(Error::new("event is not signed with any of the given public keys")) } }; @@ -642,12 +626,7 @@ pub fn verify_event(public_key_map: &PublicKeyMap, value: &Value) -> Result Resul let mut owned_value = value.clone(); { - let object = owned_value - .as_object_mut() - .expect("safe since we checked above"); + let object = owned_value.as_object_mut().expect("safe since we checked above"); for field in fields { object.remove(*field); @@ -711,9 +688,7 @@ pub fn redact(value: &Value) -> Result { let mut owned_value = value.clone(); - let event = owned_value - .as_object_mut() - .expect("safe since we checked above"); + let event = owned_value.as_object_mut().expect("safe since we checked above"); let event_type_value = match event.get("type") { Some(event_type_value) => event_type_value, @@ -722,21 +697,13 @@ pub fn redact(value: &Value) -> Result { let event_type = match event_type_value.as_str() { Some(event_type) => event_type.to_string(), - None => { - return Err(Error::new( - "field `type` in JSON value must be a JSON string", - )) - } + None => return Err(Error::new("field `type` in JSON value must be a JSON string")), }; if let Some(content_value) = event.get_mut("content") { let map = match content_value { Value::Object(ref mut map) => map, - _ => { - return Err(Error::new( - "field `content` in JSON value must be a JSON object", - )) - } + _ => return Err(Error::new("field `content` in JSON value must be a JSON object")), }; for key in map.clone().keys() { diff --git a/ruma-signatures/src/lib.rs b/ruma-signatures/src/lib.rs index 907e8787..14482edd 100644 --- a/ruma-signatures/src/lib.rs +++ b/ruma-signatures/src/lib.rs @@ -42,11 +42,7 @@ //! these respective functions for more details and full examples of use. #![warn(rust_2018_idioms)] -#![deny( - missing_copy_implementations, - missing_debug_implementations, - missing_docs -)] +#![deny(missing_copy_implementations, missing_debug_implementations, missing_docs)] use std::{ error::Error as StdError, @@ -82,9 +78,7 @@ impl Error { where T: Into, { - Self { - message: message.into(), - } + Self { message: message.into() } } } @@ -233,10 +227,7 @@ mod test { r#"{"a":"1","b":"2"}"# ); - assert_eq!( - &test_canonical_json(r#"{"b":"2","a":"1"}"#), - r#"{"a":"1","b":"2"}"# - ); + assert_eq!(&test_canonical_json(r#"{"b":"2","a":"1"}"#), r#"{"a":"1","b":"2"}"#); assert_eq!( &test_canonical_json( diff --git a/ruma-signatures/src/signatures.rs b/ruma-signatures/src/signatures.rs index f1a03033..26d9b49b 100644 --- a/ruma-signatures/src/signatures.rs +++ b/ruma-signatures/src/signatures.rs @@ -52,11 +52,7 @@ impl Signature { } })?; - Ok(Self { - algorithm, - signature: bytes.to_vec(), - version, - }) + Ok(Self { algorithm, signature: bytes.to_vec(), version }) } /// The algorithm used to generate the signature. diff --git a/ruma-signatures/src/verification.rs b/ruma-signatures/src/verification.rs index f8df82be..5709b108 100644 --- a/ruma-signatures/src/verification.rs +++ b/ruma-signatures/src/verification.rs @@ -34,11 +34,7 @@ impl Verifier for Ed25519Verifier { message: &[u8], ) -> Result<(), Error> { ED25519 - .verify( - Input::from(public_key), - Input::from(message), - Input::from(signature), - ) + .verify(Input::from(public_key), Input::from(message), Input::from(signature)) .map_err(|_| Error::new("signature verification failed")) } }