Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add test for mixed DER/BER encoding CMS #827

Closed
wants to merge 2 commits into from
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
24 changes: 24 additions & 0 deletions pkcs7/tests/content_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,27 @@ fn decode_signed_scep_example() {
_ => panic!("expected ContentInfo::SignedData(Some(_))"),
}
}

#[test]
fn decode_signed_ber() {
let path = "./tests/examples/cms_der.bin";
let bytes = fs::read(&path).expect(&format!("Failed to read from {}", &path));

let content = ContentInfo::from_der(&bytes).expect("expected valid data");

match content {
ContentInfo::SignedData(Some(data)) => {
assert_eq!(
data.encap_content_info
.e_content
.unwrap()
.decode_into::<OctetStringRef>()
.unwrap()
.as_bytes()
.len(),
10034
)
}
_ => panic!("expected ContentInfo::SignedData(Some(_))"),
}
Comment on lines +146 to +165
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let path = "./tests/examples/cms_der.bin";
let bytes = fs::read(&path).expect(&format!("Failed to read from {}", &path));
let content = ContentInfo::from_der(&bytes).expect("expected valid data");
match content {
ContentInfo::SignedData(Some(data)) => {
assert_eq!(
data.encap_content_info
.e_content
.unwrap()
.decode_into::<OctetStringRef>()
.unwrap()
.as_bytes()
.len(),
10034
)
}
_ => panic!("expected ContentInfo::SignedData(Some(_))"),
}
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_into::<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.