Skip to content

Commit a36d99f

Browse files
committed
use custom base45
1 parent 65df816 commit a36d99f

File tree

8 files changed

+41
-91
lines changed

8 files changed

+41
-91
lines changed

Diff for: Cargo.lock

-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ p256 = "0.8.0"
1919
simple_asn1 = "0.5.2"
2020
# zip = { version = "0.5.12", default-features = false, features = ['deflate-zlib'] }
2121
# flate2 = "1.0.20"
22-
base45 = "2.0.1"
22+
# flate2 = "1.0.20"
2323

2424
[[bench]]
2525
name = "benchmark"

Diff for: benches/benchmark.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
use bencher::Bencher;
22
use bencher::{benchmark_main, benchmark_group};
33
use rust_dgc::base45::ALPHABET;
4-
fn benchmark_encoding(bench: &mut Bencher) {
4+
fn benchmark_encoding_custom(bench: &mut Bencher) {
55
bench.iter(|| {
66
let sample_3 = "base-45";
77
rust_dgc::base45::encode(sample_3.as_bytes())
88
})
99
}
10-
fn benchmark_decoding(bench: &mut Bencher) {
10+
11+
fn benchmark_decoding_custom(bench: &mut Bencher) {
1112
bench.iter(|| {
1213
let sample_3 = "UJCLQE7W581";
1314
rust_dgc::base45::decode(sample_3)
1415
})
1516
}
1617

17-
fn benchmark_large_encoding(bench: &mut Bencher) {
18-
let random_bytes: Vec<u8> = (0..1_000_000).map(|_| { rand::random::<u8>() }).collect();
18+
fn benchmark_large_encoding_custom(bench: &mut Bencher) {
19+
1920
bench.iter(|| {
21+
let random_bytes: Vec<u8> = (0..1_000_000).map(|_| { rand::random::<u8>() }).collect();
2022
rust_dgc::base45::encode(&random_bytes)
2123
})
2224
}
2325

24-
fn benchmark_large_decoding(bench: &mut Bencher) {
26+
fn benchmark_large_decoding_custom(bench: &mut Bencher) {
2527
use rand::Rng;
2628

2729
let random_bytes: Vec<u8> = (0..1_500_000).map(|_| {
@@ -35,5 +37,5 @@ fn benchmark_large_decoding(bench: &mut Bencher) {
3537
})
3638
}
3739

38-
benchmark_group!(benches, benchmark_encoding, benchmark_decoding, benchmark_large_encoding, benchmark_large_decoding);
40+
benchmark_group!(benches, benchmark_encoding_custom, benchmark_decoding_custom, benchmark_large_encoding_custom, benchmark_large_decoding_custom);
3941
benchmark_main!(benches);

Diff for: src/base45.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ pub fn decode(base45_string: &str) -> Result<Vec<u8>, InvalidCharacter> {
133133
_ => panic!(),
134134
};
135135
let bytes = val.to_be_bytes();
136-
if val <= u8::MAX as u16 {
136+
if c.len() < 3 {
137137
vec![bytes[1]]
138138
} else {
139-
bytes.to_vec()
139+
bytes.to_vec()
140140
}
141141
})
142142
.collect::<Vec<u8>>())

Diff for: src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct Jwk {
3636
pub crv : Option<String>
3737
}
3838
fn main() -> Result<(), Box<dyn std::error::Error>> {
39-
4039

4140
let key_list = include_bytes!("list");
4241
let cwt = get_payload(key_list).unwrap();

Diff for: web/dgc-web/Cargo.lock

+23-65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: web/dgc-web/Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ wee_alloc = { version = "0.4.2", optional = true }
3232
serde_json = "1.0.64"
3333
base64 = "0.13.0"
3434
getrandom = {version = "0.2.2", features = ["js"]}
35-
base45 = "2.0.1"
3635
flate2 = {version = "1.0.20", default-features =false, features = ["rust_backend"]}
3736
# The `web-sys` crate allows you to interact with the various browser APIs,
3837
# like the DOM.
@@ -49,7 +48,7 @@ console_error_panic_hook = "0.1.5"
4948

5049
# These crates are used for running unit tests.
5150
[dev-dependencies]
52-
wasm-bindgen-test = "0.2.45"
53-
futures = "0.1.27"
51+
wasm-bindgen-test = "0.3.23"
52+
# futures = "0.1.27"
5453
js-sys = "0.3.22"
55-
wasm-bindgen-futures = "0.3.22"
54+
# wasm-bindgen-futures = "0.4.23"

Diff for: web/dgc-web/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::io::Cursor;
22

3-
use base45::decode;
4-
use rust_dgc::{get_payload, from_byte_string, to_byte_string, VerificationKey};
3+
use rust_dgc::{VerificationKey, base45, from_byte_string, get_payload, to_byte_string};
54
use wasm_bindgen::prelude::*;
65
use std::io::Read;
76

87
#[wasm_bindgen]
98
pub fn parse_cwt_from_bytestring(cbor_cwt: String) -> String {
109
let cbor_cwt = if cbor_cwt.starts_with("HC1:") {
11-
let mut decoded = Cursor::new( base45::decode(&cbor_cwt.replace("HC1:", "")));
10+
let mut decoded = Cursor::new( base45::decode(&cbor_cwt.replace("HC1:", "")).unwrap_or(vec![]));
1211
let mut decompressor = flate2::read::ZlibDecoder::new(&mut decoded);
1312
let mut decompressed = vec![];
1413
match decompressor.read_to_end(&mut decompressed) {
@@ -29,7 +28,7 @@ pub fn parse_cwt_from_bytestring(cbor_cwt: String) -> String {
2928
#[wasm_bindgen]
3029
pub fn get_hcert_from_cwt(cbor_cwt: String) -> String {
3130
let cbor_cwt = if cbor_cwt.starts_with("HC1:") {
32-
let mut decoded = Cursor::new( base45::decode(&cbor_cwt.replace("HC1:", "")));
31+
let mut decoded = Cursor::new( base45::decode(&cbor_cwt.replace("HC1:", "")).unwrap_or(vec![]));
3332
let mut decompressor = flate2::read::ZlibDecoder::new(&mut decoded);
3433
let mut decompressed = vec![];
3534
match decompressor.read_to_end(&mut decompressed) {
@@ -50,7 +49,7 @@ pub fn get_hcert_from_cwt(cbor_cwt: String) -> String {
5049
#[wasm_bindgen]
5150
pub fn verify_cwt_ec(cbor_cwt: String, x: String, y: String, encoding: String) -> bool {
5251
let cbor_cwt = if cbor_cwt.starts_with("HC1:") {
53-
let mut decoded = Cursor::new( base45::decode(&cbor_cwt.replace("HC1:", "")));
52+
let mut decoded = Cursor::new( base45::decode(&cbor_cwt.replace("HC1:", "")).unwrap_or(vec![]));
5453
let mut decompressor = flate2::read::ZlibDecoder::new(&mut decoded);
5554
let mut decompressed = vec![];
5655
match decompressor.read_to_end(&mut decompressed) {

0 commit comments

Comments
 (0)