Skip to content

Commit 6630c02

Browse files
committed
wip
1 parent f9ec1fc commit 6630c02

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

rust/signed_doc/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ jsonpath-rust = "0.7.5"
2929
[dev-dependencies]
3030
base64-url = "3.0.0"
3131
rand = "0.8.5"
32-
tokio = "1.42.0"
3332

3433

3534
[[bin]]

rust/signed_doc/src/lib.rs

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

@@ -142,11 +141,8 @@ impl CatalystSignedDocument {
142141
/// # Errors
143142
///
144143
/// Returns a report of verification failures and the source error.
145-
pub async fn verify<P, T>(&self, pk_getter: P) -> Result<(), CatalystSignedDocError>
146-
where
147-
P: Fn(&IdUri) -> T,
148-
T: Future<Output = Option<VerifyingKey>>,
149-
{
144+
pub fn verify<P>(&self, pk_getter: P) -> Result<(), CatalystSignedDocError>
145+
where P: Fn(&IdUri) -> Option<VerifyingKey> {
150146
let report = ProblemReport::new("Catalyst Signed Document Verification");
151147

152148
let cose_sign = match self.as_cose_sign() {
@@ -161,7 +157,7 @@ impl CatalystSignedDocument {
161157
};
162158

163159
for (signature, kid) in self.signatures().cose_signatures_with_kids() {
164-
match pk_getter(kid).await {
160+
match pk_getter(kid) {
165161
Some(pk) => {
166162
let tbs_data = cose_sign.tbs_data(&[], signature);
167163
match signature.signature.as_slice().try_into() {
@@ -408,8 +404,8 @@ mod tests {
408404
assert_eq!(decoded.doc_meta(), metadata.extra());
409405
}
410406

411-
#[tokio::test]
412-
async fn signature_verification_test() {
407+
#[test]
408+
fn signature_verification_test() {
413409
let mut csprng = OsRng;
414410
let sk: SigningKey = SigningKey::generate(&mut csprng);
415411
let content = serde_json::to_vec(&serde_json::Value::Null).unwrap();
@@ -430,8 +426,8 @@ mod tests {
430426
.build()
431427
.unwrap();
432428

433-
assert!(signed_doc.verify(|_| async { Some(pk) }).await.is_ok());
429+
assert!(signed_doc.verify(|_| Some(pk)).is_ok());
434430

435-
assert!(signed_doc.verify(|_| async { None }).await.is_err());
431+
assert!(signed_doc.verify(|_| None).is_err());
436432
}
437433
}

rust/signed_doc/src/validator/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ pub(crate) type StatelessRule = fn(&CatalystSignedDocument, &ProblemReport) -> b
1616
pub(crate) type StatefullRule<DocType, DocProvider> =
1717
fn(&DocType, &DocProvider, &ProblemReport) -> bool;
1818

19+
/// Trait for defining a stateless validation rules.
20+
pub trait StatelessValidation
21+
where Self: 'static
22+
{
23+
/// Stateless validation rules
24+
const STATELESS_RULES: &[StatelessRule];
25+
26+
/// Perform a stateless validation, collecting a problem report
27+
fn validate(doc: &CatalystSignedDocument, report: &ProblemReport) -> bool {
28+
Self::STATELESS_RULES
29+
.iter()
30+
.map(|rule| rule(doc, report))
31+
.all(|res| res)
32+
}
33+
}
34+
1935
/// Trait for defining a statefull validation rules.
2036
pub trait StatefullValidation<DocProvider>
2137
where
@@ -34,22 +50,6 @@ where
3450
}
3551
}
3652

37-
/// Trait for defining a stateless validation rules.
38-
pub trait StatelessValidation
39-
where Self: 'static
40-
{
41-
/// Stateless validation rules
42-
const STATELESS_RULES: &[StatelessRule];
43-
44-
/// Perform a stateless validation, collecting a problem report
45-
fn validate(doc: &CatalystSignedDocument, report: &ProblemReport) -> bool {
46-
Self::STATELESS_RULES
47-
.iter()
48-
.map(|rule| rule(doc, report))
49-
.all(|res| res)
50-
}
51-
}
52-
5353
/// A comprehensive validation of the `CatalystSignedDocument`,
5454
/// including a signature verification and document type based validation.
5555
///

0 commit comments

Comments
 (0)