Skip to content

Commit

Permalink
rework rsa signer algorithm
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Gautier <[email protected]>
  • Loading branch information
baloo committed Dec 1, 2023
1 parent 9739b9e commit 7358fa6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
34 changes: 18 additions & 16 deletions cryptoki-rustcrypto/src/rsa/pkcs1v15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use cryptoki::object::{Attribute, AttributeType, KeyType, ObjectClass, ObjectHandle};
use der::AnyRef;
use rsa::{
pkcs1,
pkcs1v15::{Signature, VerifyingKey},
};
use spki::{AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier, SignatureAlgorithmIdentifier};
use rsa::pkcs1v15::{RsaSignatureAssociatedOid, Signature, VerifyingKey};
use spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier, SignatureAlgorithmIdentifier};
use std::convert::TryFrom;

use super::{read_key, DigestSigning, Error};
Expand Down Expand Up @@ -71,9 +67,14 @@ impl<D: DigestSigning, S: SessionLike> Signer<D, S> {
}
}

impl<D: DigestSigning, S: SessionLike> AssociatedAlgorithmIdentifier for Signer<D, S> {
type Params = AnyRef<'static>;
const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> = pkcs1::ALGORITHM_ID;
impl<D, S> AssociatedAlgorithmIdentifier for Signer<D, S>
where
D: DigestSigning,
S: SessionLike,
{
type Params = <VerifyingKey<D> as AssociatedAlgorithmIdentifier>::Params;
const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> =
<VerifyingKey<D> as AssociatedAlgorithmIdentifier>::ALGORITHM_IDENTIFIER;
}

impl<D: DigestSigning, S: SessionLike> signature::Keypair for Signer<D, S> {
Expand All @@ -99,12 +100,13 @@ impl<D: DigestSigning, S: SessionLike> signature::Signer<Signature> for Signer<D
}
}

impl<D: DigestSigning, S: SessionLike> SignatureAlgorithmIdentifier for Signer<D, S> {
type Params = AnyRef<'static>;
impl<D, S> SignatureAlgorithmIdentifier for Signer<D, S>
where
S: SessionLike,
D: DigestSigning + RsaSignatureAssociatedOid,
{
type Params = <VerifyingKey<D> as SignatureAlgorithmIdentifier>::Params;

const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> =
AlgorithmIdentifierRef {
oid: D::OID,
parameters: Some(AnyRef::NULL),
};
const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> =
<VerifyingKey<D> as SignatureAlgorithmIdentifier>::SIGNATURE_ALGORITHM_IDENTIFIER;
}
5 changes: 2 additions & 3 deletions cryptoki-rustcrypto/src/rsa/pss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

use cryptoki::object::{Attribute, AttributeType, KeyType, ObjectClass, ObjectHandle};
use der::{asn1::ObjectIdentifier, oid::AssociatedOid, Any, AnyRef};
use der::AnyRef;
use rsa::{
pkcs1::{self, RsaPssParams},
pkcs1,
pkcs8::{self},
pss::{get_default_pss_signature_algo_id, Signature, VerifyingKey},
};
use signature::digest::Digest;
use spki::{
AlgorithmIdentifierOwned, AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier,
DynSignatureAlgorithmIdentifier,
Expand Down

0 comments on commit 7358fa6

Please sign in to comment.