pub trait FromBase64UrlStr {
// Required method
fn try_from_base64url(&self) -> Result<Vec<u8>, Base64Error>;
}Expand description
Extension trait for decoding URL-safe base64 strings into byte vectors.
Requires features encoding-base64 and alloc.
Blanket-implemented for all AsRef<str> types. Returns Vec<u8> — requires heap
allocation. For no-alloc targets, use Fixed::try_from_base64url instead, which
decodes directly into a stack-allocated [u8; N] buffer.
Uses the RFC 4648 URL-safe alphabet without = padding. Treat all input as
untrusted; validate lengths and content upstream before wrapping decoded bytes
in secrets.
Required Methods§
Sourcefn try_from_base64url(&self) -> Result<Vec<u8>, Base64Error>
fn try_from_base64url(&self) -> Result<Vec<u8>, Base64Error>
Decodes a URL-safe base64 string (no padding) into a byte vector.
§Errors
Base64Error::InvalidBase64— invalid characters or unexpected padding.
§Examples
use secure_gate::FromBase64UrlStr;
// "AQIDBA" decodes to [1, 2, 3, 4]
let bytes = "AQIDBA".try_from_base64url()?;
assert_eq!(bytes, [1, 2, 3, 4]);
assert!("!!!".try_from_base64url().is_err()); // invalid chars