base64_url/lib.rs
1/*!
2# Base64 URL
3
4Base64 encode, decode, escape and unescape for URL applications.
5
6## Examples
7
8Encode data to a Base64-URL string.
9
10```rust
11assert_eq!("SGVsbG8sIHdvcmxkIQ", base64_url::encode("Hello, world!"));
12```
13
14Decode a Base64-URL string to data.
15
16```rust
17assert_eq!(b"Hello, world!", base64_url::decode("SGVsbG8sIHdvcmxkIQ").unwrap().as_slice());
18```
19
20Escape 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.
21
22```rust
23assert_eq!("SGVsbG8sIHdvcmxkIQ", base64_url::escape("SGVsbG8sIHdvcmxkIQ=="));
24```
25
26Unescape a Base64-URL string to a Base64 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.
27
28```rust
29assert_eq!("SGVsbG8sIHdvcmxkIQ==", base64_url::unescape("SGVsbG8sIHdvcmxkIQ"));
30```
31
32Besides, you can also use other `encode_*`, `decode_*`, `escape_*`, `unescape_*` associated functions to deal with more specific cases. For example,
33
34```rust
35let hash = &[1, 2, 3, 4, 5, 6, 7, 8, 9];
36let mut url = String::from("https://example.com/?hash=");
37
38assert_eq!("AQIDBAUGBwgJ", base64_url::encode_to_string(hash, &mut url));
39assert_eq!("https://example.com/?hash=AQIDBAUGBwgJ", url);
40```
41
42## Std
43
44This crate is `no_std` compatible by default and only requires `alloc`.
45Enable the `std` feature to pass `std` support through to the `base64` dependency.
46
47```toml
48[dependencies.base64-url]
49version = "*"
50features = ["std"]
51```
52*/
53
54#![cfg_attr(not(feature = "std"), no_std)]
55
56extern crate alloc;
57
58pub extern crate base64;
59
60mod decode;
61mod encode;
62mod escape;
63mod unescape;
64
65pub use decode::*;
66pub use encode::*;
67pub use escape::*;
68pub use unescape::*;