Skip to main content

FromHexStr

Trait FromHexStr 

Source
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 feature encoding-hex.

Blanket-implemented for all AsRef<str> types. Treat all input as untrusted; validate lengths and content upstream before wrapping decoded bytes in secrets.

Required Methods§

Source

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
§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

Implementors§

Source§

impl<T: AsRef<str> + ?Sized> FromHexStr for T

Available on crate feature encoding-hex only.