Skip to content

Commit e0fc46c

Browse files
committed
revert: remove x509 feature
1 parent 0e44116 commit e0fc46c

File tree

4 files changed

+12
-112
lines changed

4 files changed

+12
-112
lines changed

ed25519-dalek/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ merlin = { version = "3", default-features = false, optional = true }
3737
rand_core = { version = "0.6.4", default-features = false, optional = true }
3838
serde = { version = "1.0", default-features = false, optional = true }
3939
zeroize = { version = "1.5", default-features = false, optional = true }
40-
x509-cert = { version = "0.2.5", features = ["builder"], optional = true }
4140

4241
[dev-dependencies]
4342
curve25519-dalek = { version = "4", path = "../curve25519-dalek", default-features = false, features = ["digest", "rand_core"] }
@@ -72,7 +71,6 @@ digest = ["signature/digest"]
7271
hazmat = []
7372
# Turns off stricter checking for scalar malleability in signatures
7473
legacy_compatibility = ["curve25519-dalek/legacy_compatibility"]
75-
x509 = ["pkcs8", "alloc", "dep:x509-cert"]
7674
pkcs8 = ["ed25519/pkcs8"]
7775
pem = ["alloc", "ed25519/pem", "pkcs8"]
7876
rand_core = ["dep:rand_core"]

ed25519-dalek/src/lib.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -288,52 +288,7 @@ pub use crate::verifying::*;
288288
#[cfg(feature = "digest")]
289289
pub use ed25519::signature::{DigestSigner, DigestVerifier};
290290
pub use ed25519::signature::{Signer, Verifier};
291-
292-
#[cfg(not(feature = "x509"))]
293291
pub use ed25519::Signature;
294292

295-
#[cfg(feature = "x509")]
296-
pub use signature_wrapper::Signature;
297-
298-
#[cfg(feature = "x509")]
299-
mod signature_wrapper {
300-
use core::ops::Deref;
301-
use core::ops::DerefMut;
302-
303-
/// Wrapper over ed25519::Signature to enable additional trait implementations required to build x509 certificates
304-
#[derive(Copy, Clone, Eq, PartialEq)]
305-
#[repr(C)]
306-
pub struct Signature(pub ed25519::Signature);
307-
308-
impl Signature {
309-
/// Parse an Ed25519 signature from a byte slice.
310-
pub fn from_bytes(bytes: &ed25519::SignatureBytes) -> Self {
311-
Self(ed25519::Signature::from_bytes(bytes))
312-
}
313-
}
314-
315-
impl TryFrom<&[u8]> for Signature {
316-
type Error = ed25519::Error;
317-
318-
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
319-
Ok(Self(ed25519::Signature::try_from(value)?))
320-
}
321-
}
322-
323-
impl Deref for Signature {
324-
type Target = ed25519::Signature;
325-
326-
fn deref(&self) -> &Self::Target {
327-
&self.0
328-
}
329-
}
330-
331-
impl DerefMut for Signature {
332-
fn deref_mut(&mut self) -> &mut Self::Target {
333-
&mut self.0
334-
}
335-
}
336-
}
337-
338293
#[cfg(feature = "pkcs8")]
339294
pub use ed25519::pkcs8;

ed25519-dalek/src/signature.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,4 @@ impl From<InternalSignature> for ed25519::Signature {
174174
fn from(sig: InternalSignature) -> ed25519::Signature {
175175
ed25519::Signature::from_components(*sig.R.as_bytes(), *sig.s.as_bytes())
176176
}
177-
}
178-
179-
#[cfg(feature = "x509")]
180-
impl From<InternalSignature> for crate::Signature {
181-
fn from(value: InternalSignature) -> Self {
182-
crate::Signature(ed25519::Signature::from(value))
183-
}
184-
}
185-
186-
#[cfg(feature = "x509")]
187-
impl ed25519::pkcs8::spki::SignatureBitStringEncoding for crate::Signature {
188-
fn to_bitstring(&self) -> x509_cert::der::Result<x509_cert::der::asn1::BitString> {
189-
let signature: ed25519::Signature = self.0.into();
190-
191-
x509_cert::der::asn1::BitString::new(0, signature.to_vec())
192-
}
193177
}

ed25519-dalek/tests/pkcs8.rs

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@
44
//! RFC5958 (PKCS#8) and RFC5280 (SPKI).
55
66
#![cfg(feature = "pkcs8")]
7-
use ed25519_dalek::pkcs8::{DecodePrivateKey, DecodePublicKey};
7+
use ed25519_dalek::pkcs8::{spki::DynSignatureAlgorithmIdentifier, DecodePrivateKey, DecodePublicKey};
88
use ed25519_dalek::{SigningKey, VerifyingKey};
99
use hex_literal::hex;
1010

1111
#[cfg(feature = "alloc")]
1212
use ed25519_dalek::pkcs8::{EncodePrivateKey, EncodePublicKey};
1313

14-
#[cfg(feature = "x509")]
15-
use x509_cert::builder::Builder;
16-
#[cfg(feature = "x509")]
17-
use x509_cert::der::EncodePem;
18-
#[cfg(feature = "x509")]
19-
use x509_cert::spki::DynSignatureAlgorithmIdentifier;
20-
2114
/// Ed25519 PKCS#8 v1 private key encoded as ASN.1 DER.
2215
const PKCS8_V1_DER: &[u8] = include_bytes!("examples/pkcs8-v1.der");
2316

@@ -76,45 +69,15 @@ fn encode_verifying_key() {
7669
assert_eq!(verifying_key, verifying_key2);
7770
}
7871

79-
#[cfg(feature = "x509")]
8072
#[test]
81-
fn build_valid_x509_cert() {
82-
use std::time::Duration;
83-
use std::str::FromStr;
84-
use x509_cert::{
85-
builder::{CertificateBuilder, Profile},
86-
name::Name,
87-
serial_number::SerialNumber,
88-
spki:: SubjectPublicKeyInfoOwned,
89-
time::Validity,
90-
};
91-
let profile = Profile::Root;
92-
let serial_number = SerialNumber::from(42u32);
93-
let validity = Validity::from_now(Duration::new(360, 0)).unwrap();
94-
let subject = Name::from_str("CN=World domination corporation,O=World domination Inc,C=US").unwrap();
95-
let signing = SigningKey::from_bytes(&SK_BYTES);
96-
let verifying_key = VerifyingKey::from_bytes(&PK_BYTES).unwrap();
97-
let public_key = verifying_key.to_public_key_der().unwrap();
98-
let key_info =
99-
SubjectPublicKeyInfoOwned::try_from(&public_key.as_bytes()[..]).unwrap();
100-
101-
let builder = CertificateBuilder::new(
102-
profile,
103-
serial_number,
104-
validity,
105-
subject,
106-
key_info,
107-
&signing,
108-
)
109-
.expect("should create certificate");
110-
111-
let certificate = builder.build().unwrap();
112-
certificate.to_pem(x509_cert::der::pem::LineEnding::LF).expect("should generate pem");
113-
114-
// Note: In order to verify the certificate the same way the x509_cert crate does it via `x509-cert-test-support`, it requires an additional `zlint` tool to be installed
115-
// The tool is installed via `go install github.com/zmap/zlint/v3/cmd/zlint@latest`.
116-
//
117-
// TODO: Blocked by: https://github.com/zmap/zlint/issues/883
118-
// let ignored = &[];
119-
// x509_cert_test_support::zlint::check_certificate(pem.as_bytes(), ignored);
120-
}
73+
fn get_algo_identifier() {
74+
let verifying_key = VerifyingKey::from_public_key_der(PUBLIC_KEY_DER).unwrap();
75+
let identifier = verifying_key.signature_algorithm_identifier().unwrap();
76+
assert!(identifier.parameters.is_none()); // According to rfc8410 this must be None
77+
assert_eq!(identifier.oid, ed25519::pkcs8::ALGORITHM_OID);
78+
79+
let signing_key = SigningKey::from_bytes(&SK_BYTES);
80+
let identifer = signing_key.signature_algorithm_identifier().unwrap();
81+
assert!(identifer.parameters.is_none()); // According to rfc8410 this must be None
82+
assert_eq!(identifer.oid, ed25519::pkcs8::ALGORITHM_OID);
83+
}

0 commit comments

Comments
 (0)