pub fn base64(len: Option<i64>) -> Result<String, Error>
Expand description
Generate a base64-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 base64 encode them.
§Examples
let bytes = spinoso_securerandom::base64(Some(1024))?;
assert_eq!(bytes.len(), 1368);
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
.