diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
commit | a0aa2307322cd47bbf416810ac0292925e03be87 (patch) | |
tree | 37076262a026c4b48c8a0e84f44ff9187556ca35 /rust/vendor/x509-parser/src/utils.rs | |
parent | Initial commit. (diff) | |
download | suricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip |
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/vendor/x509-parser/src/utils.rs')
-rw-r--r-- | rust/vendor/x509-parser/src/utils.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/rust/vendor/x509-parser/src/utils.rs b/rust/vendor/x509-parser/src/utils.rs new file mode 100644 index 0000000..72b4d99 --- /dev/null +++ b/rust/vendor/x509-parser/src/utils.rs @@ -0,0 +1,19 @@ +/// Formats a slice to a colon-separated hex string (for ex `01:02:ff:ff`) +pub fn format_serial(i: &[u8]) -> String { + let mut s = i.iter().fold(String::with_capacity(3 * i.len()), |a, b| { + a + &format!("{:02x}:", b) + }); + s.pop(); + s +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_format_serial() { + let b: &[u8] = &[1, 2, 3, 4, 0xff]; + assert_eq!("01:02:03:04:ff", format_serial(b)); + } +} |