Skip to content

Commit

Permalink
Fixed #1 and added tests for this case
Browse files Browse the repository at this point in the history
  • Loading branch information
KizzyCode committed Jun 13, 2019
1 parent 2e781a3 commit dbc7ab1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/der/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ impl DerValue {
pub fn deserialize<'a>(mut source: impl Iterator<Item = &'a u8>, len: impl Into<usize>)
-> Result<Self, Asn1DerError>
{
// Create buffer
let len = len.into();
let mut data_buf = vec![0u8; len];

// Copy data into buffer
for b in data_buf.iter_mut() {
*b = *source.next().ok_or(Asn1DerError::LengthMismatch)?;
// Create buffer and fill it with `len` bytes
let mut data_buf = Vec::new();
for _ in 0..len.into() {
data_buf.push(*source.next().ok_or(Asn1DerError::LengthMismatch)?);
}
Ok(data_buf.into())
}
Expand Down
4 changes: 3 additions & 1 deletion tests/der.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ fn test_err() {
// Incomplete value
(b"\x0c\x09\x54\x65\x73\x74\x6F\x6C\x6F\x70".as_ref(), Asn1DerError::LengthMismatch),
// Complex length > 2^64 - 1
(b"\x77\x89\x01\x00\x00\x00\x00\x00\x00\x00\x00".as_ref(), Asn1DerError::Unsupported)
(b"\x77\x89\x01\x00\x00\x00\x00\x00\x00\x00\x00".as_ref(), Asn1DerError::Unsupported),
// Excessive length announcement
(b"\x9d\xf7\x9d\x9d\x9d\x9d\x9d\x9d\x9d\x9d\x9d\x9d\x9d\x9d\x9d\x43\x9d\x01\x00\x00\x00\x9d\x9d\x9d\x9d\x9d\x9d\x9d\x9d".as_ref(), Asn1DerError::LengthMismatch)
].iter().for_each(test);
}

0 comments on commit dbc7ab1

Please sign in to comment.