From c165523eab79be9a9d69f7abf77fc479720777b2 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 --- antlir/antlir2/features/install/install.rs | 13 ++++++++++++- .../testing/image_diff_test/src/file_entry.rs | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/antlir/antlir2/features/install/install.rs b/antlir/antlir2/features/install/install.rs index 71101abd3f3..f87b7854336 100644 --- a/antlir/antlir2/features/install/install.rs +++ b/antlir/antlir2/features/install/install.rs @@ -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")] @@ -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] @@ -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())) diff --git a/antlir/antlir2/testing/image_diff_test/src/file_entry.rs b/antlir/antlir2/testing/image_diff_test/src/file_entry.rs index e593e038c4c..f398f6bead9 100644 --- a/antlir/antlir2/testing/image_diff_test/src/file_entry.rs +++ b/antlir/antlir2/testing/image_diff_test/src/file_entry.rs @@ -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 _; @@ -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)] @@ -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()))