-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rust/signed_doc): decode and validate signatures
* WIP: implement temporary Error type that will be replaced with a ProblemReport
- Loading branch information
1 parent
5c74471
commit 2b9282f
Showing
7 changed files
with
129 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! Catalyst Signed Document errors. | ||
/// Catalyst Signed Document error. | ||
#[derive(thiserror::Error, Debug)] | ||
#[error("Catalyst Signed Document Error: {0:#?}")] | ||
pub struct Error(pub(crate) Vec<anyhow::Error>); | ||
|
||
impl From<Vec<anyhow::Error>> for Error { | ||
fn from(e: Vec<anyhow::Error>) -> Self { | ||
Error(e) | ||
} | ||
} | ||
|
||
impl Error { | ||
/// List of errors. | ||
pub fn errors(&self) -> &Vec<anyhow::Error> { | ||
&self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,57 @@ | ||
//! Catalyst Signed Document COSE Signature information. | ||
pub use catalyst_types::kid_uri::KidUri; | ||
use coset::CoseSignature; | ||
|
||
/// Catalyst Signed Document COSE Signature. | ||
#[derive(Debug)] | ||
pub struct Signature { | ||
/// Key ID | ||
kid: KidUri, | ||
/// COSE Signature | ||
signature: CoseSignature, | ||
} | ||
|
||
/// List of Signatures. | ||
#[derive(Default)] | ||
pub struct Signatures(Vec<Signature>); | ||
|
||
impl Signatures { | ||
/// List of signature Key IDs. | ||
pub fn kids(&self) -> Vec<KidUri> { | ||
self.0.iter().map(|sig| sig.kid.clone()).collect() | ||
} | ||
|
||
/// List of signatures. | ||
pub fn signatures(&self) -> Vec<CoseSignature> { | ||
self.0.iter().map(|sig| sig.signature.clone()).collect() | ||
} | ||
} | ||
|
||
impl TryFrom<&Vec<CoseSignature>> for Signatures { | ||
type Error = crate::error::Error; | ||
|
||
fn try_from(value: &Vec<CoseSignature>) -> Result<Self, Self::Error> { | ||
let mut signatures = Vec::new(); | ||
let mut errors = Vec::new(); | ||
value | ||
.iter() | ||
.cloned() | ||
.enumerate() | ||
.for_each(|(idx, signature)| { | ||
match KidUri::try_from(signature.protected.header.key_id.as_ref()) { | ||
Ok(kid) => signatures.push(Signature { kid, signature }), | ||
Err(e) => { | ||
errors.push(anyhow::anyhow!( | ||
"Signature at index {idx} has valid Catalyst Key Id: {e}" | ||
)); | ||
}, | ||
} | ||
}); | ||
if errors.is_empty() { | ||
Err(errors.into()) | ||
} else { | ||
Ok(Signatures(signatures)) | ||
} | ||
} | ||
} |