Skip to content

Commit

Permalink
chore(deps): update base64 requirement from 0.13 to 0.21 (#89)
Browse files Browse the repository at this point in the history
* chore(deps): update base64 requirement from 0.13 to 0.21

Updates the requirements on [base64](https://github.com/marshallpierce/rust-base64) to permit the latest version.
- [Release notes](https://github.com/marshallpierce/rust-base64/releases)
- [Changelog](https://github.com/marshallpierce/rust-base64/blob/master/RELEASE-NOTES.md)
- [Commits](marshallpierce/rust-base64@v0.13.0...v0.21.0)

---
updated-dependencies:
- dependency-name: base64
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix: fix removed methods

* fix: indifferent padding

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Raphael Taylor-Davies <[email protected]>
  • Loading branch information
dependabot[bot] and tustvold authored Sep 17, 2023
1 parent 1adce94 commit 362f52c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pbjson-types/src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ macro_rules! ser_bytes_value {
where
S: serde::Serializer,
{
let value = pbjson::private::base64::encode(&self.value);
use pbjson::private::base64::engine::Engine;
let value =
pbjson::private::base64::engine::general_purpose::STANDARD.encode(&self.value);
value.serialize(ser)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pbjson/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = "https://github.com/influxdata/pbjson"
[dependencies]

serde = { version = "1.0", features = ["derive"] }
base64 = "0.13"
base64 = "0.21"

[dev-dependencies]
bytes = "1.0"
Expand Down
26 changes: 19 additions & 7 deletions pbjson/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub mod private {
/// Re-export base64
pub use base64;

use base64::engine::DecodePaddingMode;
use base64::engine::{GeneralPurpose, GeneralPurposeConfig};
use base64::Engine;
use serde::de::Visitor;
use serde::Deserialize;
use std::borrow::Cow;
Expand Down Expand Up @@ -69,7 +72,15 @@ pub mod private {
where
E: serde::de::Error,
{
let decoded = base64::decode_config(s, base64::STANDARD)
const INDIFFERENT_PAD: GeneralPurposeConfig = GeneralPurposeConfig::new()
.with_decode_padding_mode(DecodePaddingMode::Indifferent);
const STANDARD_INDIFFERENT_PAD: GeneralPurpose =
GeneralPurpose::new(&base64::alphabet::STANDARD, INDIFFERENT_PAD);
const URL_SAFE_INDIFFERENT_PAD: GeneralPurpose =
GeneralPurpose::new(&base64::alphabet::URL_SAFE, INDIFFERENT_PAD);

let decoded = STANDARD_INDIFFERENT_PAD
.decode(s)
.or_else(|e| match e {
// Either standard or URL-safe base64 encoding are accepted
//
Expand All @@ -78,7 +89,7 @@ pub mod private {
// Therefore if we error out on those characters, try again with
// the URL-safe character set
base64::DecodeError::InvalidByte(_, c) if c == b'-' || c == b'_' => {
base64::decode_config(s, base64::URL_SAFE)
URL_SAFE_INDIFFERENT_PAD.decode(s)
}
_ => Err(e),
})
Expand All @@ -105,6 +116,7 @@ pub mod private {
#[cfg(test)]
mod tests {
use super::*;
use base64::Engine;
use bytes::Bytes;
use rand::prelude::*;
use serde::de::value::{BorrowedStrDeserializer, Error};
Expand All @@ -117,12 +129,12 @@ pub mod private {
let raw: Vec<_> = std::iter::from_fn(|| Some(rng.gen())).take(len).collect();

for config in [
base64::STANDARD,
base64::STANDARD_NO_PAD,
base64::URL_SAFE,
base64::URL_SAFE_NO_PAD,
base64::engine::general_purpose::STANDARD,
base64::engine::general_purpose::STANDARD_NO_PAD,
base64::engine::general_purpose::URL_SAFE,
base64::engine::general_purpose::URL_SAFE_NO_PAD,
] {
let encoded = base64::encode_config(&raw, config);
let encoded = config.encode(&raw);

let deserializer = BorrowedStrDeserializer::<'_, Error>::new(&encoded);
let a: Bytes = BytesDeserialize::deserialize(deserializer).unwrap().0;
Expand Down

0 comments on commit 362f52c

Please sign in to comment.