pub struct HexString(/* private fields */);Expand description
Validated, lowercase hex string wrapper for secret data.
This struct ensures the contained string is valid hex (even length, valid chars). Provides methods for decoding back to bytes.
The string is normalized to lowercase during validation.
§Examples
let valid = HexString::new("deadbeef".to_string()).unwrap();
assert_eq!(valid.expose_secret(), "deadbeef");
let bytes = valid.into_bytes(); // Vec<u8> of [0xde, 0xad, 0xbe, 0xef]Implementations§
Source§impl HexString
impl HexString
Sourcepub fn new(s: String) -> Result<Self, &'static str>
pub fn new(s: String) -> Result<Self, &'static str>
Create a new HexString from a String, validating it in-place.
The input String is consumed.
§Security Note
Invalid inputs are only securely zeroized if the zeroize feature is enabled.
Without zeroize, rejected bytes may remain in memory until the String is dropped
normally. Enable the zeroize feature for secure wiping of invalid inputs.
Validation rules:
- Even length
- Only ASCII hex digits (
0-9,a-f,A-F) - Uppercase letters are normalized to lowercase
Zero extra allocations are performed – everything happens on the original buffer.
§Errors
Returns Err("invalid hex string") if validation fails.
§Example
use secure_gate::encoding::hex::HexString;
let valid = HexString::new("deadbeef".to_string()).unwrap();
assert_eq!(valid.expose_secret(), "deadbeef");Source§impl HexString
impl HexString
pub fn expose_secret(&self) -> HexStringView<'_>
Trait Implementations§
Source§impl PartialEq for HexString
Available on crate feature ct-eq only.Constant-time equality for hex strings — prevents timing attacks when ct-eq feature is enabled.
impl PartialEq for HexString
ct-eq only.Constant-time equality for hex strings — prevents timing attacks when ct-eq feature is enabled.
impl Eq for HexString
Equality implementation for hex strings.