From 4a1f379c734a0804e93560dac9c1d95f0f5af389 Mon Sep 17 00:00:00 2001 From: Cameron Pickett Date: Wed, 28 Aug 2024 11:18:04 -0700 Subject: [PATCH] Upgrade base64 to 0.21 (#123) Summary: Pull Request resolved: https://github.com/facebookresearch/Private-ID/pull/123 Reviewed By: zertosh Differential Revision: D61737689 fbshipit-source-id: dc98887dd6b346f11d8efe7ffa085311f6110c37 --- unsupported/juno/crates/juno_support/Cargo.toml | 2 +- .../juno/crates/juno_support/src/fetchurl.rs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/unsupported/juno/crates/juno_support/Cargo.toml b/unsupported/juno/crates/juno_support/Cargo.toml index 7b088d7d6fd..0d4dc387f7c 100644 --- a/unsupported/juno/crates/juno_support/Cargo.toml +++ b/unsupported/juno/crates/juno_support/Cargo.toml @@ -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" diff --git a/unsupported/juno/crates/juno_support/src/fetchurl.rs b/unsupported/juno/crates/juno_support/src/fetchurl.rs index 62c8ec77b1f..3d81496bd54 100644 --- a/unsupported/juno/crates/juno_support/src/fetchurl.rs +++ b/unsupported/juno/crates/juno_support/src/fetchurl.rs @@ -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")] @@ -125,7 +136,7 @@ fn fetch_data(url: &Url) -> Result { return Err(FetchError::InvalidURL("data URL unsupported encoding")); } - let buf = base64::decode_config(data, base64::URL_SAFE).map_err(|e| { + let buf: Vec = URL_SAFE_INDIFFERENT.decode(data).map_err(|e| { FetchError::DecodeError(anyhow::anyhow!(e).context("error decoding data URL")) })?;