Skip to content

Commit

Permalink
pkcs7: add test for mixed DER/BER encoding CMS (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri authored Jan 9, 2023
1 parent 4f027c7 commit 89d7d90
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pkcs7/tests/content_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,49 @@ fn decode_signed_scep_example() {
_ => panic!("expected ContentInfo::SignedData(Some(_))"),
}
}

// TODO(tarcieri): BER support
#[test]
#[ignore]
fn decode_signed_ber() {
let bytes = include_bytes!("examples/cms_ber.bin");

let content = match ContentInfo::from_der(bytes) {
Ok(ContentInfo::SignedData(Some(data))) => data,
other => panic!("unexpected result: {:?}", other),
};

assert_eq!(
content
.encap_content_info
.e_content
.unwrap()
.decode_as::<OctetStringRef>()
.unwrap()
.as_bytes()
.len(),
10034
);
}

#[test]
fn decode_signed_der() {
let bytes = include_bytes!("examples/cms_der.bin");

let content = match ContentInfo::from_der(bytes) {
Ok(ContentInfo::SignedData(Some(data))) => data,
other => panic!("unexpected result: {:?}", other),
};

assert_eq!(
content
.encap_content_info
.e_content
.unwrap()
.decode_as::<OctetStringRef>()
.unwrap()
.as_bytes()
.len(),
10034
);
}
Binary file added pkcs7/tests/examples/cms_ber.bin
Binary file not shown.
Binary file added pkcs7/tests/examples/cms_der.bin
Binary file not shown.

0 comments on commit 89d7d90

Please sign in to comment.