mirror of
https://github.com/RustCrypto/signatures
synced 2026-06-21 13:45:42 +00:00
ed25519: optional zerocopy dependency (#1134)
Derives trait impls for `Signature` and `PublicKeyBytes`
This commit is contained in:
committed by
GitHub
parent
3138dd20e3
commit
db04f38935
Generated
+1
@@ -407,6 +407,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"signature",
|
||||
"zerocopy",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ pkcs8 = { version = "0.11.0-rc.8", optional = true }
|
||||
serde = { version = "1", optional = true, default-features = false }
|
||||
serde_bytes = { version = "0.11", optional = true, default-features = false }
|
||||
zeroize = { version = "1", optional = true, default-features = false }
|
||||
zerocopy = { version = "0.8", optional = true, features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
#ed25519-dalek = { version = "2", features = ["rand_core"] }
|
||||
|
||||
@@ -296,6 +296,9 @@ use pkcs8::spki::{
|
||||
#[cfg(feature = "zeroize")]
|
||||
use zeroize::Zeroize;
|
||||
|
||||
#[cfg(feature = "zerocopy")]
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Unaligned};
|
||||
|
||||
/// Size of a single component of an Ed25519 signature.
|
||||
const COMPONENT_SIZE: usize = 32;
|
||||
|
||||
@@ -314,6 +317,10 @@ pub type SignatureBytes = [u8; Signature::BYTE_SIZE];
|
||||
/// Signature verification libraries are expected to reject invalid field
|
||||
/// elements at the time a signature is verified.
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
#[cfg_attr(
|
||||
feature = "zerocopy",
|
||||
derive(FromBytes, IntoBytes, Immutable, KnownLayout, Unaligned)
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct Signature {
|
||||
R: ComponentBytes,
|
||||
|
||||
@@ -35,6 +35,9 @@ use core::str;
|
||||
#[cfg(feature = "zeroize")]
|
||||
use zeroize::Zeroize;
|
||||
|
||||
#[cfg(feature = "zerocopy")]
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Unaligned};
|
||||
|
||||
/// Algorithm [`ObjectIdentifier`] for the Ed25519 digital signature algorithm
|
||||
/// (`id-Ed25519`).
|
||||
///
|
||||
@@ -226,6 +229,11 @@ impl str::FromStr for KeypairBytes {
|
||||
/// Note that this type operates on raw bytes and performs no validation that
|
||||
/// public keys represent valid compressed Ed25519 y-coordinates.
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
#[cfg_attr(
|
||||
feature = "zerocopy",
|
||||
derive(IntoBytes, FromBytes, Unaligned, KnownLayout, Immutable,)
|
||||
)]
|
||||
#[repr(transparent)]
|
||||
pub struct PublicKeyBytes(pub [u8; Self::BYTE_SIZE]);
|
||||
|
||||
impl PublicKeyBytes {
|
||||
|
||||
Reference in New Issue
Block a user