radicle: ensure unique signatures when parsing trailers
To ensure that signatures are unique for verifying an identity a HashMap is used in place of a Vec of tuples. This prevents any double counting for quorum checks. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
adaed6a3ac
commit
d7170ff9e7
|
|
@ -121,7 +121,7 @@ impl Identity<Untrusted> {
|
||||||
let quorum = untrusted
|
let quorum = untrusted
|
||||||
.sigs
|
.sigs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(key, _)| trusted.delegates.iter().any(|d| &**d == key))
|
.filter(|(key, _)| trusted.delegates.iter().any(|d| **d == **key))
|
||||||
.count();
|
.count();
|
||||||
if quorum < trusted.threshold {
|
if quorum < trusted.threshold {
|
||||||
return Err(IdentityError::ThresholdNotReached(
|
return Err(IdentityError::ThresholdNotReached(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
mod id;
|
mod id;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
@ -122,7 +122,7 @@ pub struct DocAt {
|
||||||
/// The parsed document.
|
/// The parsed document.
|
||||||
pub doc: Doc<Verified>,
|
pub doc: Doc<Verified>,
|
||||||
/// The validated commit signatures.
|
/// The validated commit signatures.
|
||||||
pub sigs: Vec<(PublicKey, Signature)>,
|
pub sigs: HashMap<PublicKey, Signature>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An identity document.
|
/// An identity document.
|
||||||
|
|
|
||||||
|
|
@ -840,10 +840,10 @@ pub mod trailers {
|
||||||
Signature(#[from] SignatureError),
|
Signature(#[from] SignatureError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_signatures(msg: &str) -> Result<Vec<(PublicKey, Signature)>, Error> {
|
pub fn parse_signatures(msg: &str) -> Result<HashMap<PublicKey, Signature>, Error> {
|
||||||
let trailers =
|
let trailers =
|
||||||
git2::message_trailers_strs(msg).map_err(|_| Error::SignatureTrailerFormat)?;
|
git2::message_trailers_strs(msg).map_err(|_| Error::SignatureTrailerFormat)?;
|
||||||
let mut signatures = Vec::with_capacity(trailers.len());
|
let mut signatures = HashMap::with_capacity(trailers.len());
|
||||||
|
|
||||||
for (key, val) in trailers.iter() {
|
for (key, val) in trailers.iter() {
|
||||||
if key == SIGNATURE_TRAILER {
|
if key == SIGNATURE_TRAILER {
|
||||||
|
|
@ -851,7 +851,7 @@ pub mod trailers {
|
||||||
let pk = PublicKey::from_str(pk)?;
|
let pk = PublicKey::from_str(pk)?;
|
||||||
let sig = Signature::from_str(sig)?;
|
let sig = Signature::from_str(sig)?;
|
||||||
|
|
||||||
signatures.push((pk, sig));
|
signatures.insert(pk, sig);
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::SignatureTrailerFormat);
|
return Err(Error::SignatureTrailerFormat);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue