Bump `base64ct` crate `1.5.0` -> `1.5.1`

This new release checks for invalid symbols in non-padded inputs
for decoding. Therefore, we can get rid of the logic implemented
in `https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/600`
This commit is contained in:
Arturo Marquez 2022-06-27 23:10:58 -05:00
parent 0127ef7bee
commit af4970ec1f
No known key found for this signature in database
GPG Key ID: 4770F4929D4B560A
3 changed files with 9 additions and 21 deletions

4
Cargo.lock generated
View File

@ -510,9 +510,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "base64ct"
version = "1.5.0"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dea908e7347a8c64e378c17e30ef880ad73e3b4498346b055c2c00ea342f3179"
checksum = "3bdca834647821e0b13d9539a8634eb62d3501b6b6c2cec1722786ee6671b851"
[[package]]
name = "bitflags"

View File

@ -45,7 +45,7 @@ experimental-api = []
dangerous-expose-struct-fields = ["visible", "visibility"]
[dependencies]
base64ct = { version = "1.5.0", features = ["alloc"] }
base64ct = { version = "1.5.1", features = ["alloc"] }
bitflags = "1"
derive_more = "0.99"
digest = "0.10.0"

View File

@ -36,7 +36,7 @@ pub(crate) trait FromBytes: Sized {
/// Types for decoding base64-encoded values.
mod b64impl {
use crate::{Error, ParseErrorKind as EK, Pos, Result};
use base64ct::{Base64, Encoding};
use base64ct::{Base64, Base64Unpadded, Encoding};
use std::ops::RangeBounds;
/// A byte array, encoded in base64 with optional padding.
@ -45,22 +45,10 @@ mod b64impl {
impl std::str::FromStr for B64 {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
// The `base64ct` crate only rejects invalid
// characters when the input is padded. Therefore,
// the input must be padded fist. For more info on
// this, take a look at this issue:
// `https://github.com/RustCrypto/utils/issues/576`
let mut string = s.to_string();
// Determine padding length
let offset = 4 - s.len() % 4;
match offset {
4 => (),
_ => {
// Add pad to input
string.push_str("=".repeat(offset).as_str());
}
}
let v = Base64::decode_vec(&string);
let v: core::result::Result<Vec<u8>, base64ct::Error> = match s.len() % 4 {
0 => Base64::decode_vec(s),
_ => Base64Unpadded::decode_vec(s),
};
let v = v.map_err(|_| {
EK::BadArgument
.with_msg("Invalid base64")
@ -533,8 +521,8 @@ mod test {
assert!("B".parse::<B64>().is_err());
assert!("B=".parse::<B64>().is_err());
assert!("B==".parse::<B64>().is_err());
assert!("Bg=".parse::<B64>().is_err());
assert_eq!("Bg".parse::<B64>()?.as_bytes(), b"\x06");
assert_eq!("Bg=".parse::<B64>()?.as_bytes(), b"\x06");
assert_eq!("Bg==".parse::<B64>()?.as_bytes(), b"\x06");
assert_eq!("BCg".parse::<B64>()?.as_bytes(), b"\x04\x28");
assert_eq!("BCg=".parse::<B64>()?.as_bytes(), b"\x04\x28");