Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magiclen/base64-url
Base64 encode, decode, escape and unescape for URL applications.
https://github.com/magiclen/base64-url
base64 base64-url rust
Last synced: 28 days ago
JSON representation
Base64 encode, decode, escape and unescape for URL applications.
- Host: GitHub
- URL: https://github.com/magiclen/base64-url
- Owner: magiclen
- License: mit
- Created: 2018-08-25T09:40:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-01T13:21:05.000Z (8 months ago)
- Last Synced: 2024-11-20T08:15:00.315Z (about 1 month ago)
- Topics: base64, base64-url, rust
- Language: Rust
- Homepage:
- Size: 43.9 KB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Base64 URL
====================[![CI](https://github.com/magiclen/base64-url/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/base64-url/actions/workflows/ci.yml)
Base64 encode, decode, escape and unescape for URL applications.
## Examples
Encode data to a Base64-URL string.
```rust
assert_eq!("SGVsbG8sIHdvcmxkIQ", base64_url::encode("Hello, world!"));
```Decode a Base64-URL string to data.
```rust
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.
```rust
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.
```rust
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,
```rust
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.
```toml
[dependencies.base64-url]
version = "*"
default-features = false
```## Crates.io
https://crates.io/crates/base64-url
## Documentation
https://docs.rs/base64-url
## License
[MIT](LICENSE)