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-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.
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## No Std
43
44Disable the default features to compile this crate without std.
45
46```toml
47[dependencies.base64-url]
48version = "*"
49default-features = false
50```
51*/
52
53#![cfg_attr(not(feature = "std"), no_std)]
54
55extern crate alloc;
56
57pub extern crate base64;
58
59mod decode;
60mod encode;
61mod escape;
62mod unescape;
63
64pub use decode::*;
65pub use encode::*;
66pub use escape::*;
67pub use unescape::*;