pub trait FromHexStr {
// Required method
fn try_from_hex(&self) -> Result<Vec<u8>, HexError>;
}Expand description
Extension trait for decoding hexadecimal strings into byte vectors.
Requires features encoding-hex and alloc.
Blanket-implemented for all AsRef<str> types. Returns Vec<u8> — requires heap
allocation. For no-alloc targets, use Fixed::try_from_hex instead, which decodes
directly into a stack-allocated [u8; N] buffer.
Treat all input as untrusted; validate lengths and content upstream before wrapping decoded bytes in secrets.
Required Methods§
Sourcefn try_from_hex(&self) -> Result<Vec<u8>, HexError>
fn try_from_hex(&self) -> Result<Vec<u8>, HexError>
Decodes a hexadecimal string into a byte vector.
Case-insensitive; rejects odd-length strings and invalid characters.
§Errors
HexError::InvalidHex— non-hex characters or odd-length input.
§Examples
use secure_gate::FromHexStr;
let bytes = "deadbeef".try_from_hex()?;
assert_eq!(bytes, [0xde, 0xad, 0xbe, 0xef]);
assert!("xyz!".try_from_hex().is_err()); // invalid chars
assert!("a".try_from_hex().is_err()); // odd length