Skip to main content

FromBase64UrlStr

Trait FromBase64UrlStr 

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

Source

fn try_from_base64url(&self) -> Result<Vec<u8>, Base64Error>

Decodes a URL-safe base64 string (no padding) into a byte vector.

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

Implementors§

Source§

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

Available on crate features encoding-base64 and alloc only.