Skip to content
Open
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
2 changes: 1 addition & 1 deletion der/src/asn1/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'a> DecodeValue<'a> for &'a SequenceRef {
}
}

impl EncodeValue for SequenceRef {
impl EncodeValue for &SequenceRef {
fn value_len(&self) -> Result<Length> {
Ok(self.body.len())
}
Expand Down
35 changes: 35 additions & 0 deletions der/tests/derive_no_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,41 @@ mod sequence {
assert_eq!(obj, obj_decoded);
}
}

/// Custom derive test cases for the `Sequence` macro with oid support.
#[cfg(all(feature = "oid", feature = "heapless"))]
mod sequence_oid {
use const_oid::ObjectIdentifier;
use der::Decode;
use der::Encode;
use der::Sequence;
use der::asn1::SequenceRef;
use hex_literal::hex;

/// Example from: <https://github.com/RustCrypto/formats/issues/1976>
#[derive(Debug, Sequence)]
pub struct OidAndImplicitSequence<'a> {
pub oid: ObjectIdentifier,
#[asn1(context_specific = "0", tag_mode = "IMPLICIT")]
pub data: &'a SequenceRef,
}

#[test]
fn roundtrip_oid_and_implicit_sequence() {
let obj_data: &[u8] = &hex!(
"30 09" // SEQUENCE
"06 03" // OBJECT IDENTIFIER
"29 01 01" // oid "1.1.1.1"
"A0 02" // CONTEXT-SPECIFIC [0] (constructed)
"AA BB"
);
let obj = OidAndImplicitSequence::from_der(obj_data).unwrap();

assert_eq!(obj.data.as_bytes(), &hex!("AA BB"));
assert_eq!(obj_data, &obj.to_der().unwrap());
}
}

/// Custom derive test cases for the `Sequence` macro with heapless crate.
#[cfg(all(feature = "oid", feature = "heapless"))]
mod sequence_heapless_vec {
Expand Down
Loading