@@ -5,14 +5,14 @@ mod content;
55pub mod doc_types;
66pub mod error;
77mod metadata;
8+ pub mod providers;
89mod signature;
910mod utils;
1011pub mod validator;
1112
1213use std:: {
1314 convert:: TryFrom ,
1415 fmt:: { Display , Formatter } ,
15- future:: Future ,
1616 sync:: Arc ,
1717} ;
1818
@@ -21,11 +21,11 @@ use catalyst_types::problem_report::ProblemReport;
2121pub use catalyst_types:: uuid:: { Uuid , UuidV4 , UuidV7 } ;
2222pub use content:: Content ;
2323use coset:: { CborSerializable , Header } ;
24- use ed25519_dalek:: VerifyingKey ;
2524use error:: CatalystSignedDocError ;
2625use metadata:: { ContentEncoding , ContentType } ;
2726pub use metadata:: { DocumentRef , ExtraFields , Metadata } ;
2827use minicbor:: { decode, encode, Decode , Decoder , Encode } ;
28+ use providers:: VerifyingKeyProvider ;
2929pub use signature:: { IdUri , Signatures } ;
3030use utils:: context:: DecodeSignDocCtx ;
3131
@@ -144,11 +144,9 @@ impl CatalystSignedDocument {
144144 /// Returns a report of verification failures and the source error.
145145 /// If `provider` returns error, fails fast and placed this error into
146146 /// `CatalystSignedDocError::error`.
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- {
147+ pub async fn verify (
148+ & self , provider : & impl VerifyingKeyProvider ,
149+ ) -> Result < ( ) , CatalystSignedDocError > {
152150 let report = ProblemReport :: new ( "Catalyst Signed Document Verification" ) ;
153151
154152 let cose_sign = match self . as_cose_sign ( ) {
@@ -163,7 +161,7 @@ impl CatalystSignedDocument {
163161 } ;
164162
165163 for ( signature, kid) in self . signatures ( ) . cose_signatures_with_kids ( ) {
166- match provider ( kid) . await {
164+ match provider. try_get_vk ( kid) . await {
167165 Ok ( Some ( pk) ) => {
168166 let tbs_data = cose_sign. tbs_data ( & [ ] , signature) ;
169167 match signature. signature . as_slice ( ) . try_into ( ) {
@@ -358,7 +356,7 @@ impl Encode<()> for CatalystSignedDocument {
358356mod tests {
359357 use std:: str:: FromStr ;
360358
361- use ed25519_dalek:: SigningKey ;
359+ use ed25519_dalek:: { SigningKey , VerifyingKey } ;
362360 use metadata:: { ContentEncoding , ContentType } ;
363361 use rand:: rngs:: OsRng ;
364362
@@ -413,6 +411,16 @@ mod tests {
413411 assert_eq ! ( decoded. doc_meta( ) , metadata. extra( ) ) ;
414412 }
415413
414+ struct Provider ( anyhow:: Result < Option < VerifyingKey > > ) ;
415+ impl VerifyingKeyProvider for Provider {
416+ async fn try_get_vk (
417+ & self , _kid : & IdUri ,
418+ ) -> anyhow:: Result < Option < ed25519_dalek:: VerifyingKey > > {
419+ let res = self . 0 . as_ref ( ) . map_err ( |e| anyhow:: anyhow!( "{e}" ) ) ?;
420+ Ok ( * res)
421+ }
422+ }
423+
416424 #[ tokio:: test]
417425 async fn signature_verification_test ( ) {
418426 let mut csprng = OsRng ;
@@ -435,10 +443,10 @@ mod tests {
435443 . build ( )
436444 . unwrap ( ) ;
437445
438- assert ! ( signed_doc. verify( |_| async { Ok ( Some ( pk) ) } ) . await . is_ok( ) ) ;
439- assert ! ( signed_doc. verify( |_| async { Ok ( None ) } ) . await . is_err( ) ) ;
446+ assert ! ( signed_doc. verify( & Provider ( Ok ( Some ( pk) ) ) ) . await . is_ok( ) ) ;
447+ assert ! ( signed_doc. verify( & Provider ( Ok ( None ) ) ) . await . is_err( ) ) ;
440448 assert ! ( signed_doc
441- . verify( |_| async { Err ( anyhow:: anyhow!( "some error" ) ) } )
449+ . verify( & Provider ( Err ( anyhow:: anyhow!( "some error" ) ) ) )
442450 . await
443451 . is_err( ) ) ;
444452 }
0 commit comments