Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BASE64_MIME_PERMISSIVE to ignore trailing bits #103

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "data-encoding-bin"
version = "0.3.3"
version = "0.3.4-git"
authors = ["Julien Cretin <git@ia0.eu>"]
license = "MIT"
edition = "2021"
Expand All @@ -16,5 +16,5 @@ name = "data-encoding"
path = "src/main.rs"

[dependencies]
data-encoding = { version = "2.5.0", path = "../lib" }
data-encoding = { version = "2.6.0-git", path = "../lib" }
getopts = "0.2"
6 changes: 6 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.6.0-git

### Minor

- Add `BASE64_MIME_PERMISSIVE` constant to ignore trailing bits (fixes #102)

## 2.5.0

### Minor
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "data-encoding"
version = "2.5.0"
version = "2.6.0-git"
authors = ["Julien Cretin <git@ia0.eu>"]
license = "MIT"
edition = "2018"
Expand Down
35 changes: 18 additions & 17 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

This library provides the following common encodings:

| Name | Description |
| --- | --- |
| `HEXLOWER` | lowercase hexadecimal |
| `HEXLOWER_PERMISSIVE` | lowercase hexadecimal (case-insensitive decoding) |
| `HEXUPPER` | uppercase hexadecimal |
| `HEXUPPER_PERMISSIVE` | uppercase hexadecimal (case-insensitive decoding) |
| `BASE32` | RFC4648 base32 |
| `BASE32_NOPAD` | RFC4648 base32 (no padding) |
| `BASE32_DNSSEC` | RFC5155 base32 |
| `BASE32_DNSCURVE` | DNSCurve base32 |
| `BASE32HEX` | RFC4648 base32hex |
| `BASE32HEX_NOPAD` | RFC4648 base32hex (no padding) |
| `BASE64` | RFC4648 base64 |
| `BASE64_NOPAD` | RFC4648 base64 (no padding) |
| `BASE64_MIME` | RFC2045-like base64 |
| `BASE64URL` | RFC4648 base64url |
| `BASE64URL_NOPAD` | RFC4648 base64url (no padding) |
| Name | Description |
|--------------------------|---------------------------------------------------|
| `HEXLOWER` | lowercase hexadecimal |
| `HEXLOWER_PERMISSIVE` | lowercase hexadecimal (case-insensitive decoding) |
| `HEXUPPER` | uppercase hexadecimal |
| `HEXUPPER_PERMISSIVE` | uppercase hexadecimal (case-insensitive decoding) |
| `BASE32` | RFC4648 base32 |
| `BASE32_NOPAD` | RFC4648 base32 (no padding) |
| `BASE32_DNSSEC` | RFC5155 base32 |
| `BASE32_DNSCURVE` | DNSCurve base32 |
| `BASE32HEX` | RFC4648 base32hex |
| `BASE32HEX_NOPAD` | RFC4648 base32hex (no padding) |
| `BASE64` | RFC4648 base64 |
| `BASE64_NOPAD` | RFC4648 base64 (no padding) |
| `BASE64_MIME` | RFC2045-like base64 |
| `BASE64_MIME_PERMISSIVE` | RFC2045-like base64 (ignoring trailing bits) |
| `BASE64URL` | RFC4648 base64url |
| `BASE64URL_NOPAD` | RFC4648 base64url (no padding) |

It also provides the possibility to define custom little-endian ASCII
base-conversion encodings for bases of size 2, 4, 8, 16, 32, and 64 (for which
Expand Down
6 changes: 3 additions & 3 deletions lib/macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "data-encoding-macro"
version = "0.1.14"
version = "0.1.15-git"
authors = ["Julien Cretin <cretin@google.com>"]
license = "MIT"
edition = "2018"
Expand All @@ -14,5 +14,5 @@ description = "Macros for data-encoding"
include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]

[dependencies]
data-encoding = { version = "2.5.0", path = "..", default-features = false }
data-encoding-macro-internal = { version = "0.1.12", path = "internal" }
data-encoding = { version = "2.6.0-git", path = "..", default-features = false }
data-encoding-macro-internal = { version = "0.1.13-git", path = "internal" }
4 changes: 2 additions & 2 deletions lib/macro/internal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "data-encoding-macro-internal"
version = "0.1.12"
version = "0.1.13-git"
authors = ["Julien Cretin <cretin@google.com>"]
license = "MIT"
edition = "2018"
Expand All @@ -14,7 +14,7 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
proc-macro = true

[dependencies.data-encoding]
version = "2.5.0"
version = "2.6.0-git"
path = "../.."
default-features = false
features = ["alloc"]
Expand Down
8 changes: 8 additions & 0 deletions lib/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ make! {
wrap_width: 76,
wrap_separator: "\r\n",
}
make! {
base64_mime_permissive base64_mime_permissive_array = BASE64_MIME_PERMISSIVE;
symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
padding: '=',
wrap_width: 76,
wrap_separator: "\r\n",
check_trailing_bits: false,
}
make! {
base64url base64url_array = BASE64URL;
symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
Expand Down
50 changes: 49 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,7 @@ const BASE64_NOPAD_IMPL: &[u8] = &[
/// This encoding is a static version of:
///
/// ```rust
/// # use data_encoding::{Specification, Wrap, BASE64_MIME};
/// # use data_encoding::{Specification, BASE64_MIME};
/// let mut spec = Specification::new();
/// spec.symbols.push_str("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
/// spec.padding = Some('=');
Expand Down Expand Up @@ -2429,6 +2429,54 @@ const BASE64_MIME_IMPL: &[u8] = &[
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 61, 30, 76, 13, 10,
];

/// MIME base64 encoding without trailing bits check
///
/// This encoding is a static version of:
///
/// ```rust
/// # use data_encoding::{Specification, BASE64_MIME_PERMISSIVE};
/// let mut spec = Specification::new();
/// spec.symbols.push_str("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
/// spec.padding = Some('=');
/// spec.wrap.width = 76;
/// spec.wrap.separator.push_str("\r\n");
/// spec.check_trailing_bits = false;
/// assert_eq!(BASE64_MIME_PERMISSIVE, spec.encoding().unwrap());
/// ```
///
/// It does not exactly conform to [RFC2045] because it does not print the header
/// and does not ignore all characters.
///
/// [RFC2045]: https://tools.ietf.org/html/rfc2045
pub const BASE64_MIME_PERMISSIVE: Encoding = Encoding::internal_new(BASE64_MIME_PERMISSIVE_IMPL);
const BASE64_MIME_PERMISSIVE_IMPL: &[u8] = &[
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 65, 66, 67, 68,
69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98,
99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 129, 128, 128, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 62, 128, 128, 128, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 128, 128, 128, 130, 128,
128, 128, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 128, 128, 128, 128, 128, 128, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 61, 14, 76, 13, 10,
];

/// Padded base64url encoding
///
/// This encoding is a static version of:
Expand Down
1 change: 1 addition & 0 deletions lib/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ fn round_trip() {
test(data_encoding::BASE64);
test(data_encoding::BASE64_NOPAD);
test(data_encoding::BASE64_MIME);
test(data_encoding::BASE64_MIME_PERMISSIVE);
test(data_encoding::BASE64URL);
test(data_encoding::BASE64URL_NOPAD);
}
Expand Down
2 changes: 1 addition & 1 deletion www/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
data-encoding = "2"
data-encoding = { path = "../lib" }
lazy_static = "1"
wasm-bindgen = "0.2"

Expand Down
1 change: 1 addition & 0 deletions www/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ lazy_static! {
add!(BASE64URL);
add!(BASE64URL_NOPAD);
add!(BASE64_MIME);
add!(BASE64_MIME_PERMISSIVE);
add!(BASE64_NOPAD);
add!(HEXLOWER);
add!(HEXLOWER_PERMISSIVE);
Expand Down