Skip to content

Commit

Permalink
Merge pull request #196 from marshallpierce/mp/port-decode-size
Browse files Browse the repository at this point in the history
Merge 0.13.1
  • Loading branch information
marshallpierce committed Oct 21, 2022
2 parents a675443 + caadeaa commit 7fa4339
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -14,7 +14,7 @@ workflows:
# be easier on the CI hosts since presumably those fat lower layers will already be cached, and
# therefore faster than a minimal, customized alpine.
# MSRV
'rust:1.47.0'
'rust:1.51.0'
]
# a hacky scheme to work around CircleCI's inability to deal with mutable docker tags, forcing us to
# get a nightly or stable toolchain via rustup instead of a mutable docker tag
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -10,7 +10,7 @@ keywords = ["base64", "utf8", "encode", "decode", "no_std"]
categories = ["encoding"]
license = "MIT OR Apache-2.0"
edition = "2018"
rust-version = "1.47.0"
rust-version = "1.51.0"

[[bench]]
name = "benchmarks"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -45,7 +45,7 @@ If you have a `Read` (e.g. reading a file or network socket), there are various

## Rust version compatibility

The minimum required Rust version is 1.47.0.
The minimum required Rust version is 1.51.0.

# Contributing

Expand Down
8 changes: 8 additions & 0 deletions RELEASE-NOTES.md
@@ -1,5 +1,9 @@
# 0.20.0

## Next

- MSRV is now 1.51.0 to keep up with `criterion`

## 0.20.0-alpha.1

### Breaking changes
Expand All @@ -13,6 +17,10 @@
- `DecoderReader` now owns its inner reader, and can expose it via `into_inner()`. For symmetry, `EncoderWriter` can do the same with its writer.
- `encoded_len` is now public so you can size encode buffers precisely.

# 0.13.1

- More precise decode buffer sizing, avoiding unnecessary allocation in `decode_config`.

# 0.13.0

- Config methods are const
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
@@ -1 +1 @@
msrv = "1.47.0"
msrv = "1.51.0"
22 changes: 21 additions & 1 deletion src/decode.rs
Expand Up @@ -95,7 +95,14 @@ pub fn decode_engine<E: Engine, T: AsRef<[u8]>>(
input: T,
engine: &E,
) -> Result<Vec<u8>, DecodeError> {
let mut buffer = Vec::<u8>::new();
let decoded_length_estimate = (input
.as_ref()
.len()
.checked_add(3)
.expect("decoded length calculation overflow"))
/ 4
* 3;
let mut buffer = Vec::<u8>::with_capacity(decoded_length_estimate);
decode_engine_vec(input, &mut buffer, engine).map(|_| buffer)
}

Expand Down Expand Up @@ -340,4 +347,17 @@ mod tests {
assert_eq!(orig_data, decode_buf);
}
}

#[test]
fn decode_engine_estimation_works_for_various_lengths() {
for num_prefix_quads in 0..100 {
for suffix in &["AA", "AAA", "AAAA"] {
let mut prefix = "AAAA".repeat(num_prefix_quads);
prefix.push_str(suffix);
// make sure no overflow (and thus a panic) occurs
let res = decode_engine(prefix, &DEFAULT_ENGINE);
assert!(res.is_ok());
}
}
}
}

0 comments on commit 7fa4339

Please sign in to comment.