Skip to main content

urlsafe_base64_encode

Function urlsafe_base64_encode 

Source
pub fn urlsafe_base64_encode(bytes: &[u8]) -> String
Expand description

Base64-encode bytes with the URL-safe alphabet and the = padding stripped, so the result drops into a URL path or query value with no escaping. Used for the uidb64 part of /reset/<uidb64>/<token>/.

ⓘ
use rustango::url_codec::urlsafe_base64_encode;
assert_eq!(urlsafe_base64_encode(b"foo"), "Zm9v");
assert_eq!(urlsafe_base64_encode(b""), "");
// Encodes characters that would need `%`-escape in standard b64:
// raw `+` → `-`, raw `/` → `_`.
assert_eq!(urlsafe_base64_encode(&[0xfb, 0xff]), "-_8");

Gated on _base64: only the two base64 helpers need an optional crate, so the rest of the module stays available in every feature set.