Skip to content

Commit 3fd648f

Browse files
authored
Add v3-preview back to its own crate (#139)
This is the follow-up of #120.
1 parent 4fce77c commit 3fd648f

File tree

8 files changed

+3681
-7
lines changed

8 files changed

+3681
-7
lines changed

lib/v3/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
## 0.1.0

lib/v3/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "data-encoding-v3"
3+
version = "0.1.0"
4+
authors = ["Julien Cretin <[email protected]>"]
5+
license = "MIT"
6+
edition = "2024"
7+
rust-version = "1.85"
8+
keywords = ["no_std", "base64", "base32", "hex"]
9+
categories = ["encoding", "no-std"]
10+
readme = "README.md"
11+
repository = "https://github.com/ia0/data-encoding"
12+
documentation = "https://docs.rs/data-encoding"
13+
description = "Development branch of data-encoding 3.0.0"
14+
include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
15+
16+
# TODO(https://github.com/rust-lang/rust/issues/43781): Remove this once doc_auto_cfg is in the MSRV.
17+
[package.metadata.docs.rs]
18+
rustdoc-args = ["--cfg=docsrs"]
19+
20+
[features]
21+
default = ["std"]
22+
alloc = []
23+
std = ["alloc"]
24+
25+
[lints]
26+
rust.elided-lifetimes-in-paths = "warn"
27+
rust.let-underscore-drop = "warn"
28+
rust.missing-debug-implementations = "warn"
29+
rust.missing-docs = "warn"
30+
rust.unreachable-pub = "warn"
31+
rust.unused-results = "warn"
32+
clippy.pedantic = { level = "warn", priority = -1 }
33+
clippy.assigning-clones = "allow"
34+
clippy.doc-markdown = "allow"
35+
clippy.enum-glob-use = "allow"
36+
clippy.match-bool = "allow"
37+
clippy.semicolon-if-nothing-returned = "allow"
38+
clippy.similar-names = "allow"

lib/v3/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE

lib/v3/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:warning: It is strongly **discouraged** to use this crate _at this time_. There are no guarantees
2+
whatsoever (correctness, stability, documentation, etc). This warning will be updated as new
3+
versions are published.
4+
5+
This crate is the development branch of `[email protected]`. It is provided as a workaround to the
6+
[Cargo pre-release issues](https://github.com/rust-lang/cargo/issues/2222#issuecomment-2509149376).
7+
It will obey the following rules:
8+
- The initial version is `[email protected]`
9+
- The final version is `[email protected]`
10+
- Version `[email protected]` represents `[email protected]`
11+
- Version `[email protected]` corresponds to `[email protected]`
12+
- Only the final version will be published to `data-encoding`
13+
14+
In particular, the `data-encoding` crate won't have any `3.0.0` pre-release version. This crate
15+
should be used instead. To minimize code changes (v3 won't break simple usages of v2), you can
16+
modify your `Cargo.toml` from using `data-encoding`:
17+
18+
```toml
19+
[dependencies]
20+
data-encoding = "2.9.0"
21+
```
22+
23+
to using `data-encoding-v3` while preserving the crate name:
24+
25+
```toml
26+
[dependencies]
27+
data-encoding = { package = "data-encoding-v3", version = "0.1.0" }
28+
```
29+
30+
When `data-encoding-v3` reaches `1.0.0`, then `data-encoding` will reach `3.0.0` too, and the
31+
`Cargo.toml` should use `data-encoding` again:
32+
33+
```toml
34+
[dependencies]
35+
data-encoding = "3.0.0"
36+
```

lib/v3/benches/lib.rs

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#![feature(test)]
2+
#![allow(missing_docs)]
3+
4+
extern crate test;
5+
6+
use data_encoding_v3 as constants;
7+
use data_encoding_v3::{Bit1, Bit2, Bit3, Bit6, Encoding, False, Specification, True};
8+
use test::Bencher;
9+
10+
#[bench]
11+
fn base02_encode_base(b: &mut Bencher) {
12+
let input = &[0u8; 4096];
13+
let output = &mut [0u8; 32768];
14+
let mut spec = Specification::new();
15+
spec.symbols.push_str("01");
16+
let base = spec.encoding().unwrap();
17+
let base = Encoding::<Bit1, True, False, False, False>::try_from(base).unwrap();
18+
b.iter(|| base.encode_mut(input, output));
19+
}
20+
21+
#[bench]
22+
fn base02_decode_base(b: &mut Bencher) {
23+
let input = &[b'0'; 4096];
24+
let output = &mut [0u8; 512];
25+
let mut spec = Specification::new();
26+
spec.symbols.push_str("01");
27+
let base = spec.encoding().unwrap();
28+
let base = Encoding::<Bit1, True, False, False, False>::try_from(base).unwrap();
29+
b.iter(|| base.decode_mut(input, output));
30+
}
31+
32+
#[bench]
33+
fn base04_encode_base(b: &mut Bencher) {
34+
let input = &[0u8; 4096];
35+
let output = &mut [0u8; 16384];
36+
let mut spec = Specification::new();
37+
spec.symbols.push_str("0123");
38+
let base = spec.encoding().unwrap();
39+
let base = Encoding::<Bit2, True, False, False, False>::try_from(base).unwrap();
40+
b.iter(|| base.encode_mut(input, output));
41+
}
42+
43+
#[bench]
44+
fn base04_decode_base(b: &mut Bencher) {
45+
let input = &[b'0'; 4096];
46+
let output = &mut [0u8; 1024];
47+
let mut spec = Specification::new();
48+
spec.symbols.push_str("0123");
49+
let base = spec.encoding().unwrap();
50+
let base = Encoding::<Bit2, True, False, False, False>::try_from(base).unwrap();
51+
b.iter(|| base.decode_mut(input, output));
52+
}
53+
54+
#[bench]
55+
fn base08_encode_base(b: &mut Bencher) {
56+
let input = &[0u8; 4096];
57+
let output = &mut [0u8; 10923];
58+
let mut spec = Specification::new();
59+
spec.symbols.push_str("01234567");
60+
let base = spec.encoding().unwrap();
61+
let base = Encoding::<Bit3, True, False, False, False>::try_from(base).unwrap();
62+
b.iter(|| base.encode_mut(input, output));
63+
}
64+
65+
#[bench]
66+
fn base08_decode_base(b: &mut Bencher) {
67+
let input = &[b'0'; 4096];
68+
let output = &mut [0u8; 1536];
69+
let mut spec = Specification::new();
70+
spec.symbols.push_str("01234567");
71+
let base = spec.encoding().unwrap();
72+
let base = Encoding::<Bit3, True, False, False, False>::try_from(base).unwrap();
73+
b.iter(|| base.decode_mut(input, output));
74+
}
75+
76+
#[bench]
77+
fn base16_encode_base(b: &mut Bencher) {
78+
let input = &[0u8; 4096];
79+
let output = &mut [0u8; 8192];
80+
b.iter(|| constants::HEXLOWER.encode_mut(input, output));
81+
}
82+
83+
#[bench]
84+
fn base16_decode_base(b: &mut Bencher) {
85+
let input = &[b'0'; 4096];
86+
let output = &mut [0u8; 2048];
87+
b.iter(|| constants::HEXLOWER.decode_mut(input, output));
88+
}
89+
90+
#[bench]
91+
fn base32_encode_base(b: &mut Bencher) {
92+
let input = &[0u8; 4096];
93+
let output = &mut [0u8; 6560];
94+
b.iter(|| constants::BASE32.encode_mut(input, output));
95+
}
96+
97+
#[bench]
98+
fn base32_decode_base(b: &mut Bencher) {
99+
let input = &[b'A'; 4096];
100+
let output = &mut [0u8; 2560];
101+
b.iter(|| constants::BASE32.decode_mut(input, output));
102+
}
103+
104+
#[bench]
105+
fn base64_encode_base(b: &mut Bencher) {
106+
let input = &[0u8; 4096];
107+
let output = &mut [0u8; 5462];
108+
b.iter(|| constants::BASE64_NOPAD.encode_mut(input, output));
109+
}
110+
111+
#[bench]
112+
fn base64_decode_base(b: &mut Bencher) {
113+
let input = &[b'A'; 4096];
114+
let output = &mut [0u8; 3072];
115+
b.iter(|| constants::BASE64_NOPAD.decode_mut(input, output));
116+
}
117+
118+
#[bench]
119+
fn base64_encode_pad(b: &mut Bencher) {
120+
let input = &mut [b'A'; 4096];
121+
let output = &mut [0u8; 5464];
122+
b.iter(|| constants::BASE64.encode_mut(input, output));
123+
}
124+
125+
#[bench]
126+
fn base64_decode_pad(b: &mut Bencher) {
127+
let input = &mut [b'A'; 4096];
128+
for i in 0 .. 20 {
129+
let x = 4096 * i / 20 / 4 * 4;
130+
input[x + 3] = b'=';
131+
if i % 2 == 0 {
132+
input[x + 2] = b'=';
133+
}
134+
}
135+
let output = &mut [0u8; 3072];
136+
b.iter(|| constants::BASE64.decode_mut(input, output).unwrap());
137+
}
138+
139+
#[bench]
140+
fn base64_encode_wrap(b: &mut Bencher) {
141+
let input = &[0u8; 4096];
142+
let output = &mut [0u8; 5608];
143+
let mut spec = constants::BASE64.specification();
144+
spec.wrap.width = 76;
145+
spec.wrap.separator.push_str("\r\n");
146+
let base64 = spec.encoding().unwrap();
147+
let base64 = Encoding::<Bit6, True, True, True, True>::try_from(base64).unwrap();
148+
b.iter(|| base64.encode_mut(input, output));
149+
}
150+
151+
#[bench]
152+
fn base64_decode_wrap(b: &mut Bencher) {
153+
let input = &mut [b'A'; 4096];
154+
for i in 0 .. 20 {
155+
let x = 4096 * i / 20 / 4 * 4;
156+
input[x + 3] = b'\n';
157+
}
158+
let output = &mut [0u8; 3072];
159+
let mut spec = constants::BASE64.specification();
160+
spec.wrap.width = 76;
161+
spec.wrap.separator.push_str("\r\n");
162+
let base64 = spec.encoding().unwrap();
163+
let base64 = Encoding::<Bit6, True, True, True, True>::try_from(base64).unwrap();
164+
b.iter(|| base64.decode_mut(input, output).unwrap());
165+
}
166+
167+
#[bench]
168+
fn dnscurve_decode_base(b: &mut Bencher) {
169+
let input = &[b'0'; 4096];
170+
let output = &mut [0u8; 2560];
171+
b.iter(|| constants::BASE32_DNSCURVE.decode_mut(input, output));
172+
}
173+
174+
#[bench]
175+
fn dnscurve_encode_base(b: &mut Bencher) {
176+
let input = &[0u8; 4096];
177+
let output = &mut [0u8; 6554];
178+
b.iter(|| constants::BASE32_DNSCURVE.encode_mut(input, output));
179+
}

0 commit comments

Comments
 (0)