1
- use cryptoki:: {
2
- object:: { Attribute , AttributeType , KeyType , ObjectClass , ObjectHandle } ,
3
- session:: Session ,
4
- } ;
1
+ use cryptoki:: object:: { Attribute , AttributeType , KeyType , ObjectClass , ObjectHandle } ;
5
2
use der:: { asn1:: ObjectIdentifier , oid:: AssociatedOid , Any , AnyRef } ;
6
3
use rsa:: {
7
4
pkcs1:: { self , RsaPssParams } ,
@@ -17,17 +14,18 @@ use spki::{
17
14
use std:: convert:: TryFrom ;
18
15
19
16
use super :: { DigestSigning , Error } ;
17
+ use crate :: SessionLike ;
20
18
21
- pub struct Signer < D : DigestSigning > {
22
- session : Session ,
19
+ pub struct Signer < D : DigestSigning , S : SessionLike > {
20
+ session : S ,
23
21
_public_key : ObjectHandle ,
24
22
private_key : ObjectHandle ,
25
23
verifying_key : VerifyingKey < D > ,
26
24
salt_len : usize ,
27
25
}
28
26
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 > {
31
29
// First we'll lookup a private key with that label.
32
30
let template = vec ! [
33
31
Attribute :: Token ( true ) ,
@@ -88,25 +86,25 @@ impl<D: DigestSigning> Signer<D> {
88
86
} )
89
87
}
90
88
91
- pub fn into_session ( self ) -> Session {
89
+ pub fn into_session ( self ) -> S {
92
90
self . session
93
91
}
94
92
}
95
93
96
- impl < D : DigestSigning > AssociatedAlgorithmIdentifier for Signer < D > {
94
+ impl < D : DigestSigning , S : SessionLike > AssociatedAlgorithmIdentifier for Signer < D , S > {
97
95
type Params = AnyRef < ' static > ;
98
96
const ALGORITHM_IDENTIFIER : AlgorithmIdentifierRef < ' static > = pkcs1:: ALGORITHM_ID ;
99
97
}
100
98
101
- impl < D : DigestSigning > signature:: Keypair for Signer < D > {
99
+ impl < D : DigestSigning , S : SessionLike > signature:: Keypair for Signer < D , S > {
102
100
type VerifyingKey = VerifyingKey < D > ;
103
101
104
102
fn verifying_key ( & self ) -> Self :: VerifyingKey {
105
103
self . verifying_key . clone ( )
106
104
}
107
105
}
108
106
109
- impl < D : DigestSigning > signature:: Signer < Signature > for Signer < D > {
107
+ impl < D : DigestSigning , S : SessionLike > signature:: Signer < Signature > for Signer < D , S > {
110
108
fn try_sign ( & self , msg : & [ u8 ] ) -> Result < Signature , signature:: Error > {
111
109
let bytes = self
112
110
. session
@@ -121,7 +119,7 @@ impl<D: DigestSigning> signature::Signer<Signature> for Signer<D> {
121
119
}
122
120
}
123
121
124
- impl < D : DigestSigning > DynSignatureAlgorithmIdentifier for Signer < D > {
122
+ impl < D : DigestSigning , S : SessionLike > DynSignatureAlgorithmIdentifier for Signer < D , S > {
125
123
fn signature_algorithm_identifier ( & self ) -> pkcs8:: spki:: Result < AlgorithmIdentifierOwned > {
126
124
get_pss_signature_algo_id :: < D > ( self . salt_len as u8 )
127
125
}
0 commit comments