Skip to content

Commit

Permalink
Upgrade base64 to 0.21 (#123)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: facebookresearch/Private-ID#123

Reviewed By: zertosh

Differential Revision: D61737689

fbshipit-source-id: dc98887dd6b346f11d8efe7ffa085311f6110c37
  • Loading branch information
capickett authored and facebook-github-bot committed Aug 28, 2024
1 parent 0410fb4 commit 4a1f379
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion unsupported/juno/crates/juno_support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"

[dependencies]
libcplusplus = { path = "../libcplusplus" }
base64 = "0.13"
base64 = "0.21.7"
anyhow = "1.0"
thiserror = "1.0"
url = "2.2.2"
Expand Down
15 changes: 13 additions & 2 deletions unsupported/juno/crates/juno_support/src/fetchurl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ use std::fs::File;
use std::io::Read;

use anyhow;
use base64;
use base64::alphabet::URL_SAFE;
use base64::engine::general_purpose::GeneralPurpose;
use base64::engine::general_purpose::GeneralPurposeConfig;
use base64::engine::general_purpose::PAD;
use base64::engine::DecodePaddingMode;
use base64::Engine;
use thiserror;
use url::Url;

// Bring back the pre 0.20 bevahiour and allow either padded or un-padded base64 strings at decode time.
const URL_SAFE_INDIFFERENT: GeneralPurpose = GeneralPurpose::new(
&URL_SAFE,
PAD.with_decode_padding_mode(DecodePaddingMode::Indifferent),
);

#[derive(thiserror::Error, Debug)]
pub enum FetchError {
#[error("URL parse error")]
Expand Down Expand Up @@ -125,7 +136,7 @@ fn fetch_data(url: &Url) -> Result<Data, FetchError> {
return Err(FetchError::InvalidURL("data URL unsupported encoding"));
}

let buf = base64::decode_config(data, base64::URL_SAFE).map_err(|e| {
let buf: Vec<u8> = URL_SAFE_INDIFFERENT.decode(data).map_err(|e| {
FetchError::DecodeError(anyhow::anyhow!(e).context("error decoding data URL"))
})?;

Expand Down

0 comments on commit 4a1f379

Please sign in to comment.