Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions der/src/reader/pem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ impl<'i> Reader<'i> for PemReader<'i> {
}

fn read_into<'o>(&mut self, buf: &'o mut [u8]) -> crate::Result<&'o [u8]> {
if buf.is_empty() {
return Ok(buf);
}

let new_position = (self.position + buf.len())?;
if new_position > self.input_len {
return Err(ErrorKind::Incomplete {
Expand Down
22 changes: 18 additions & 4 deletions der/tests/pem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![cfg(all(feature = "derive", feature = "oid", feature = "pem"))]

use der::{
Decode, DecodePem, EncodePem, Sequence,
Any, Decode, DecodePem, EncodePem, Sequence,
asn1::{BitString, ObjectIdentifier},
pem::{LineEnding, PemLabel},
};
Expand All @@ -15,14 +15,14 @@ const SPKI_DER: &[u8] = include_bytes!("examples/spki.der");
const SPKI_PEM: &str = include_str!("examples/spki.pem");

/// X.509 `AlgorithmIdentifier`
#[derive(Copy, Clone, Debug, Eq, PartialEq, Sequence)]
#[derive(Clone, Debug, Eq, PartialEq, Sequence)]
pub struct AlgorithmIdentifier {
pub algorithm: ObjectIdentifier,
// pub parameters: ... (not used in spki.pem)
pub parameters: Option<Any>,
}

/// X.509 `SubjectPublicKeyInfo` (SPKI) in borrowed form
#[derive(Copy, Clone, Debug, Eq, PartialEq, Sequence)]
#[derive(Clone, Debug, Eq, PartialEq, Sequence)]
pub struct SpkiBorrowed<'a> {
pub algorithm: AlgorithmIdentifier,
#[asn1(type = "BIT STRING")]
Expand Down Expand Up @@ -65,3 +65,17 @@ fn to_pem() {
let pem = spki.to_pem(LineEnding::LF).unwrap();
assert_eq!(&pem, SPKI_PEM);
}

#[test]
fn read_zero_slices_from_pem() {
let spki = SpkiOwned {
algorithm: AlgorithmIdentifier {
algorithm: ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.11"),
parameters: Some(Any::null()),
},
subject_public_key: BitString::new(0, []).unwrap(),
};

let pem = spki.to_pem(LineEnding::LF).unwrap();
SpkiOwned::from_pem(pem).unwrap();
}