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
//! Security relevant features that need extra attention are bundled here for better maintainability

pub mod constant_time;
pub mod display;
pub mod vec;
pub mod zeroize;

#[cfg(test)]
mod security_tests {
    use super::super::*;

    #[test]
    fn test_extend_no_reallocate() {
        let other_bytes = bytes![0xff;200000];
        let bytes = bytes![0xff;1000000];
        let bytes_res = bytes.try_extend(other_bytes);
        assert!(bytes_res.is_ok()); // no insecure reallocation happened
        let bytes = bytes_res.unwrap();

        assert_eq!(bytes.bytes.capacity(), 1200010);
    }

    #[test]
    fn test_extend_no_reallocate_large_cap() {
        let other_bytes = ByteArray::with_capacity(1024);
        let bytes = bytes![0xff;1000000];
        let bytes_res = bytes.try_extend_with_preserve_cap(other_bytes);
        assert!(bytes_res.is_ok()); // no insecure reallocation happened

        let bytes = bytes_res.unwrap();
        assert_eq!(bytes.bytes.capacity(), 1001034);
        assert_eq!(bytes.bytes.len(), 1000000);
    }
}