Rerun cargo fmt
This commit is contained in:
parent
edda62f52d
commit
d5bd6bd61d
@ -139,9 +139,8 @@ where
|
|||||||
let signature = key_pair.sign(json.as_bytes());
|
let signature = key_pair.sign(json.as_bytes());
|
||||||
|
|
||||||
// Insert the new signature in the map we pulled out (or created) previously.
|
// Insert the new signature in the map we pulled out (or created) previously.
|
||||||
let signature_set = signature_map
|
let signature_set =
|
||||||
.entry(entity_id.to_string())
|
signature_map.entry(entity_id.to_string()).or_insert_with(|| HashMap::with_capacity(1));
|
||||||
.or_insert_with(|| HashMap::with_capacity(1));
|
|
||||||
|
|
||||||
signature_set.insert(signature.id(), signature.base64());
|
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) {
|
let signature_set = match signature_map.get(entity_id) {
|
||||||
Some(set) => set,
|
Some(set) => set,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(format!(
|
return Err(Error::new(format!("no signatures found for entity `{}`", entity_id)))
|
||||||
"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 {
|
let signature = match maybe_signature {
|
||||||
Some(signature) => signature,
|
Some(signature) => signature,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(
|
return Err(Error::new("event is not signed with any of the given public keys"))
|
||||||
"event is not signed with any of the given public keys",
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let public_key = match maybe_public_key {
|
let public_key = match maybe_public_key {
|
||||||
Some(public_key) => public_key,
|
Some(public_key) => public_key,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(
|
return Err(Error::new("event is not signed with any of the given public keys"))
|
||||||
"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")),
|
_ => return Err(Error::new("JSON value must be a JSON object")),
|
||||||
};
|
};
|
||||||
|
|
||||||
let hashes_value = map
|
let hashes_value =
|
||||||
.entry("hashes")
|
map.entry("hashes").or_insert_with(|| Value::Object(Map::with_capacity(1)));
|
||||||
.or_insert_with(|| Value::Object(Map::with_capacity(1)));
|
|
||||||
|
|
||||||
match hashes_value.as_object_mut() {
|
match hashes_value.as_object_mut() {
|
||||||
Some(hashes) => hashes.insert("sha256".to_string(), Value::String(hash)),
|
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<Veri
|
|||||||
let signature_set = match signature_map.get(entity_id) {
|
let signature_set = match signature_map.get(entity_id) {
|
||||||
Some(set) => set,
|
Some(set) => set,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(format!(
|
return Err(Error::new(format!("no signatures found for entity `{}`", entity_id)))
|
||||||
"no signatures found for entity `{}`",
|
|
||||||
entity_id
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -621,18 +609,14 @@ pub fn verify_event(public_key_map: &PublicKeyMap, value: &Value) -> Result<Veri
|
|||||||
let signature = match maybe_signature {
|
let signature = match maybe_signature {
|
||||||
Some(signature) => signature,
|
Some(signature) => signature,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(
|
return Err(Error::new("event is not signed with any of the given public keys"))
|
||||||
"event is not signed with any of the given public keys",
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let public_key = match maybe_public_key {
|
let public_key = match maybe_public_key {
|
||||||
Some(public_key) => public_key,
|
Some(public_key) => public_key,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(
|
return Err(Error::new("event is not signed with any of the given public keys"))
|
||||||
"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<Veri
|
|||||||
|
|
||||||
let public_key_bytes = decode_config(&public_key, STANDARD_NO_PAD)?;
|
let public_key_bytes = decode_config(&public_key, STANDARD_NO_PAD)?;
|
||||||
|
|
||||||
verify_json_with(
|
verify_json_with(&Ed25519Verifier, &public_key_bytes, &signature_bytes, &canonical_json)?;
|
||||||
&Ed25519Verifier,
|
|
||||||
&public_key_bytes,
|
|
||||||
&signature_bytes,
|
|
||||||
&canonical_json,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let calculated_hash = content_hash(value)?;
|
let calculated_hash = content_hash(value)?;
|
||||||
@ -669,9 +648,7 @@ fn canonical_json_with_fields_to_remove(value: &Value, fields: &[&str]) -> Resul
|
|||||||
let mut owned_value = value.clone();
|
let mut owned_value = value.clone();
|
||||||
|
|
||||||
{
|
{
|
||||||
let object = owned_value
|
let object = owned_value.as_object_mut().expect("safe since we checked above");
|
||||||
.as_object_mut()
|
|
||||||
.expect("safe since we checked above");
|
|
||||||
|
|
||||||
for field in fields {
|
for field in fields {
|
||||||
object.remove(*field);
|
object.remove(*field);
|
||||||
@ -711,9 +688,7 @@ pub fn redact(value: &Value) -> Result<Value, Error> {
|
|||||||
|
|
||||||
let mut owned_value = value.clone();
|
let mut owned_value = value.clone();
|
||||||
|
|
||||||
let event = owned_value
|
let event = owned_value.as_object_mut().expect("safe since we checked above");
|
||||||
.as_object_mut()
|
|
||||||
.expect("safe since we checked above");
|
|
||||||
|
|
||||||
let event_type_value = match event.get("type") {
|
let event_type_value = match event.get("type") {
|
||||||
Some(event_type_value) => event_type_value,
|
Some(event_type_value) => event_type_value,
|
||||||
@ -722,21 +697,13 @@ pub fn redact(value: &Value) -> Result<Value, Error> {
|
|||||||
|
|
||||||
let event_type = match event_type_value.as_str() {
|
let event_type = match event_type_value.as_str() {
|
||||||
Some(event_type) => event_type.to_string(),
|
Some(event_type) => event_type.to_string(),
|
||||||
None => {
|
None => return Err(Error::new("field `type` in JSON value must be a JSON string")),
|
||||||
return Err(Error::new(
|
|
||||||
"field `type` in JSON value must be a JSON string",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(content_value) = event.get_mut("content") {
|
if let Some(content_value) = event.get_mut("content") {
|
||||||
let map = match content_value {
|
let map = match content_value {
|
||||||
Value::Object(ref mut map) => map,
|
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() {
|
for key in map.clone().keys() {
|
||||||
|
@ -42,11 +42,7 @@
|
|||||||
//! these respective functions for more details and full examples of use.
|
//! these respective functions for more details and full examples of use.
|
||||||
|
|
||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![deny(
|
#![deny(missing_copy_implementations, missing_debug_implementations, missing_docs)]
|
||||||
missing_copy_implementations,
|
|
||||||
missing_debug_implementations,
|
|
||||||
missing_docs
|
|
||||||
)]
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
error::Error as StdError,
|
error::Error as StdError,
|
||||||
@ -82,9 +78,7 @@ impl Error {
|
|||||||
where
|
where
|
||||||
T: Into<String>,
|
T: Into<String>,
|
||||||
{
|
{
|
||||||
Self {
|
Self { message: message.into() }
|
||||||
message: message.into(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,10 +227,7 @@ mod test {
|
|||||||
r#"{"a":"1","b":"2"}"#
|
r#"{"a":"1","b":"2"}"#
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(&test_canonical_json(r#"{"b":"2","a":"1"}"#), r#"{"a":"1","b":"2"}"#);
|
||||||
&test_canonical_json(r#"{"b":"2","a":"1"}"#),
|
|
||||||
r#"{"a":"1","b":"2"}"#
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&test_canonical_json(
|
&test_canonical_json(
|
||||||
|
@ -52,11 +52,7 @@ impl Signature {
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self { algorithm, signature: bytes.to_vec(), version })
|
||||||
algorithm,
|
|
||||||
signature: bytes.to_vec(),
|
|
||||||
version,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The algorithm used to generate the signature.
|
/// The algorithm used to generate the signature.
|
||||||
|
@ -34,11 +34,7 @@ impl Verifier for Ed25519Verifier {
|
|||||||
message: &[u8],
|
message: &[u8],
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
ED25519
|
ED25519
|
||||||
.verify(
|
.verify(Input::from(public_key), Input::from(message), Input::from(signature))
|
||||||
Input::from(public_key),
|
|
||||||
Input::from(message),
|
|
||||||
Input::from(signature),
|
|
||||||
)
|
|
||||||
.map_err(|_| Error::new("signature verification failed"))
|
.map_err(|_| Error::new("signature verification failed"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user