11// Copyright 2023 Contributors to the Parsec project.
22// SPDX-License-Identifier: Apache-2.0
33
4- use cryptoki:: {
5- object:: { Attribute , AttributeType , KeyType , ObjectClass , ObjectHandle } ,
6- session:: Session ,
7- } ;
4+ use cryptoki:: object:: { Attribute , AttributeType , KeyType , ObjectClass , ObjectHandle } ;
85use der:: { asn1:: ObjectIdentifier , oid:: AssociatedOid , Any , AnyRef } ;
96use rsa:: {
107 pkcs1:: { self , RsaPssParams } ,
@@ -20,17 +17,18 @@ use spki::{
2017use std:: convert:: TryFrom ;
2118
2219use super :: { DigestSigning , Error } ;
20+ use crate :: SessionLike ;
2321
24- pub struct Signer < D : DigestSigning > {
25- session : Session ,
22+ pub struct Signer < D : DigestSigning , S : SessionLike > {
23+ session : S ,
2624 _public_key : ObjectHandle ,
2725 private_key : ObjectHandle ,
2826 verifying_key : VerifyingKey < D > ,
2927 salt_len : usize ,
3028}
3129
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 > {
3432 // First we'll lookup a private key with that label.
3533 let template = vec ! [
3634 Attribute :: Token ( true ) ,
@@ -91,25 +89,25 @@ impl<D: DigestSigning> Signer<D> {
9189 } )
9290 }
9391
94- pub fn into_session ( self ) -> Session {
92+ pub fn into_session ( self ) -> S {
9593 self . session
9694 }
9795}
9896
99- impl < D : DigestSigning > AssociatedAlgorithmIdentifier for Signer < D > {
97+ impl < D : DigestSigning , S : SessionLike > AssociatedAlgorithmIdentifier for Signer < D , S > {
10098 type Params = AnyRef < ' static > ;
10199 const ALGORITHM_IDENTIFIER : AlgorithmIdentifierRef < ' static > = pkcs1:: ALGORITHM_ID ;
102100}
103101
104- impl < D : DigestSigning > signature:: Keypair for Signer < D > {
102+ impl < D : DigestSigning , S : SessionLike > signature:: Keypair for Signer < D , S > {
105103 type VerifyingKey = VerifyingKey < D > ;
106104
107105 fn verifying_key ( & self ) -> Self :: VerifyingKey {
108106 self . verifying_key . clone ( )
109107 }
110108}
111109
112- impl < D : DigestSigning > signature:: Signer < Signature > for Signer < D > {
110+ impl < D : DigestSigning , S : SessionLike > signature:: Signer < Signature > for Signer < D , S > {
113111 fn try_sign ( & self , msg : & [ u8 ] ) -> Result < Signature , signature:: Error > {
114112 let bytes = self
115113 . session
@@ -124,7 +122,7 @@ impl<D: DigestSigning> signature::Signer<Signature> for Signer<D> {
124122 }
125123}
126124
127- impl < D : DigestSigning > DynSignatureAlgorithmIdentifier for Signer < D > {
125+ impl < D : DigestSigning , S : SessionLike > DynSignatureAlgorithmIdentifier for Signer < D , S > {
128126 fn signature_algorithm_identifier ( & self ) -> pkcs8:: spki:: Result < AlgorithmIdentifierOwned > {
129127 get_pss_signature_algo_id :: < D > ( self . salt_len as u8 )
130128 }
0 commit comments