Skip to content

Commit

Permalink
Merge pull request #255 from marshallpierce/mp/debug
Browse files Browse the repository at this point in the history
Add Debug and Clone to general purpose Engine
  • Loading branch information
marshallpierce committed Oct 21, 2023
2 parents 53a8737 + bda313a commit 95dda57
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
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
Expand Down
9 changes: 3 additions & 6 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(|| {
Expand Down Expand Up @@ -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());
}

Expand Down
2 changes: 2 additions & 0 deletions src/engine/general_purpose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion src/read/decoder_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn trailing_junk() {
saw_error = true;
break;
}
Ok(read) if read == 0 => break,
Ok(0) => break,
Ok(_) => (),
}
}
Expand Down

0 comments on commit 95dda57

Please sign in to comment.