Rename Signatures
SignatureMap
.
This commit is contained in:
parent
97ee073e11
commit
07295b11bb
47
src/lib.rs
47
src/lib.rs
@ -57,7 +57,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Verifying signatures of Matrix events is not yet implemented by ruma-signatures.
|
//! Verifying signatures of Matrix events is not yet implemented by ruma-signatures.
|
||||||
//!
|
//!
|
||||||
//! # Signature sets
|
//! # Signature sets and maps
|
||||||
//!
|
//!
|
||||||
//! Signatures that a homeserver has added to an event are stored in a JSON object under the
|
//! Signatures that a homeserver has added to an event are stored in a JSON object under the
|
||||||
//! "signatures" key in the event's JSON representation:
|
//! "signatures" key in the event's JSON representation:
|
||||||
@ -96,7 +96,7 @@
|
|||||||
//! This code produces the object under the "example.com" key in the preceeding JSON. Similarly,
|
//! This code produces the object under the "example.com" key in the preceeding JSON. Similarly,
|
||||||
//! a `SignatureSet` can be produced by deserializing JSON that follows this form.
|
//! a `SignatureSet` can be produced by deserializing JSON that follows this form.
|
||||||
//!
|
//!
|
||||||
//! The outer object (the map of server names to signature sets) is a `Signatures` value and
|
//! The outer object (the map of server names to signature sets) is a `SignatureMap` value and
|
||||||
//! created like this:
|
//! created like this:
|
||||||
//!
|
//!
|
||||||
//! ```rust,no_run
|
//! ```rust,no_run
|
||||||
@ -109,12 +109,13 @@
|
|||||||
//! );
|
//! );
|
||||||
//! let mut signature_set = ruma_signatures::SignatureSet::new();
|
//! let mut signature_set = ruma_signatures::SignatureSet::new();
|
||||||
//! signature_set.insert(signature);
|
//! signature_set.insert(signature);
|
||||||
//! let mut signatures = ruma_signatures::Signatures::new();
|
//! let mut signature_map = ruma_signatures::SignatureMap::new();
|
||||||
//! signatures.insert("example.com", signature_set).expect("example.com is a valid server name");
|
//! signature_map.insert("example.com", signature_set).expect("example.com is a valid server name");
|
||||||
//! serde_json::to_string(&signatures).expect("signatures should serialize");
|
//! serde_json::to_string(&signature_map).expect("signature_map should serialize");
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Just like the `SignatureSet` itself, the `Signatures` value can also be deserialized from JSON.
|
//! Just like the `SignatureSet` itself, the `SignatureMap` value can also be deserialized from
|
||||||
|
//! JSON.
|
||||||
|
|
||||||
#![deny(
|
#![deny(
|
||||||
missing_copy_implementations,
|
missing_copy_implementations,
|
||||||
@ -152,7 +153,7 @@ use serde_json::{to_string, Value};
|
|||||||
pub use url::Host;
|
pub use url::Host;
|
||||||
|
|
||||||
pub use keys::{Ed25519KeyPair, KeyPair};
|
pub use keys::{Ed25519KeyPair, KeyPair};
|
||||||
pub use signatures::{Signature, SignatureSet, Signatures};
|
pub use signatures::{Signature, SignatureMap, SignatureSet};
|
||||||
pub use verification::{Ed25519Verifier, Verifier};
|
pub use verification::{Ed25519Verifier, Verifier};
|
||||||
|
|
||||||
mod keys;
|
mod keys;
|
||||||
@ -288,8 +289,8 @@ mod test {
|
|||||||
use serde_json::{from_str, to_string, to_value};
|
use serde_json::{from_str, to_string, to_value};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
sign_json, verify_json, Ed25519KeyPair, Ed25519Verifier, KeyPair, Signature, SignatureSet,
|
sign_json, verify_json, Ed25519KeyPair, Ed25519Verifier, KeyPair, Signature, SignatureMap,
|
||||||
Signatures,
|
SignatureSet,
|
||||||
};
|
};
|
||||||
|
|
||||||
const PUBLIC_KEY: &str = "XGX0JRS2Af3be3knz2fBiRbApjm2Dh61gXDJA8kcJNI";
|
const PUBLIC_KEY: &str = "XGX0JRS2Af3be3knz2fBiRbApjm2Dh61gXDJA8kcJNI";
|
||||||
@ -346,10 +347,10 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn signatures_empty_json() {
|
fn signature_map_empty_json() {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct EmptyWithSignatures {
|
struct EmptyWithSignatureMap {
|
||||||
signatures: Signatures,
|
signatures: SignatureMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
let signature = Signature::new(
|
let signature = Signature::new(
|
||||||
@ -363,10 +364,12 @@ mod test {
|
|||||||
let mut signature_set = SignatureSet::with_capacity(1);
|
let mut signature_set = SignatureSet::with_capacity(1);
|
||||||
signature_set.insert(signature);
|
signature_set.insert(signature);
|
||||||
|
|
||||||
let mut signatures = Signatures::with_capacity(1);
|
let mut signature_map = SignatureMap::with_capacity(1);
|
||||||
signatures.insert("domain", signature_set).ok();
|
signature_map.insert("domain", signature_set).ok();
|
||||||
|
|
||||||
let empty = EmptyWithSignatures { signatures };
|
let empty = EmptyWithSignatureMap {
|
||||||
|
signatures: signature_map,
|
||||||
|
};
|
||||||
|
|
||||||
let json = to_string(&empty).unwrap();
|
let json = to_string(&empty).unwrap();
|
||||||
|
|
||||||
@ -464,11 +467,11 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn signatures_minimal_json() {
|
fn signature_map_minimal_json() {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct MinimalWithSignatures {
|
struct MinimalWithSignatureMap {
|
||||||
one: u8,
|
one: u8,
|
||||||
signatures: Signatures,
|
signatures: SignatureMap,
|
||||||
two: String,
|
two: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,12 +486,12 @@ mod test {
|
|||||||
let mut signature_set = SignatureSet::with_capacity(1);
|
let mut signature_set = SignatureSet::with_capacity(1);
|
||||||
signature_set.insert(signature);
|
signature_set.insert(signature);
|
||||||
|
|
||||||
let mut signatures = Signatures::with_capacity(1);
|
let mut signature_map = SignatureMap::with_capacity(1);
|
||||||
signatures.insert("domain", signature_set).ok();
|
signature_map.insert("domain", signature_set).ok();
|
||||||
|
|
||||||
let minimal = MinimalWithSignatures {
|
let minimal = MinimalWithSignatureMap {
|
||||||
one: 1,
|
one: 1,
|
||||||
signatures: signatures.clone(),
|
signatures: signature_map.clone(),
|
||||||
two: "Two".to_string(),
|
two: "Two".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,20 +89,20 @@ impl Signature {
|
|||||||
|
|
||||||
/// A map of server names to sets of digital signatures created by that server.
|
/// A map of server names to sets of digital signatures created by that server.
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
pub struct Signatures {
|
pub struct SignatureMap {
|
||||||
/// A map of homeservers to sets of signatures for the homeserver.
|
/// A map of homeservers to sets of signatures for the homeserver.
|
||||||
map: HashMap<Host, SignatureSet>,
|
map: HashMap<Host, SignatureSet>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Signatures {
|
impl SignatureMap {
|
||||||
/// Initializes a new empty Signatures.
|
/// Initializes a new empty `SignatureMap`.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
map: HashMap::new(),
|
map: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initializes a new empty Signatures with room for a specific number of servers.
|
/// Initializes a new empty `SignatureMap` with room for a specific number of servers.
|
||||||
///
|
///
|
||||||
/// # Parameters
|
/// # Parameters
|
||||||
///
|
///
|
||||||
@ -154,7 +154,7 @@ impl Signatures {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for Signatures {
|
impl Serialize for SignatureMap {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
@ -170,20 +170,20 @@ impl Serialize for Signatures {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Signatures {
|
impl<'de> Deserialize<'de> for SignatureMap {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
deserializer.deserialize_map(SignaturesVisitor)
|
deserializer.deserialize_map(SignatureMapVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serde Visitor for deserializing `Signatures`.
|
/// Serde Visitor for deserializing `SignatureMap`.
|
||||||
struct SignaturesVisitor;
|
struct SignatureMapVisitor;
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for SignaturesVisitor {
|
impl<'de> Visitor<'de> for SignatureMapVisitor {
|
||||||
type Value = Signatures;
|
type Value = SignatureMap;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
|
fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
|
||||||
write!(formatter, "digital signatures")
|
write!(formatter, "digital signatures")
|
||||||
@ -194,8 +194,8 @@ impl<'de> Visitor<'de> for SignaturesVisitor {
|
|||||||
M: MapAccess<'de>,
|
M: MapAccess<'de>,
|
||||||
{
|
{
|
||||||
let mut signatures = match visitor.size_hint() {
|
let mut signatures = match visitor.size_hint() {
|
||||||
Some(capacity) => Signatures::with_capacity(capacity),
|
Some(capacity) => SignatureMap::with_capacity(capacity),
|
||||||
None => Signatures::new(),
|
None => SignatureMap::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
while let Some((server_name, signature_set)) =
|
while let Some((server_name, signature_set)) =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user