rama-http-types 0.3.0-rc1

rama http type defintions and high level utilities
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mod http;
#[doc(inline)]
pub use http::{Ja4H, Ja4HComputeError};

/// 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()
    }
}