#decode-base64 #base64 #url #encode-decode #decode #encode #utf-8

no-std base64-url

Base64 encode, decode, escape and unescape for URL applications

31 stable releases

2.0.2 Dec 24, 2023
2.0.1 Nov 26, 2023
2.0.0 Mar 14, 2023
1.4.13 Mar 5, 2022
1.1.7 Nov 16, 2018

#124 in Encoding

Download history 47035/week @ 2023-12-12 37408/week @ 2023-12-19 22915/week @ 2023-12-26 49397/week @ 2024-01-02 53676/week @ 2024-01-09 64393/week @ 2024-01-16 63232/week @ 2024-01-23 68551/week @ 2024-01-30 57338/week @ 2024-02-06 57922/week @ 2024-02-13 67485/week @ 2024-02-20 68306/week @ 2024-02-27 64679/week @ 2024-03-05 60848/week @ 2024-03-12 64381/week @ 2024-03-19 52351/week @ 2024-03-26

252,371 downloads per month
Used in 108 crates (30 directly)

MIT license

21KB
347 lines

Base64 URL

CI

Base64 encode, decode, escape and unescape for URL applications.

Examples

Encode data to a Base64-URL string.

assert_eq!("SGVsbG8sIHdvcmxkIQ", base64_url::encode("Hello, world!"));

Decode a Base64-URL string to data.

assert_eq!(b"Hello, world!", base64_url::decode("SGVsbG8sIHdvcmxkIQ").unwrap().as_slice());

Escape a Base64 string to a Base64-URL string. The conversion is not concerning with Base64 decoding. You need to make sure the input string is a correct Base64 string by yourself.

assert_eq!("SGVsbG8sIHdvcmxkIQ", base64_url::escape("SGVsbG8sIHdvcmxkIQ=="));

Unescape a Base64-URL string to a Base64-URL string. The conversion is not concerning with Base64 decoding. You need to make sure the input string is a correct Base64-URL string by yourself.

assert_eq!("SGVsbG8sIHdvcmxkIQ==", base64_url::unescape("SGVsbG8sIHdvcmxkIQ"));

Besides, you can also use other encode_*, decode_*, escape_*, unescape_* associated functions to deal with more specific cases. For example,

let hash = &[1, 2, 3, 4, 5, 6, 7, 8, 9];
let mut url = String::from("https://example.com/?hash=");

assert_eq!("AQIDBAUGBwgJ", base64_url::encode_to_string(hash, &mut url));
assert_eq!("https://example.com/?hash=AQIDBAUGBwgJ", url);

No Std

Disable the default features to compile this crate without std.

[dependencies.base64-url]
version = "*"
default-features = false

Crates.io

https://crates.io/crates/base64-url

Documentation

https://docs.rs/base64-url

License

MIT

Dependencies

~220KB