@@ -25,6 +25,7 @@ use cipher::{
25
25
use const_oid:: ObjectIdentifier ;
26
26
use core:: cmp:: Ordering ;
27
27
use core:: fmt;
28
+ use core:: future:: ready;
28
29
use core:: marker:: PhantomData ;
29
30
use der:: asn1:: { BitString , Null , OctetString , OctetStringRef , SetOfVec } ;
30
31
use der:: oid:: db:: DB ;
@@ -410,9 +411,30 @@ impl<'s> SignedDataBuilder<'s> {
410
411
S :: VerifyingKey : EncodePublicKey ,
411
412
Signature : SignatureBitStringEncoding ,
412
413
{
413
- let signer_info = signer_info_builder
414
+ self . add_signer_info_cb :: < S , Signature , _ > ( signer_info_builder, signer, |_| Ok ( ( ) ) )
415
+ }
416
+
417
+ /// Add a signer info. The signature will be calculated. Note that the encapsulated content
418
+ /// must not be changed after the first signer info was added.
419
+ pub fn add_signer_info_cb < S , Signature , CB > (
420
+ & mut self ,
421
+ signer_info_builder : SignerInfoBuilder < ' _ > ,
422
+ signer : & S ,
423
+ callback : CB ,
424
+ ) -> Result < & mut Self >
425
+ where
426
+ S : Keypair + DynSignatureAlgorithmIdentifier ,
427
+ S : Signer < Signature > ,
428
+ S :: VerifyingKey : EncodePublicKey ,
429
+ Signature : SignatureBitStringEncoding ,
430
+ CB : FnOnce ( & mut SignerInfo ) -> Result < ( ) > ,
431
+ {
432
+ let mut signer_info = signer_info_builder
414
433
. build :: < S , Signature > ( signer)
415
434
. map_err ( |_| der:: Error :: from ( ErrorKind :: Failed ) ) ?;
435
+
436
+ callback ( & mut signer_info) ?;
437
+
416
438
self . signer_infos . push ( signer_info) ;
417
439
418
440
Ok ( self )
@@ -433,9 +455,37 @@ impl<'s> SignedDataBuilder<'s> {
433
455
Signature : SignatureBitStringEncoding ,
434
456
R : CryptoRng + ?Sized ,
435
457
{
436
- let signer_info = signer_info_builder
458
+ self . add_signer_info_with_rng_cb :: < S , Signature , _ , R > (
459
+ signer_info_builder,
460
+ signer,
461
+ |_| Ok ( ( ) ) ,
462
+ rng,
463
+ )
464
+ }
465
+
466
+ /// Add a signer info. The signature will be calculated. Note that the encapsulated content
467
+ /// must not be changed after the first signer info was added.
468
+ pub fn add_signer_info_with_rng_cb < S , Signature , CB , R > (
469
+ & mut self ,
470
+ signer_info_builder : SignerInfoBuilder < ' _ > ,
471
+ signer : & S ,
472
+ callback : CB ,
473
+ rng : & mut R ,
474
+ ) -> Result < & mut Self >
475
+ where
476
+ S : Keypair + DynSignatureAlgorithmIdentifier ,
477
+ S : RandomizedSigner < Signature > ,
478
+ S :: VerifyingKey : EncodePublicKey ,
479
+ Signature : SignatureBitStringEncoding ,
480
+ CB : FnOnce ( & mut SignerInfo ) -> Result < ( ) > ,
481
+ R : CryptoRng + ?Sized ,
482
+ {
483
+ let mut signer_info = signer_info_builder
437
484
. build_with_rng :: < S , Signature , R > ( signer, rng)
438
485
. map_err ( |_| der:: Error :: from ( ErrorKind :: Failed ) ) ?;
486
+
487
+ callback ( & mut signer_info) ?;
488
+
439
489
self . signer_infos . push ( signer_info) ;
440
490
441
491
Ok ( self )
@@ -454,10 +504,33 @@ impl<'s> SignedDataBuilder<'s> {
454
504
S :: VerifyingKey : EncodePublicKey ,
455
505
Signature : SignatureBitStringEncoding ,
456
506
{
457
- let signer_info = signer_info_builder
507
+ self . add_signer_info_cb_async ( signer_info_builder, signer, |_| ready ( Ok ( ( ) ) ) )
508
+ . await
509
+ }
510
+
511
+ /// Add a signer info. The signature will be calculated. Note that the encapsulated content
512
+ /// must not be changed after the first signer info was added.
513
+ pub async fn add_signer_info_cb_async < S , Signature , F , CB > (
514
+ & mut self ,
515
+ signer_info_builder : SignerInfoBuilder < ' _ > ,
516
+ signer : & S ,
517
+ callback : CB ,
518
+ ) -> Result < & mut Self >
519
+ where
520
+ S : Keypair + DynSignatureAlgorithmIdentifier ,
521
+ S : AsyncSigner < Signature > ,
522
+ S :: VerifyingKey : EncodePublicKey ,
523
+ Signature : SignatureBitStringEncoding ,
524
+ F : Future < Output = Result < ( ) > > ,
525
+ CB : FnOnce ( & mut SignerInfo ) -> F ,
526
+ {
527
+ let mut signer_info = signer_info_builder
458
528
. build_async :: < S , Signature > ( signer)
459
529
. await
460
530
. map_err ( |_| der:: Error :: from ( ErrorKind :: Failed ) ) ?;
531
+
532
+ callback ( & mut signer_info) . await ?;
533
+
461
534
self . signer_infos . push ( signer_info) ;
462
535
463
536
Ok ( self )
@@ -478,10 +551,35 @@ impl<'s> SignedDataBuilder<'s> {
478
551
Signature : SignatureBitStringEncoding ,
479
552
R : CryptoRng + ?Sized ,
480
553
{
481
- let signer_info = signer_info_builder
554
+ self . add_signer_info_with_rng_cb_async ( signer_info_builder, signer, rng, |_| ready ( Ok ( ( ) ) ) )
555
+ . await
556
+ }
557
+
558
+ /// Add a signer info. The signature will be calculated. Note that the encapsulated content
559
+ /// must not be changed after the first signer info was added.
560
+ pub async fn add_signer_info_with_rng_cb_async < S , Signature , R , F , CB > (
561
+ & mut self ,
562
+ signer_info_builder : SignerInfoBuilder < ' _ > ,
563
+ signer : & S ,
564
+ rng : & mut R ,
565
+ callback : CB ,
566
+ ) -> Result < & mut Self >
567
+ where
568
+ S : Keypair + DynSignatureAlgorithmIdentifier ,
569
+ S : AsyncRandomizedSigner < Signature > ,
570
+ S :: VerifyingKey : EncodePublicKey ,
571
+ Signature : SignatureBitStringEncoding ,
572
+ R : CryptoRng + ?Sized ,
573
+ F : Future < Output = Result < ( ) > > ,
574
+ CB : FnOnce ( & mut SignerInfo ) -> F ,
575
+ {
576
+ let mut signer_info = signer_info_builder
482
577
. build_with_rng_async :: < S , Signature , R > ( signer, rng)
483
578
. await
484
579
. map_err ( |_| der:: Error :: from ( ErrorKind :: Failed ) ) ?;
580
+
581
+ callback ( & mut signer_info) . await ?;
582
+
485
583
self . signer_infos . push ( signer_info) ;
486
584
487
585
Ok ( self )
0 commit comments