spinoso_securerandom

Function hex

Source
pub fn hex(len: Option<i64>) -> Result<String, Error>
Expand description

Generate a hex-encoded String of random bytes.

If len is Some and non-negative, generate a vector of len random bytes. If len is None, generate 16 random bytes. Take the resulting bytes and hexadecimal encode them.

§Examples

let bytes = spinoso_securerandom::hex(Some(1024))?;
assert_eq!(bytes.len(), 2048);
assert!(bytes.is_ascii());

§Errors

If the given length is negative, return an ArgumentError.

If the underlying source of randomness returns an error, return a RandomBytesError.