x509_parser/
utils.rs

1/// Formats a slice to a colon-separated hex string (for ex `01:02:ff:ff`)
2pub fn format_serial(i: &[u8]) -> String {
3    let mut s = i.iter().fold(String::with_capacity(3 * i.len()), |a, b| {
4        a + &format!("{:02x}:", b)
5    });
6    s.pop();
7    s
8}
9
10#[cfg(test)]
11mod tests {
12    use super::*;
13
14    #[test]
15    fn test_format_serial() {
16        let b: &[u8] = &[1, 2, 3, 4, 0xff];
17        assert_eq!("01:02:03:04:ff", format_serial(b));
18    }
19}