base16ct 1.0.0

Pure Rust implementation of Base16 a.k.a hexadecimal (RFC 4648) which avoids any usages of data-dependent branches/LUTs and thereby provides portable "best effort" constant-time operation and embedded-friendly no_std support
Documentation
use core::fmt;

/// `core::fmt` presenter for binary data encoded as hexadecimal (Base16).
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct HexDisplay<'a>(pub &'a [u8]);

impl fmt::Display for HexDisplay<'_> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{self:X}")
    }
}

impl fmt::UpperHex for HexDisplay<'_> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut hex = [0u8; 2];

        for &byte in self.0 {
            f.write_str(crate::upper::encode_str(&[byte], &mut hex)?)?;
        }

        Ok(())
    }
}

impl fmt::LowerHex for HexDisplay<'_> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut hex = [0u8; 2];

        for &byte in self.0 {
            f.write_str(crate::lower::encode_str(&[byte], &mut hex)?)?;
        }

        Ok(())
    }
}