Skip to content

Commit

Permalink
Fix OctetString inner bytes rendering (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestTvarynka authored Aug 24, 2024
1 parent d99b39b commit cc09a1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions crates/asn1-parser/tests/decode_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,15 @@ fn test_1() {
let asn1 = Asn1::decode_buff(raw).unwrap();
println!("{:?}", asn1);
}

#[test]
fn test_2() {
init_logging();

let raw = &[
4, 24, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0,
];

let asn1 = Asn1::decode_buff(raw).unwrap();
println!("{:?}", asn1);
}
8 changes: 7 additions & 1 deletion src/asn1/scheme/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ pub fn octet_string(props: &OctetStringNodeProps) -> Html {
},
None => {
let encoded_octets = match std::str::from_utf8(octets) {
Ok(s) => s.to_owned(),
Ok(s) => {
if s.chars().any(|c| (c as u8) < 32) {
hex::encode(octets)
} else {
s.to_owned()
}
}
Err(_) => hex::encode(octets),
};
html! {
Expand Down

0 comments on commit cc09a1f

Please sign in to comment.