liminal-server 0.28.7

Standalone server for the liminal messaging bus
Documentation
//! Credential bytes shown by their length (LIM-010 R1, PROTO-007).

/// Bytes whose `Debug` is their length and never a byte.
///
/// A type holding a credential writes its `Debug` by hand and shows each
/// credential field through this, or holds the field in it.
#[derive(Clone, PartialEq, Eq)]
pub struct Redacted<T>(pub T);

impl<T: AsRef<[u8]>> core::fmt::Debug for Redacted<T> {
    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(formatter, "Redacted({} bytes)", self.0.as_ref().len())
    }
}

#[cfg(test)]
mod tests {
    use super::Redacted;
    use crate::credential_debug_tests::{shows_none_of, token_shaped};

    #[test]
    fn redacted_debug_shows_the_length_and_no_byte() {
        let bytes = token_shaped::<32>(32);
        assert_eq!(format!("{:?}", Redacted(bytes)), "Redacted(32 bytes)");
        shows_none_of(&Redacted(bytes), &bytes);
        shows_none_of(&Redacted(bytes.to_vec()), &bytes);
    }
}