Expand description
Hexadecimal decoding trait.
Import path:
use secure_gate::FromHexStr;
This trait provides secure, explicit decoding of hexadecimal strings to byte vectors. It is designed for handling untrusted input in cryptographic contexts, such as decoding hex-encoded keys or nonces.
Requires the encoding-hex feature.
§Security Notes
- Treat all input as untrusted: validate hex strings upstream before wrapping in secrets. Invalid hex may indicate tampering or injection attempts.
- Heap allocation: Returns
Vec<u8>— wrap inFixedorDynamicto store as a secret. - Case-insensitive: Accepts both uppercase and lowercase hex digits.
§Example
use secure_gate::{FromHexStr, Fixed};
{
let bytes = "01234567".try_from_hex().unwrap();
assert_eq!(bytes, vec![0x01, 0x23, 0x45, 0x67]);
// Wrap result in a secret immediately
let secret: Fixed<[u8; 4]> = Fixed::try_from_hex("deadbeef").unwrap();
// Error on invalid input
assert!("xyz!".try_from_hex().is_err());
}Traits§
- From
HexStr - Extension trait for decoding hexadecimal strings into byte vectors.