Skip to content

Commit 7358fa6

Browse files
committed
rework rsa signer algorithm
Signed-off-by: Arthur Gautier <[email protected]>
1 parent 9739b9e commit 7358fa6

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

cryptoki-rustcrypto/src/rsa/pkcs1v15.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use cryptoki::object::{Attribute, AttributeType, KeyType, ObjectClass, ObjectHandle};
5-
use der::AnyRef;
6-
use rsa::{
7-
pkcs1,
8-
pkcs1v15::{Signature, VerifyingKey},
9-
};
10-
use spki::{AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier, SignatureAlgorithmIdentifier};
5+
use rsa::pkcs1v15::{RsaSignatureAssociatedOid, Signature, VerifyingKey};
6+
use spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier, SignatureAlgorithmIdentifier};
117
use std::convert::TryFrom;
128

139
use super::{read_key, DigestSigning, Error};
@@ -71,9 +67,14 @@ impl<D: DigestSigning, S: SessionLike> Signer<D, S> {
7167
}
7268
}
7369

74-
impl<D: DigestSigning, S: SessionLike> AssociatedAlgorithmIdentifier for Signer<D, S> {
75-
type Params = AnyRef<'static>;
76-
const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> = pkcs1::ALGORITHM_ID;
70+
impl<D, S> AssociatedAlgorithmIdentifier for Signer<D, S>
71+
where
72+
D: DigestSigning,
73+
S: SessionLike,
74+
{
75+
type Params = <VerifyingKey<D> as AssociatedAlgorithmIdentifier>::Params;
76+
const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> =
77+
<VerifyingKey<D> as AssociatedAlgorithmIdentifier>::ALGORITHM_IDENTIFIER;
7778
}
7879

7980
impl<D: DigestSigning, S: SessionLike> signature::Keypair for Signer<D, S> {
@@ -99,12 +100,13 @@ impl<D: DigestSigning, S: SessionLike> signature::Signer<Signature> for Signer<D
99100
}
100101
}
101102

102-
impl<D: DigestSigning, S: SessionLike> SignatureAlgorithmIdentifier for Signer<D, S> {
103-
type Params = AnyRef<'static>;
103+
impl<D, S> SignatureAlgorithmIdentifier for Signer<D, S>
104+
where
105+
S: SessionLike,
106+
D: DigestSigning + RsaSignatureAssociatedOid,
107+
{
108+
type Params = <VerifyingKey<D> as SignatureAlgorithmIdentifier>::Params;
104109

105-
const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> =
106-
AlgorithmIdentifierRef {
107-
oid: D::OID,
108-
parameters: Some(AnyRef::NULL),
109-
};
110+
const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> =
111+
<VerifyingKey<D> as SignatureAlgorithmIdentifier>::SIGNATURE_ALGORITHM_IDENTIFIER;
110112
}

cryptoki-rustcrypto/src/rsa/pss.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use cryptoki::object::{Attribute, AttributeType, KeyType, ObjectClass, ObjectHandle};
5-
use der::{asn1::ObjectIdentifier, oid::AssociatedOid, Any, AnyRef};
5+
use der::AnyRef;
66
use rsa::{
7-
pkcs1::{self, RsaPssParams},
7+
pkcs1,
88
pkcs8::{self},
99
pss::{get_default_pss_signature_algo_id, Signature, VerifyingKey},
1010
};
11-
use signature::digest::Digest;
1211
use spki::{
1312
AlgorithmIdentifierOwned, AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier,
1413
DynSignatureAlgorithmIdentifier,

0 commit comments

Comments
 (0)