Skip to content

Commit

Permalink
Add test for issue 76 (wrong handling of UTF-16 data)
Browse files Browse the repository at this point in the history
  • Loading branch information
chifflier committed Jan 21, 2025
1 parent a235c2a commit 7ba0ae7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/issue-76.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use der_parser::ber::*;

#[test]
fn issue76_example1() {
// This is a 4 bytes (2 characters) UTF-16-BE string. The first two bytes are the tag and size.
let bytes = [0x80, 0x04, 0x00, 0x4c, 0x00, 0x65];
let (i, header) = ber_read_element_header(&bytes).expect("parsing failed");
let (rem, _content) =
parse_ber_content(Tag::BmpString)(i, &header, MAX_RECURSION).expect("parsing failed");
assert!(rem.is_empty());
}

#[test]
fn issue76_example2() {
// This is a 6 bytes (3 characters) UTF-16-BE string. The first two bytes are the tag and size.
let bytes = [0x80, 0x06, 0x79, 0x3E, 0x30, 0xBA, 0x30, 0xFC];
let (i, header) = ber_read_element_header(&bytes).expect("parsing failed");
let (rem, _content) =
parse_ber_content(Tag::BmpString)(i, &header, MAX_RECURSION).expect("parsing failed");
assert!(rem.is_empty());
}

0 comments on commit 7ba0ae7

Please sign in to comment.