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 ed24fc7 commit fad0c69
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 21 deletions.
2 changes: 1 addition & 1 deletion eden/mononoke/blobstore/sqlblob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "GPLv2+"
[dependencies]
anyhow = "1.0.86"
async-trait = "0.1.71"
base64 = "0.13"
base64 = "0.21"
blobstore = { version = "0.1.0", path = ".." }
bytes = { version = "1.6.0", features = ["serde"] }
cached_config = { version = "0.1.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" }
Expand Down
14 changes: 12 additions & 2 deletions eden/mononoke/blobstore/sqlblob/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ use anyhow::format_err;
use anyhow::Error;
use anyhow::Result;
use async_trait::async_trait;
use base64::alphabet::STANDARD;
use base64::engine::general_purpose::GeneralPurpose;
use base64::engine::general_purpose::NO_PAD;
use base64::engine::DecodePaddingMode;
use base64::Engine;
use blobstore::Blobstore;
use blobstore::BlobstoreGetData;
use blobstore::BlobstoreIsPresent;
Expand Down Expand Up @@ -77,6 +82,11 @@ use crate::store::ChunkGenerationState;
use crate::store::ChunkSqlStore;
use crate::store::ChunkingMethod;
use crate::store::DataSqlStore;
// Bring back the pre 0.20 bevahiour and allow either padded or un-padded base64 strings at decode time.
const STANDARD_NO_PAD_INDIFFERENT: GeneralPurpose = GeneralPurpose::new(
&STANDARD,
NO_PAD.with_decode_padding_mode(DecodePaddingMode::Indifferent),
);

// Leaving some space for metadata
const MAX_KEY_SIZE: usize = 200;
Expand Down Expand Up @@ -122,7 +132,7 @@ const DEFAULT_CTIME_INLINE_GRACE: i64 = 86400;
pub const MAX_INLINE_LEN: u64 = 255 * 3 / 4;

fn encode_small_value(raw: &[u8]) -> String {
base64::encode_config(raw, base64::STANDARD_NO_PAD)
STANDARD_NO_PAD_INDIFFERENT.encode(raw)
}

impl Sqlblob {
Expand Down Expand Up @@ -505,7 +515,7 @@ impl Sqlblob {
if let Some(chunked) = chunked {
let blob = match chunked.chunking_method {
ChunkingMethod::InlineBase64 => {
let decoded = base64::decode_config(&chunked.id, base64::STANDARD_NO_PAD)?;
let decoded = STANDARD_NO_PAD_INDIFFERENT.decode(&chunked.id)?;
Bytes::copy_from_slice(decoded.as_ref())
}
ChunkingMethod::ByContentHashBlake2 => {
Expand Down
2 changes: 1 addition & 1 deletion eden/mononoke/common/rust/sql_ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ anyhow = "1.0.86"
async-trait = "0.1.71"
aws-config = "0.55.3"
aws-sdk-secretsmanager = "0.28.0"
base64 = "0.13"
base64 = "0.21"
bytes = { version = "1.6.0", features = ["serde"] }
caching_ext = { version = "0.1.0", path = "../caching_ext" }
clientinfo = { version = "0.1.0", path = "../../../../scm/lib/clientinfo" }
Expand Down
3 changes: 2 additions & 1 deletion eden/mononoke/common/rust/sql_ext/src/mononoke_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use abomonation_derive::Abomonation;
use anyhow::anyhow;
use anyhow::Result;
use async_trait::async_trait;
use base64::Engine;
use bytes::Bytes;
use caching_ext::*;
use itertools::Itertools;
Expand Down Expand Up @@ -615,7 +616,7 @@ where
fn get_cache_key(&self, key: &Key) -> String {
// We just need a unique representation of the key as a String.
// Let's use base64 as it's smaller than just .to_string()
base64::encode(key.to_ne_bytes())
base64::engine::general_purpose::STANDARD.encode(key.to_ne_bytes())
}

async fn get_from_db(
Expand Down
2 changes: 1 addition & 1 deletion eden/mononoke/edenapi_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "GPLv2+"
anyhow = "1.0.86"
async-stream = "0.3"
async-trait = "0.1.71"
base64 = "0.13"
base64 = "0.21"
blobstore = { version = "0.1.0", path = "../blobstore" }
bookmarks = { version = "0.1.0", path = "../bookmarks" }
bookmarks_movement = { version = "0.1.0", path = "../bookmarks/bookmarks_movement" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::collections::HashSet;
use anyhow::bail;
use anyhow::Context;
use anyhow::Result;
use base64::Engine;
use bytes::Bytes;
use fbinit::FacebookInit;
use gotham::state::FromState;
Expand Down Expand Up @@ -134,7 +135,10 @@ impl RequestDumper {
self.log_action = LogAction::BodyTooBig;
return;
}
self.logger.add("body", base64::encode(&body[..]));
self.logger.add(
"body",
base64::engine::general_purpose::STANDARD.encode(&body[..]),
);
}

// If the request is very small, log the request in human readable format.
Expand Down
2 changes: 1 addition & 1 deletion eden/mononoke/mercurial/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ anyhow = "1.0.86"
ascii = "1.0"
async-stream = "0.3"
async-trait = "0.1.71"
base64 = "0.13"
base64 = "0.21"
bitflags = { version = "2.4", features = ["serde"] }
blake3 = { version = "=1.5.0", features = ["traits-preview"] }
blobstore = { version = "0.1.0", path = "../../blobstore" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use anyhow::bail;
use anyhow::Context;
use anyhow::Result;
use async_trait::async_trait;
use base64::Engine;
use blake3::Hasher as Blake3Hasher;
use blobstore::Blobstore;
use blobstore::BlobstoreBytes;
Expand Down Expand Up @@ -294,7 +295,11 @@ impl ShardedHgAugmentedManifest {
w.write_all(file.content_sha1.to_hex().as_bytes())?;
w.write_all(b" ")?;
if let Some(file_header_metadata) = &file.file_header_metadata {
w.write_all(base64::encode(file_header_metadata).as_ref())?;
w.write_all(
base64::engine::general_purpose::STANDARD
.encode(file_header_metadata)
.as_ref(),
)?;
} else {
w.write_all(b"-")?;
}
Expand Down
2 changes: 1 addition & 1 deletion eden/mononoke/mononoke_hg_sync_job/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ anyhow = "1.0.86"
assembly_line = { version = "0.1.0", path = "../common/assembly_line" }
async-stream = "0.3"
async-trait = "0.1.71"
base64 = "0.13"
base64 = "0.21"
blobstore = { version = "0.1.0", path = "../blobstore" }
bonsai_globalrev_mapping = { version = "0.1.0", path = "../bonsai_globalrev_mapping" }
bonsai_hg_mapping = { version = "0.1.0", path = "../bonsai_hg_mapping" }
Expand Down
3 changes: 2 additions & 1 deletion eden/mononoke/mononoke_hg_sync_job/src/hgrepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use anyhow::format_err;
use anyhow::Context as _;
use anyhow::Error;
use anyhow::Result;
use base64::Engine;
use bookmarks::BookmarkKey;
use futures::future;
use futures::future::FutureExt;
Expand Down Expand Up @@ -314,7 +315,7 @@ impl HgPeer {
};

let onto_bookmark = onto_bookmark.to_string();
let onto_bookmark = base64::encode(&onto_bookmark);
let onto_bookmark = base64::engine::general_purpose::STANDARD.encode(&onto_bookmark);
let expected_hash = expected_location_string_arg(expected_bookmark_position);

let hgbonsaimapping = match commits_in_bundle {
Expand Down
2 changes: 1 addition & 1 deletion eden/mononoke/server/repo_listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "GPLv2+"

[dependencies]
anyhow = "1.0.86"
base64 = "0.13"
base64 = "0.21"
bookmarks = { version = "0.1.0", path = "../../bookmarks" }
bytes = { version = "1.6.0", features = ["serde"] }
cached_config = { version = "0.1.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" }
Expand Down
3 changes: 2 additions & 1 deletion eden/mononoke/server/repo_listener/src/http_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use anyhow::anyhow;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use base64::Engine;
use bookmarks::BookmarksRef;
#[cfg(fbcode_build)]
use clientinfo::ClientEntryPoint;
Expand Down Expand Up @@ -467,7 +468,7 @@ fn calculate_websocket_accept(headers: &HeaderMap<HeaderValue>) -> String {
}
sha1.update(WEBSOCKET_MAGIC_KEY.as_bytes());
let hash: [u8; 20] = sha1.finalize().into();
base64::encode(hash)
base64::engine::general_purpose::STANDARD.encode(hash)
}

#[cfg(not(fbcode_build))]
Expand Down
2 changes: 1 addition & 1 deletion eden/scm/lib/commitcloudsubscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ description = """

[dependencies]
anyhow = "1.0.86"
base64 = "0.13"
base64 = "0.21"
configset = { version = "0.1.0", path = "../config/set" }
filetime = "0.2.9"
hostcaps = { version = "0.1.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" }
Expand Down
4 changes: 3 additions & 1 deletion eden/scm/lib/commitcloudsubscriber/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::str;
use std::time::SystemTime;

use anyhow::Result;
use base64::Engine;
use configset::Config;
use filetime::FileTime;
use log::error;
Expand Down Expand Up @@ -214,7 +215,8 @@ pub fn read_or_generate_access_token(user_token_path: &Option<PathBuf>) -> Resul
clicat_tool
);
let token_timeout_seconds = 1200;
let payload = base64::encode(json!({"app":COMMIT_CLOUD_APP_ID}).to_string());
let payload = base64::engine::general_purpose::STANDARD
.encode(json!({"app":COMMIT_CLOUD_APP_ID}).to_string());
let output = Command::new(clicat_tool)
.args(vec![
"create",
Expand Down
2 changes: 1 addition & 1 deletion eden/scm/lib/config/loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ harness = false

[dependencies]
anyhow = "1.0.86"
base64 = "0.13"
base64 = "0.21"
configmodel = { version = "0.1.0", path = "../model" }
configset = { version = "0.1.0", path = "../set" }
dirs = "2.0"
Expand Down
2 changes: 1 addition & 1 deletion eden/scm/lib/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.86"
base64 = "0.13"
base64 = "0.21"
bitflags = { version = "2.4", features = ["serde"] }
blake3 = { version = "=1.5.0", features = ["traits-preview"] }
byteorder = "1.3"
Expand Down
21 changes: 19 additions & 2 deletions eden/scm/lib/types/src/augmented_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ use std::io::Write;

use anyhow::anyhow;
use anyhow::Error;
use base64::alphabet::STANDARD;
use base64::engine::general_purpose::GeneralPurpose;
use base64::engine::general_purpose::GeneralPurposeConfig;
use base64::engine::DecodePaddingMode;
use base64::Engine;
use blake3::Hasher as Blake3Hasher;
use minibytes::Bytes;

Expand All @@ -22,6 +27,12 @@ use crate::Id20;
use crate::RepoPathBuf;
use crate::Sha1;

// 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),
);

#[derive(Clone, Debug, PartialEq)]
pub struct AugmentedFileNode {
pub file_type: FileType,
Expand Down Expand Up @@ -187,7 +198,11 @@ impl AugmentedTree {
w.write_all(file.content_sha1.to_hex().as_ref())?;
w.write_all(b" ")?;
if let Some(file_header_metadata) = &file.file_header_metadata {
w.write_all(base64::encode(file_header_metadata).as_bytes())?;
w.write_all(
base64::engine::general_purpose::STANDARD
.encode(file_header_metadata)
.as_bytes(),
)?;
} else {
w.write_all(b"-")?;
};
Expand Down Expand Up @@ -311,7 +326,9 @@ impl AugmentedTree {
let file_header_metadata = if file_header_metadata == "-" {
None
} else {
Some(Bytes::from(base64::decode(file_header_metadata)?))
Some(Bytes::from(
STANDARD_INDIFFERENT.decode(file_header_metadata)?,
))
};

Ok((
Expand Down
2 changes: 1 addition & 1 deletion eden/scm/lib/webview-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ serde = { version = "1.0.185", features = ["derive", "rc"] }
serde_json = { version = "1.0.100", features = ["float_roundtrip", "unbounded_depth"] }

[target.'cfg(target_os = "macos")'.dependencies]
base64 = "0.13"
base64 = "0.21"
open = "4"
tinyfiledialogs = "3.9.1"
tracing = { version = "0.1.40", features = ["attributes", "valuable"] }
Expand Down
4 changes: 3 additions & 1 deletion eden/scm/lib/webview-app/src/macos_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::path::PathBuf;
use std::process::Command;

use anyhow::Context;
use base64::Engine;
use serde::Deserialize;
use serde::Serialize;

Expand Down Expand Up @@ -351,7 +352,8 @@ extern "C" fn handle_webview_invoke(webview: *mut webview_sys::CWebView, arg: *c
file_name.to_owned().into_string().unwrap_or_default();
Some(WebviewInvokeFile {
name: file_name,
base64_content: base64::encode(content),
base64_content: base64::engine::general_purpose::STANDARD
.encode(content),
})
}
Err(e) => {
Expand Down

0 comments on commit fad0c69

Please sign in to comment.