1- use cryptoki:: {
2- object:: { Attribute , AttributeType , KeyType , ObjectClass , ObjectHandle } ,
3- session:: Session ,
4- } ;
1+ use cryptoki:: object:: { Attribute , AttributeType , KeyType , ObjectClass , ObjectHandle } ;
52use der:: { asn1:: ObjectIdentifier , oid:: AssociatedOid , Any , AnyRef } ;
63use rsa:: {
74 pkcs1:: { self , RsaPssParams } ,
@@ -17,17 +14,18 @@ use spki::{
1714use std:: convert:: TryFrom ;
1815
1916use super :: { DigestSigning , Error } ;
17+ use crate :: SessionLike ;
2018
21- pub struct Signer < D : DigestSigning > {
22- session : Session ,
19+ pub struct Signer < D : DigestSigning , S : SessionLike > {
20+ session : S ,
2321 _public_key : ObjectHandle ,
2422 private_key : ObjectHandle ,
2523 verifying_key : VerifyingKey < D > ,
2624 salt_len : usize ,
2725}
2826
29- impl < D : DigestSigning > Signer < D > {
30- pub fn new ( session : Session , label : & [ u8 ] ) -> Result < Self , Error > {
27+ impl < D : DigestSigning , S : SessionLike > Signer < D , S > {
28+ pub fn new ( session : S , label : & [ u8 ] ) -> Result < Self , Error > {
3129 // First we'll lookup a private key with that label.
3230 let template = vec ! [
3331 Attribute :: Token ( true ) ,
@@ -88,25 +86,25 @@ impl<D: DigestSigning> Signer<D> {
8886 } )
8987 }
9088
91- pub fn into_session ( self ) -> Session {
89+ pub fn into_session ( self ) -> S {
9290 self . session
9391 }
9492}
9593
96- impl < D : DigestSigning > AssociatedAlgorithmIdentifier for Signer < D > {
94+ impl < D : DigestSigning , S : SessionLike > AssociatedAlgorithmIdentifier for Signer < D , S > {
9795 type Params = AnyRef < ' static > ;
9896 const ALGORITHM_IDENTIFIER : AlgorithmIdentifierRef < ' static > = pkcs1:: ALGORITHM_ID ;
9997}
10098
101- impl < D : DigestSigning > signature:: Keypair for Signer < D > {
99+ impl < D : DigestSigning , S : SessionLike > signature:: Keypair for Signer < D , S > {
102100 type VerifyingKey = VerifyingKey < D > ;
103101
104102 fn verifying_key ( & self ) -> Self :: VerifyingKey {
105103 self . verifying_key . clone ( )
106104 }
107105}
108106
109- impl < D : DigestSigning > signature:: Signer < Signature > for Signer < D > {
107+ impl < D : DigestSigning , S : SessionLike > signature:: Signer < Signature > for Signer < D , S > {
110108 fn try_sign ( & self , msg : & [ u8 ] ) -> Result < Signature , signature:: Error > {
111109 let bytes = self
112110 . session
@@ -121,7 +119,7 @@ impl<D: DigestSigning> signature::Signer<Signature> for Signer<D> {
121119 }
122120}
123121
124- impl < D : DigestSigning > DynSignatureAlgorithmIdentifier for Signer < D > {
122+ impl < D : DigestSigning , S : SessionLike > DynSignatureAlgorithmIdentifier for Signer < D , S > {
125123 fn signature_algorithm_identifier ( & self ) -> pkcs8:: spki:: Result < AlgorithmIdentifierOwned > {
126124 get_pss_signature_algo_id :: < D > ( self . salt_len as u8 )
127125 }
0 commit comments