chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

67
vendor/der/tests/pem.rs vendored Normal file
View File

@@ -0,0 +1,67 @@
//! PEM decoding and encoding tests.
#![cfg(all(feature = "derive", feature = "oid", feature = "pem"))]
use der::{
asn1::{BitString, ObjectIdentifier},
pem::{LineEnding, PemLabel},
Decode, DecodePem, EncodePem, Sequence,
};
/// Example SPKI document encoded as DER.
const SPKI_DER: &[u8] = include_bytes!("examples/spki.der");
/// Example SPKI document encoded as PEM.
const SPKI_PEM: &str = include_str!("examples/spki.pem");
/// X.509 `AlgorithmIdentifier`
#[derive(Copy, Clone, Debug, Eq, PartialEq, Sequence)]
pub struct AlgorithmIdentifier {
pub algorithm: ObjectIdentifier,
// pub parameters: ... (not used in spki.pem)
}
/// X.509 `SubjectPublicKeyInfo` (SPKI) in borrowed form
#[derive(Copy, Clone, Debug, Eq, PartialEq, Sequence)]
pub struct SpkiBorrowed<'a> {
pub algorithm: AlgorithmIdentifier,
#[asn1(type = "BIT STRING")]
pub subject_public_key: &'a [u8],
}
impl PemLabel for SpkiBorrowed<'_> {
const PEM_LABEL: &'static str = "PUBLIC KEY";
}
/// X.509 `SubjectPublicKeyInfo` (SPKI) in owned form
#[derive(Clone, Debug, Eq, PartialEq, Sequence)]
pub struct SpkiOwned {
pub algorithm: AlgorithmIdentifier,
pub subject_public_key: BitString,
}
impl PemLabel for SpkiOwned {
const PEM_LABEL: &'static str = "PUBLIC KEY";
}
#[test]
fn from_pem() {
// Decode PEM to owned form.
let pem_spki = SpkiOwned::from_pem(SPKI_PEM).unwrap();
// Decode DER to borrowed form.
let der_spki = SpkiBorrowed::from_der(SPKI_DER).unwrap();
assert_eq!(pem_spki.algorithm, der_spki.algorithm);
assert_eq!(
pem_spki.subject_public_key.raw_bytes(),
der_spki.subject_public_key
);
}
#[test]
fn to_pem() {
let spki = SpkiBorrowed::from_der(SPKI_DER).unwrap();
let pem = spki.to_pem(LineEnding::LF).unwrap();
assert_eq!(&pem, SPKI_PEM);
}