byte-array-ops 0.4.0

A no_std-compatible library for security-by-default byte array operations. Includes automatic memory zeroization, constant-time utilities, multiple input formats (hex, binary, UTF-8), bitwise operations, and comprehensive type conversions with minimal dependencies.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#[doc(hidden)]
pub(super) struct Utils;

impl Utils {
    /// Warning : Only use in contexts where it is sure we have a hex string
    /// Checks must take place before calling this
    /// This will panic otherwise
    /// TODO : make this Result<T,E> just in case
    pub(super) fn hex_char_to_nibble_unchecked(byte: u8) -> u8 {
        match byte {
            b'0'..=b'9' => byte - b'0',
            b'a'..=b'f' => byte - b'a' + 10,
            b'A'..=b'F' => byte - b'A' + 10,
            _ => unreachable!(), // already validated
        }
    }
}