Skip to content

Commit 40478ae

Browse files
committed
make signed doc signature validation async
1 parent cd4301c commit 40478ae

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

rust/signed_doc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jsonpath-rust = "0.7.5"
2929
[dev-dependencies]
3030
base64-url = "3.0.0"
3131
rand = "0.8.5"
32-
32+
tokio = { version = "1.42.0", features = [ "macros" ] }
3333

3434
[[bin]]
3535
name = "signed-docs"

rust/signed_doc/src/lib.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod validator;
1212
use std::{
1313
convert::TryFrom,
1414
fmt::{Display, Formatter},
15+
future::Future,
1516
sync::Arc,
1617
};
1718

@@ -143,8 +144,11 @@ impl CatalystSignedDocument {
143144
/// Returns a report of verification failures and the source error.
144145
/// If `provider` returns error, fails fast and placed this error into
145146
/// `CatalystSignedDocError::error`.
146-
pub fn verify<P>(&self, provider: P) -> Result<(), CatalystSignedDocError>
147-
where P: Fn(&IdUri) -> anyhow::Result<Option<VerifyingKey>> {
147+
pub async fn verify<P, PF>(&self, provider: P) -> Result<(), CatalystSignedDocError>
148+
where
149+
P: Fn(&IdUri) -> PF,
150+
PF: Future<Output = anyhow::Result<Option<VerifyingKey>>>,
151+
{
148152
let report = ProblemReport::new("Catalyst Signed Document Verification");
149153

150154
let cose_sign = match self.as_cose_sign() {
@@ -159,7 +163,7 @@ impl CatalystSignedDocument {
159163
};
160164

161165
for (signature, kid) in self.signatures().cose_signatures_with_kids() {
162-
match provider(kid) {
166+
match provider(kid).await {
163167
Ok(Some(pk)) => {
164168
let tbs_data = cose_sign.tbs_data(&[], signature);
165169
match signature.signature.as_slice().try_into() {
@@ -409,8 +413,8 @@ mod tests {
409413
assert_eq!(decoded.doc_meta(), metadata.extra());
410414
}
411415

412-
#[test]
413-
fn signature_verification_test() {
416+
#[tokio::test]
417+
async fn signature_verification_test() {
414418
let mut csprng = OsRng;
415419
let sk: SigningKey = SigningKey::generate(&mut csprng);
416420
let content = serde_json::to_vec(&serde_json::Value::Null).unwrap();
@@ -431,10 +435,11 @@ mod tests {
431435
.build()
432436
.unwrap();
433437

434-
assert!(signed_doc.verify(|_| Ok(Some(pk))).is_ok());
435-
assert!(signed_doc.verify(|_| Ok(None)).is_err());
438+
assert!(signed_doc.verify(|_| async { Ok(Some(pk)) }).await.is_ok());
439+
assert!(signed_doc.verify(|_| async { Ok(None) }).await.is_err());
436440
assert!(signed_doc
437-
.verify(|_| Err(anyhow::anyhow!("some error")))
441+
.verify(|_| async { Err(anyhow::anyhow!("some error")) })
442+
.await
438443
.is_err());
439444
}
440445
}

0 commit comments

Comments
 (0)