byte_array_ops/security/display.rs
1//! Display and Debug implementations for ByteArray
2//!
3//! Formatting is restricted to prevent accidental data leakage
4
5use crate::model::ByteArray;
6use core::fmt::{Debug, Display, Formatter};
7
8impl Display for ByteArray {
9 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
10 #[cfg(debug_assertions)] // we show the data only when we are in debug releases
11 return self.bytes.fmt(f);
12 #[cfg(not(debug_assertions))]
13 // when in release mode we truncate and only show bytearray length
14 return write!(f, "ByteArray length: {}", self.len());
15 }
16}
17
18/// Debug implementation delegates to Display for consistent behavior
19impl Debug for ByteArray {
20 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
21 <ByteArray as Display>::fmt(self, f)
22 }
23}