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