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 2e4fbcd commit c165523
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion antlir/antlir2/features/install/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ use antlir2_users::GroupId;
use antlir2_users::Id;
use antlir2_users::UserId;
use anyhow::Context;
use base64::alphabet::STANDARD;
use base64::engine::general_purpose::GeneralPurpose;
use base64::engine::general_purpose::GeneralPurposeConfig;
use base64::engine::DecodePaddingMode;
use base64::Engine;
#[cfg(feature = "setcap")]
use libcap::Capabilities;
#[cfg(feature = "setcap")]
Expand All @@ -44,6 +49,12 @@ use tracing::debug;
use walkdir::WalkDir;
use xattr::FileExt as _;

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

pub type Feature = Install;

#[serde_as]
Expand Down Expand Up @@ -181,7 +192,7 @@ impl<'de> Deserialize<'de> for XattrValue {
let bytes = hex::decode(hex_value).map_err(D::Error::custom)?;
Ok(Self(bytes))
} else if let Some(b64) = s.strip_prefix("0s") {
let bytes = base64::decode(b64).map_err(D::Error::custom)?;
let bytes = STANDARD_INDIFFERENT.decode(b64).map_err(D::Error::custom)?;
Ok(Self(bytes))
} else {
Ok(Self(s.into_bytes()))
Expand Down
13 changes: 12 additions & 1 deletion antlir/antlir2/testing/image_diff_test/src/file_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use antlir2_facts::fact::user::User;
use antlir2_mode::Mode;
use anyhow::Context;
use anyhow::Result;
use base64::alphabet::STANDARD;
use base64::engine::general_purpose::GeneralPurpose;
use base64::engine::general_purpose::GeneralPurposeConfig;
use base64::engine::DecodePaddingMode;
use base64::Engine;
use md5::Digest;
use md5::Md5;
use serde::de::Error as _;
Expand All @@ -27,6 +32,12 @@ use serde::Serialize;
use serde_with::serde_as;
use serde_with::DisplayFromStr;

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

#[serde_as]
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
Expand Down Expand Up @@ -232,7 +243,7 @@ impl<'de> Deserialize<'de> for XattrData {
let bytes = hex::decode(hex_value).map_err(D::Error::custom)?;
Ok(Self(bytes))
} else if let Some(b64) = s.strip_prefix("0s") {
let bytes = base64::decode(b64).map_err(D::Error::custom)?;
let bytes = STANDARD_INDIFFERENT.decode(b64).map_err(D::Error::custom)?;
Ok(Self(bytes))
} else {
Ok(Self(s.into_bytes()))
Expand Down

0 comments on commit c165523

Please sign in to comment.