Skip to content

Commit

Permalink
ed25519: implement SignatureBitStringEncoding support (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo authored Jan 23, 2025
1 parent 753cfcf commit e5a732d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ed25519/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,25 @@ mod serde;
pub use signature::{self, Error, SignatureEncoding};

#[cfg(feature = "pkcs8")]
pub use crate::pkcs8::{KeypairBytes, PublicKeyBytes};
pub use crate::pkcs8::{
spki::{
der::{oid::ObjectIdentifier, AnyRef},
AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier,
},
KeypairBytes, PublicKeyBytes,
};

use core::fmt;

#[cfg(feature = "alloc")]
use alloc::vec::Vec;

#[cfg(all(feature = "alloc", feature = "pkcs8"))]
use pkcs8::spki::{
der::{self, asn1::BitString},
SignatureBitStringEncoding,
};

/// Size of a single component of an Ed25519 signature.
const COMPONENT_SIZE: usize = 32;

Expand Down Expand Up @@ -371,6 +383,23 @@ impl SignatureEncoding for Signature {
}
}

#[cfg(all(feature = "alloc", feature = "pkcs8"))]
impl SignatureBitStringEncoding for Signature {
fn to_bitstring(&self) -> der::Result<BitString> {
BitString::new(0, self.to_vec())
}
}

#[cfg(feature = "pkcs8")]
impl AssociatedAlgorithmIdentifier for Signature {
type Params = AnyRef<'static>;

const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> = AlgorithmIdentifierRef {
oid: ObjectIdentifier::new_unwrap("1.3.101.112"),
parameters: None,
};
}

impl From<Signature> for SignatureBytes {
fn from(sig: Signature) -> SignatureBytes {
sig.to_bytes()
Expand Down

0 comments on commit e5a732d

Please sign in to comment.