Crates.io | base64-url |
lib.rs | base64-url |
version | 3.0.0 |
source | src |
created_at | 2018-08-25 09:44:33.778 |
updated_at | 2024-05-01 13:17:04.141505 |
description | Base64 encode, decode, escape and unescape for URL applications. |
homepage | https://magiclen.org/base64-url |
repository | https://github.com/magiclen/base64-url |
max_upload_size | |
id | 81227 |
size | 21,842 |
Base64 encode, decode, escape and unescape for URL applications.
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);
Disable the default features to compile this crate without std.
[dependencies.base64-url]
version = "*"
default-features = false
https://crates.io/crates/base64-url