rama-tls 0.3.0

rama TLS-agnostic types and utilities
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mod tls;

pub use tls::{Ja4, Ja4ComputeError};

/// Hash a string into the 12-hex-char truncated SHA-256 digest used by the
/// JA4 family. Empty input maps to the all-zero sentinel per the spec.
fn hash12(s: impl AsRef<str>) -> std::borrow::Cow<'static, str> {
    use sha2::{Digest as _, Sha256};

    let s = s.as_ref();
    if s.is_empty() {
        "000000000000".into()
    } else {
        let sha256 = Sha256::digest(s);
        hex::encode(&sha256.as_slice()[..6]).into()
    }
}