xarf-rs 0.1.4

XARF v4 (eXtended Abuse Reporting Format) parser, validator, and generator with v3 compatibility
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Lower-case hex encoder for digest output.
//!
//! Written byte-at-a-time into a pre-sized `String` via a 16-entry lookup
//! table — no per-byte heap allocations.

const TABLE: &[u8; 16] = b"0123456789abcdef";

/// Encode `bytes` as lower-case hex. Result length is `bytes.len() * 2`.
pub(crate) fn encode(bytes: &[u8]) -> String {
    let mut out = Vec::with_capacity(bytes.len() * 2);
    for &b in bytes {
        out.push(TABLE[(b >> 4) as usize]);
        out.push(TABLE[(b & 0x0f) as usize]);
    }
    // SAFETY: TABLE contains only ASCII digits 0-9a-f, so every pushed byte is
    // valid UTF-8.
    unsafe { String::from_utf8_unchecked(out) }
}