Skip to content

Commit d159f47

Browse files
authored
ed25519-dalek: use SignatureAlgorithmIdenfier instead of the dynamic counterpart (#779)
This allows to use ed25519 to create certificates for example This partially reverts #712
1 parent a99efe2 commit d159f47

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

ed25519-dalek/src/signing.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -676,20 +676,6 @@ impl pkcs8::EncodePrivateKey for SigningKey {
676676
}
677677
}
678678

679-
#[cfg(all(feature = "alloc", feature = "pkcs8"))]
680-
impl pkcs8::spki::DynSignatureAlgorithmIdentifier for SigningKey {
681-
fn signature_algorithm_identifier(
682-
&self,
683-
) -> pkcs8::spki::Result<pkcs8::spki::AlgorithmIdentifierOwned> {
684-
// From https://datatracker.ietf.org/doc/html/rfc8410
685-
// `id-Ed25519 OBJECT IDENTIFIER ::= { 1 3 101 112 }`
686-
Ok(pkcs8::spki::AlgorithmIdentifier {
687-
oid: ed25519::pkcs8::ALGORITHM_OID,
688-
parameters: None,
689-
})
690-
}
691-
}
692-
693679
#[cfg(feature = "pkcs8")]
694680
impl TryFrom<pkcs8::KeypairBytes> for SigningKey {
695681
type Error = pkcs8::Error;
@@ -720,6 +706,14 @@ impl TryFrom<&pkcs8::KeypairBytes> for SigningKey {
720706
}
721707
}
722708

709+
#[cfg(feature = "pkcs8")]
710+
impl pkcs8::spki::SignatureAlgorithmIdentifier for SigningKey {
711+
type Params = pkcs8::spki::der::AnyRef<'static>;
712+
713+
const SIGNATURE_ALGORITHM_IDENTIFIER: pkcs8::spki::AlgorithmIdentifier<Self::Params> =
714+
<Signature as pkcs8::spki::AssociatedAlgorithmIdentifier>::ALGORITHM_IDENTIFIER;
715+
}
716+
723717
#[cfg(feature = "pkcs8")]
724718
impl From<SigningKey> for pkcs8::KeypairBytes {
725719
fn from(signing_key: SigningKey) -> pkcs8::KeypairBytes {

ed25519-dalek/src/verifying.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,14 @@ impl TryFrom<&[u8]> for VerifyingKey {
610610
}
611611
}
612612

613+
#[cfg(feature = "pkcs8")]
614+
impl pkcs8::spki::SignatureAlgorithmIdentifier for VerifyingKey {
615+
type Params = pkcs8::spki::der::AnyRef<'static>;
616+
617+
const SIGNATURE_ALGORITHM_IDENTIFIER: pkcs8::spki::AlgorithmIdentifier<Self::Params> =
618+
<ed25519::Signature as pkcs8::spki::AssociatedAlgorithmIdentifier>::ALGORITHM_IDENTIFIER;
619+
}
620+
613621
impl From<VerifyingKey> for EdwardsPoint {
614622
fn from(vk: VerifyingKey) -> EdwardsPoint {
615623
vk.point
@@ -623,20 +631,6 @@ impl pkcs8::EncodePublicKey for VerifyingKey {
623631
}
624632
}
625633

626-
#[cfg(all(feature = "alloc", feature = "pkcs8"))]
627-
impl pkcs8::spki::DynSignatureAlgorithmIdentifier for VerifyingKey {
628-
fn signature_algorithm_identifier(
629-
&self,
630-
) -> pkcs8::spki::Result<pkcs8::spki::AlgorithmIdentifierOwned> {
631-
// From https://datatracker.ietf.org/doc/html/rfc8410
632-
// `id-Ed25519 OBJECT IDENTIFIER ::= { 1 3 101 112 }`
633-
Ok(ed25519::pkcs8::spki::AlgorithmIdentifierOwned {
634-
oid: ed25519::pkcs8::ALGORITHM_OID,
635-
parameters: None,
636-
})
637-
}
638-
}
639-
640634
#[cfg(feature = "pkcs8")]
641635
impl TryFrom<pkcs8::PublicKeyBytes> for VerifyingKey {
642636
type Error = pkcs8::spki::Error;

0 commit comments

Comments
 (0)