@@ -19,6 +19,7 @@ use alloc::borrow::ToOwned;
1919use alloc:: boxed:: Box ;
2020use alloc:: string:: String ;
2121use alloc:: vec:: Vec ;
22+ use async_signature:: { AsyncRandomizedSigner , AsyncSigner } ;
2223use cipher:: {
2324 block_padding:: Pkcs7 ,
2425 rand_core:: { self , CryptoRng , CryptoRngCore , RngCore } ,
@@ -43,7 +44,7 @@ use spki::{
4344use std:: time:: SystemTime ;
4445use std:: vec;
4546use x509_cert:: attr:: { Attribute , AttributeValue , Attributes } ;
46- use x509_cert:: builder:: { self , Builder } ;
47+ use x509_cert:: builder:: { self , AsyncBuilder , Builder } ;
4748use zeroize:: Zeroize ;
4849
4950/// Error type
@@ -426,6 +427,51 @@ impl<'s> SignedDataBuilder<'s> {
426427 Ok ( self )
427428 }
428429
430+ /// Add a signer info. The signature will be calculated. Note that the encapsulated content
431+ /// must not be changed after the first signer info was added.
432+ pub async fn add_signer_info_async < S , Signature > (
433+ & mut self ,
434+ signer_info_builder : SignerInfoBuilder < ' _ > ,
435+ signer : & S ,
436+ ) -> Result < & mut Self >
437+ where
438+ S : Keypair + DynSignatureAlgorithmIdentifier ,
439+ S : AsyncSigner < Signature > ,
440+ S :: VerifyingKey : EncodePublicKey ,
441+ Signature : SignatureBitStringEncoding + ' static ,
442+ {
443+ let signer_info = signer_info_builder
444+ . build_async :: < S , Signature > ( signer)
445+ . await
446+ . map_err ( |_| der:: Error :: from ( ErrorKind :: Failed ) ) ?;
447+ self . signer_infos . push ( signer_info) ;
448+
449+ Ok ( self )
450+ }
451+
452+ /// Add a signer info. The signature will be calculated. Note that the encapsulated content
453+ /// must not be changed after the first signer info was added.
454+ pub async fn add_signer_info_with_rng_async < S , Signature > (
455+ & mut self ,
456+ signer_info_builder : SignerInfoBuilder < ' _ > ,
457+ signer : & S ,
458+ rng : & mut impl CryptoRngCore ,
459+ ) -> Result < & mut Self >
460+ where
461+ S : Keypair + DynSignatureAlgorithmIdentifier ,
462+ S : AsyncRandomizedSigner < Signature > ,
463+ S :: VerifyingKey : EncodePublicKey ,
464+ Signature : SignatureBitStringEncoding + ' static ,
465+ {
466+ let signer_info = signer_info_builder
467+ . build_with_rng_async :: < S , Signature > ( signer, rng)
468+ . await
469+ . map_err ( |_| der:: Error :: from ( ErrorKind :: Failed ) ) ?;
470+ self . signer_infos . push ( signer_info) ;
471+
472+ Ok ( self )
473+ }
474+
429475 /// This method returns a `ContentInfo` of type `signedData`.
430476 pub fn build ( & mut self ) -> Result < ContentInfo > {
431477 let digest_algorithms =
0 commit comments