Skip to content

Commit 59549dd

Browse files
wathiedeia0
andauthored
Add BASE64_MIME_PERMISSIVE to ignore trailing bits (#103)
Fixes #102 --------- Co-authored-by: Julien Cretin <[email protected]>
1 parent 978bc8c commit 59549dd

File tree

11 files changed

+92
-27
lines changed

11 files changed

+92
-27
lines changed

bin/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "data-encoding-bin"
3-
version = "0.3.3"
3+
version = "0.3.4-git"
44
authors = ["Julien Cretin <[email protected]>"]
55
license = "MIT"
66
edition = "2021"
@@ -16,5 +16,5 @@ name = "data-encoding"
1616
path = "src/main.rs"
1717

1818
[dependencies]
19-
data-encoding = { version = "2.5.0", path = "../lib" }
19+
data-encoding = { version = "2.6.0-git", path = "../lib" }
2020
getopts = "0.2"

lib/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2.6.0-git
4+
5+
### Minor
6+
7+
- Add `BASE64_MIME_PERMISSIVE` constant to ignore trailing bits (fixes #102)
8+
39
## 2.5.0
410

511
### Minor

lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "data-encoding"
3-
version = "2.5.0"
3+
version = "2.6.0-git"
44
authors = ["Julien Cretin <[email protected]>"]
55
license = "MIT"
66
edition = "2018"

lib/README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33

44
This library provides the following common encodings:
55

6-
| Name | Description |
7-
| --- | --- |
8-
| `HEXLOWER` | lowercase hexadecimal |
9-
| `HEXLOWER_PERMISSIVE` | lowercase hexadecimal (case-insensitive decoding) |
10-
| `HEXUPPER` | uppercase hexadecimal |
11-
| `HEXUPPER_PERMISSIVE` | uppercase hexadecimal (case-insensitive decoding) |
12-
| `BASE32` | RFC4648 base32 |
13-
| `BASE32_NOPAD` | RFC4648 base32 (no padding) |
14-
| `BASE32_DNSSEC` | RFC5155 base32 |
15-
| `BASE32_DNSCURVE` | DNSCurve base32 |
16-
| `BASE32HEX` | RFC4648 base32hex |
17-
| `BASE32HEX_NOPAD` | RFC4648 base32hex (no padding) |
18-
| `BASE64` | RFC4648 base64 |
19-
| `BASE64_NOPAD` | RFC4648 base64 (no padding) |
20-
| `BASE64_MIME` | RFC2045-like base64 |
21-
| `BASE64URL` | RFC4648 base64url |
22-
| `BASE64URL_NOPAD` | RFC4648 base64url (no padding) |
6+
| Name | Description |
7+
|--------------------------|---------------------------------------------------|
8+
| `HEXLOWER` | lowercase hexadecimal |
9+
| `HEXLOWER_PERMISSIVE` | lowercase hexadecimal (case-insensitive decoding) |
10+
| `HEXUPPER` | uppercase hexadecimal |
11+
| `HEXUPPER_PERMISSIVE` | uppercase hexadecimal (case-insensitive decoding) |
12+
| `BASE32` | RFC4648 base32 |
13+
| `BASE32_NOPAD` | RFC4648 base32 (no padding) |
14+
| `BASE32_DNSSEC` | RFC5155 base32 |
15+
| `BASE32_DNSCURVE` | DNSCurve base32 |
16+
| `BASE32HEX` | RFC4648 base32hex |
17+
| `BASE32HEX_NOPAD` | RFC4648 base32hex (no padding) |
18+
| `BASE64` | RFC4648 base64 |
19+
| `BASE64_NOPAD` | RFC4648 base64 (no padding) |
20+
| `BASE64_MIME` | RFC2045-like base64 |
21+
| `BASE64_MIME_PERMISSIVE` | RFC2045-like base64 (ignoring trailing bits) |
22+
| `BASE64URL` | RFC4648 base64url |
23+
| `BASE64URL_NOPAD` | RFC4648 base64url (no padding) |
2324

2425
It also provides the possibility to define custom little-endian ASCII
2526
base-conversion encodings for bases of size 2, 4, 8, 16, 32, and 64 (for which

lib/macro/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "data-encoding-macro"
3-
version = "0.1.14"
3+
version = "0.1.15-git"
44
authors = ["Julien Cretin <[email protected]>"]
55
license = "MIT"
66
edition = "2018"
@@ -14,5 +14,5 @@ description = "Macros for data-encoding"
1414
include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
1515

1616
[dependencies]
17-
data-encoding = { version = "2.5.0", path = "..", default-features = false }
18-
data-encoding-macro-internal = { version = "0.1.12", path = "internal" }
17+
data-encoding = { version = "2.6.0-git", path = "..", default-features = false }
18+
data-encoding-macro-internal = { version = "0.1.13-git", path = "internal" }

lib/macro/internal/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "data-encoding-macro-internal"
3-
version = "0.1.12"
3+
version = "0.1.13-git"
44
authors = ["Julien Cretin <[email protected]>"]
55
license = "MIT"
66
edition = "2018"
@@ -14,7 +14,7 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
1414
proc-macro = true
1515

1616
[dependencies.data-encoding]
17-
version = "2.5.0"
17+
version = "2.6.0-git"
1818
path = "../.."
1919
default-features = false
2020
features = ["alloc"]

lib/macro/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ make! {
246246
wrap_width: 76,
247247
wrap_separator: "\r\n",
248248
}
249+
make! {
250+
base64_mime_permissive base64_mime_permissive_array = BASE64_MIME_PERMISSIVE;
251+
symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
252+
padding: '=',
253+
wrap_width: 76,
254+
wrap_separator: "\r\n",
255+
check_trailing_bits: false,
256+
}
249257
make! {
250258
base64url base64url_array = BASE64URL;
251259
symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",

lib/src/lib.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ const BASE64_NOPAD_IMPL: &[u8] = &[
23872387
/// This encoding is a static version of:
23882388
///
23892389
/// ```rust
2390-
/// # use data_encoding::{Specification, Wrap, BASE64_MIME};
2390+
/// # use data_encoding::{Specification, BASE64_MIME};
23912391
/// let mut spec = Specification::new();
23922392
/// spec.symbols.push_str("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
23932393
/// spec.padding = Some('=');
@@ -2429,6 +2429,54 @@ const BASE64_MIME_IMPL: &[u8] = &[
24292429
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 61, 30, 76, 13, 10,
24302430
];
24312431

2432+
/// MIME base64 encoding without trailing bits check
2433+
///
2434+
/// This encoding is a static version of:
2435+
///
2436+
/// ```rust
2437+
/// # use data_encoding::{Specification, BASE64_MIME_PERMISSIVE};
2438+
/// let mut spec = Specification::new();
2439+
/// spec.symbols.push_str("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
2440+
/// spec.padding = Some('=');
2441+
/// spec.wrap.width = 76;
2442+
/// spec.wrap.separator.push_str("\r\n");
2443+
/// spec.check_trailing_bits = false;
2444+
/// assert_eq!(BASE64_MIME_PERMISSIVE, spec.encoding().unwrap());
2445+
/// ```
2446+
///
2447+
/// It does not exactly conform to [RFC2045] because it does not print the header
2448+
/// and does not ignore all characters.
2449+
///
2450+
/// [RFC2045]: https://tools.ietf.org/html/rfc2045
2451+
pub const BASE64_MIME_PERMISSIVE: Encoding = Encoding::internal_new(BASE64_MIME_PERMISSIVE_IMPL);
2452+
const BASE64_MIME_PERMISSIVE_IMPL: &[u8] = &[
2453+
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
2454+
89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
2455+
115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 65, 66,
2456+
67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
2457+
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
2458+
116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 65, 66, 67,
2459+
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97,
2460+
98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
2461+
117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 65, 66, 67, 68,
2462+
69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98,
2463+
99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
2464+
118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 128, 128, 128, 128,
2465+
128, 128, 128, 128, 128, 128, 129, 128, 128, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2466+
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2467+
128, 62, 128, 128, 128, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 128, 128, 128, 130, 128,
2468+
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,
2469+
24, 25, 128, 128, 128, 128, 128, 128, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
2470+
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2471+
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2472+
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2473+
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2474+
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2475+
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2476+
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
2477+
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 61, 14, 76, 13, 10,
2478+
];
2479+
24322480
/// Padded base64url encoding
24332481
///
24342482
/// This encoding is a static version of:

lib/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ fn round_trip() {
412412
test(data_encoding::BASE64);
413413
test(data_encoding::BASE64_NOPAD);
414414
test(data_encoding::BASE64_MIME);
415+
test(data_encoding::BASE64_MIME_PERMISSIVE);
415416
test(data_encoding::BASE64URL);
416417
test(data_encoding::BASE64URL_NOPAD);
417418
}

www/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ publish = false
1212
crate-type = ["cdylib"]
1313

1414
[dependencies]
15-
data-encoding = "2"
15+
data-encoding = { path = "../lib" }
1616
lazy_static = "1"
1717
wasm-bindgen = "0.2"
1818

www/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ lazy_static! {
6363
add!(BASE64URL);
6464
add!(BASE64URL_NOPAD);
6565
add!(BASE64_MIME);
66+
add!(BASE64_MIME_PERMISSIVE);
6667
add!(BASE64_NOPAD);
6768
add!(HEXLOWER);
6869
add!(HEXLOWER_PERMISSIVE);

0 commit comments

Comments
 (0)