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 Debug and Clone to general purpose Engine #255

Merged
merged 1 commit into from
Oct 21, 2023
Merged
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ workflows:
# get a nightly or stable toolchain via rustup instead of a mutable docker tag
toolchain_override: [
'__msrv__', # won't add any other toolchains, just uses what's in the docker image
'1.63.0', # minimum needed to build dev-dependencies
'1.65.0', # minimum needed to build dev-dependencies
'stable',
'beta',
'nightly'
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ keywords = ["base64", "utf8", "encode", "decode", "no_std"]
categories = ["encoding"]
license = "MIT OR Apache-2.0"
edition = "2018"
# dev-dependencies require 1.63, but the main code doesn't
# dev-dependencies require 1.65, but the main code doesn't
# This option was added in 1.56, keep it for when we bump MSRV.
rust-version = "1.48.0"

4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.21.5

- Add `Debug` and `Clone` impls for the general purpose Engine

# 0.21.4

- Make `encoded_len` `const`, allowing the creation of arrays sized to encode compile-time-known data lengths
9 changes: 3 additions & 6 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -39,8 +39,7 @@ fn do_decode_bench_slice(b: &mut Bencher, &size: &usize) {
fill(&mut v);
let encoded = STANDARD.encode(&v);

let mut buf = Vec::new();
buf.resize(size, 0);
let mut buf = vec![0; size];
b.iter(|| {
STANDARD.decode_slice(&encoded, &mut buf).unwrap();
black_box(&buf);
@@ -52,8 +51,7 @@ fn do_decode_bench_stream(b: &mut Bencher, &size: &usize) {
fill(&mut v);
let encoded = STANDARD.encode(&v);

let mut buf = Vec::new();
buf.resize(size, 0);
let mut buf = vec![0; size];
buf.truncate(0);

b.iter(|| {
@@ -96,9 +94,8 @@ fn do_encode_bench_reuse_buf(b: &mut Bencher, &size: &usize) {
fn do_encode_bench_slice(b: &mut Bencher, &size: &usize) {
let mut v: Vec<u8> = Vec::with_capacity(size);
fill(&mut v);
let mut buf = Vec::new();
// conservative estimate of encoded size
buf.resize(v.len() * 2, 0);
let mut buf = vec![0; v.len() * 2];
b.iter(|| STANDARD.encode_slice(&v, &mut buf).unwrap());
}

2 changes: 2 additions & 0 deletions src/engine/general_purpose/mod.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ pub(crate) const INVALID_VALUE: u8 = 255;
/// - It uses no vector CPU instructions, so it will work on any system.
/// - It is reasonably fast (~2-3GiB/s).
/// - It is not constant-time, though, so it is vulnerable to timing side-channel attacks. For loading cryptographic keys, etc, it is suggested to use the forthcoming constant-time implementation.

#[derive(Debug, Clone)]
pub struct GeneralPurpose {
encode_table: [u8; 64],
decode_table: [u8; 256],
2 changes: 1 addition & 1 deletion src/read/decoder_tests.rs
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ fn trailing_junk() {
saw_error = true;
break;
}
Ok(read) if read == 0 => break,
Ok(0) => break,
Ok(_) => (),
}
}