0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

chore: update base64 crate (#20877)

This commit is contained in:
Luca Casonato 2023-10-26 18:39:04 +02:00 committed by GitHub
parent 842e29057d
commit 08b99f3909
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 56 additions and 32 deletions

10
Cargo.lock generated
View file

@ -971,7 +971,7 @@ version = "1.37.2"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"base32", "base32",
"base64 0.13.1", "base64 0.21.4",
"bincode", "bincode",
"bytes", "bytes",
"cache_control", "cache_control",
@ -1236,7 +1236,7 @@ dependencies = [
"aes", "aes",
"aes-gcm", "aes-gcm",
"aes-kw", "aes-kw",
"base64 0.13.1", "base64 0.21.4",
"cbc", "cbc",
"const-oid", "const-oid",
"ctr", "ctr",
@ -1378,7 +1378,7 @@ version = "0.116.0"
dependencies = [ dependencies = [
"async-compression", "async-compression",
"async-trait", "async-trait",
"base64 0.13.1", "base64 0.21.4",
"bencher", "bencher",
"brotli", "brotli",
"bytes", "bytes",
@ -1428,7 +1428,7 @@ version = "0.29.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"base64 0.13.1", "base64 0.21.4",
"chrono", "chrono",
"deno_core", "deno_core",
"deno_node", "deno_node",
@ -5647,7 +5647,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-stream", "async-stream",
"base64 0.13.1", "base64 0.21.4",
"bytes", "bytes",
"console_static_text", "console_static_text",
"fastwebsockets", "fastwebsockets",

View file

@ -72,8 +72,7 @@ deno_napi = { version = "0.51.0", path = "./ext/napi" }
aes = "=0.8.3" aes = "=0.8.3"
anyhow = "1.0.57" anyhow = "1.0.57"
async-trait = "0.1.73" async-trait = "0.1.73"
# TODO(mmastrac): Requires code changes to bump base64 = "0.21.4"
base64 = "=0.13.1"
bencher = "0.1" bencher = "0.1"
brotli = "3.3.4" brotli = "3.3.4"
bytes = "1.4.0" bytes = "1.4.0"

View file

@ -1,5 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use log::debug; use log::debug;
use log::error; use log::error;
@ -23,7 +25,7 @@ impl fmt::Display for AuthToken {
AuthTokenData::Bearer(token) => write!(f, "Bearer {token}"), AuthTokenData::Bearer(token) => write!(f, "Bearer {token}"),
AuthTokenData::Basic { username, password } => { AuthTokenData::Basic { username, password } => {
let credentials = format!("{username}:{password}"); let credentials = format!("{username}:{password}");
write!(f, "Basic {}", base64::encode(credentials)) write!(f, "Basic {}", BASE64_STANDARD.encode(credentials))
} }
} }
} }

View file

@ -5,6 +5,8 @@ use std::fs;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use deno_core::anyhow::bail; use deno_core::anyhow::bail;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_npm::registry::NpmPackageVersionDistInfo; use deno_npm::registry::NpmPackageVersionDistInfo;
@ -52,7 +54,7 @@ fn verify_tarball_integrity(
let mut hash_ctx = Context::new(algo); let mut hash_ctx = Context::new(algo);
hash_ctx.update(data); hash_ctx.update(data);
let digest = hash_ctx.finish(); let digest = hash_ctx.finish();
let tarball_checksum = base64::encode(digest.as_ref()); let tarball_checksum = BASE64_STANDARD.encode(digest.as_ref());
(tarball_checksum, base64_hash) (tarball_checksum, base64_hash)
} }
NpmPackageVersionDistInfoIntegrity::LegacySha1Hex(hex) => { NpmPackageVersionDistInfoIntegrity::LegacySha1Hex(hex) => {

View file

@ -1,5 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use deno_core::ModuleCode; use deno_core::ModuleCode;
use encoding_rs::*; use encoding_rs::*;
use std::borrow::Cow; use std::borrow::Cow;
@ -62,7 +64,8 @@ pub fn source_map_from_code(code: &ModuleCode) -> Option<Vec<u8>> {
let last_line = bytes.rsplit(|u| *u == b'\n').next()?; let last_line = bytes.rsplit(|u| *u == b'\n').next()?;
if last_line.starts_with(SOURCE_MAP_PREFIX) { if last_line.starts_with(SOURCE_MAP_PREFIX) {
let input = last_line.split_at(SOURCE_MAP_PREFIX.len()).1; let input = last_line.split_at(SOURCE_MAP_PREFIX.len()).1;
let decoded_map = base64::decode(input) let decoded_map = BASE64_STANDARD
.decode(input)
.expect("Unable to decode source map from emitted file."); .expect("Unable to decode source map from emitted file.");
Some(decoded_map) Some(decoded_map)
} else { } else {

View file

@ -1,5 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use base64::prelude::BASE64_URL_SAFE_NO_PAD;
use base64::Engine;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::op2; use deno_core::op2;
use deno_core::ToJsBuffer; use deno_core::ToJsBuffer;
@ -151,8 +153,5 @@ pub fn op_crypto_jwk_x_ed25519(
#[buffer] pkey: &[u8], #[buffer] pkey: &[u8],
) -> Result<String, AnyError> { ) -> Result<String, AnyError> {
let pair = Ed25519KeyPair::from_seed_unchecked(pkey)?; let pair = Ed25519KeyPair::from_seed_unchecked(pkey)?;
Ok(base64::encode_config( Ok(BASE64_URL_SAFE_NO_PAD.encode(pair.public_key().as_ref()))
pair.public_key().as_ref(),
base64::URL_SAFE_NO_PAD,
))
} }

View file

@ -1,5 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use base64::prelude::BASE64_URL_SAFE_NO_PAD;
use base64::Engine;
use const_oid::AssociatedOid; use const_oid::AssociatedOid;
use const_oid::ObjectIdentifier; use const_oid::ObjectIdentifier;
use deno_core::error::custom_error; use deno_core::error::custom_error;
@ -111,11 +113,11 @@ pub fn op_crypto_export_key(
} }
fn uint_to_b64(bytes: UIntRef) -> String { fn uint_to_b64(bytes: UIntRef) -> String {
base64::encode_config(bytes.as_bytes(), base64::URL_SAFE_NO_PAD) BASE64_URL_SAFE_NO_PAD.encode(bytes.as_bytes())
} }
fn bytes_to_b64(bytes: &[u8]) -> String { fn bytes_to_b64(bytes: &[u8]) -> String {
base64::encode_config(bytes, base64::URL_SAFE_NO_PAD) BASE64_URL_SAFE_NO_PAD.encode(bytes)
} }
fn export_key_rsa( fn export_key_rsa(

View file

@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use base64::Engine;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::op2; use deno_core::op2;
use deno_core::JsBuffer; use deno_core::JsBuffer;
@ -106,12 +107,19 @@ pub fn op_crypto_import_key(
} }
} }
const URL_SAFE_FORGIVING: base64::Config = const BASE64_URL_SAFE_FORGIVING:
base64::URL_SAFE_NO_PAD.decode_allow_trailing_bits(true); base64::engine::general_purpose::GeneralPurpose =
base64::engine::general_purpose::GeneralPurpose::new(
&base64::alphabet::URL_SAFE,
base64::engine::general_purpose::GeneralPurposeConfig::new()
.with_decode_allow_trailing_bits(true)
.with_decode_padding_mode(base64::engine::DecodePaddingMode::Indifferent),
);
macro_rules! jwt_b64_int_or_err { macro_rules! jwt_b64_int_or_err {
($name:ident, $b64:expr, $err:expr) => { ($name:ident, $b64:expr, $err:expr) => {
let bytes = base64::decode_config($b64, URL_SAFE_FORGIVING) let bytes = BASE64_URL_SAFE_FORGIVING
.decode($b64)
.map_err(|_| data_error($err))?; .map_err(|_| data_error($err))?;
let $name = UIntRef::new(&bytes).map_err(|_| data_error($err))?; let $name = UIntRef::new(&bytes).map_err(|_| data_error($err))?;
}; };
@ -759,7 +767,8 @@ fn import_key_ec(
fn import_key_aes(key_data: KeyData) -> Result<ImportKeyResult, AnyError> { fn import_key_aes(key_data: KeyData) -> Result<ImportKeyResult, AnyError> {
Ok(match key_data { Ok(match key_data {
KeyData::JwkSecret { k } => { KeyData::JwkSecret { k } => {
let data = base64::decode_config(k, URL_SAFE_FORGIVING) let data = BASE64_URL_SAFE_FORGIVING
.decode(k)
.map_err(|_| data_error("invalid key data"))?; .map_err(|_| data_error("invalid key data"))?;
ImportKeyResult::Hmac { ImportKeyResult::Hmac {
raw_data: RustRawKeyData::Secret(data.into()), raw_data: RustRawKeyData::Secret(data.into()),
@ -772,7 +781,8 @@ fn import_key_aes(key_data: KeyData) -> Result<ImportKeyResult, AnyError> {
fn import_key_hmac(key_data: KeyData) -> Result<ImportKeyResult, AnyError> { fn import_key_hmac(key_data: KeyData) -> Result<ImportKeyResult, AnyError> {
Ok(match key_data { Ok(match key_data {
KeyData::JwkSecret { k } => { KeyData::JwkSecret { k } => {
let data = base64::decode_config(k, URL_SAFE_FORGIVING) let data = BASE64_URL_SAFE_FORGIVING
.decode(k)
.map_err(|_| data_error("invalid key data"))?; .map_err(|_| data_error("invalid key data"))?;
ImportKeyResult::Hmac { ImportKeyResult::Hmac {
raw_data: RustRawKeyData::Secret(data.into()), raw_data: RustRawKeyData::Secret(data.into()),

View file

@ -4,6 +4,8 @@ use aes_kw::KekAes128;
use aes_kw::KekAes192; use aes_kw::KekAes192;
use aes_kw::KekAes256; use aes_kw::KekAes256;
use base64::prelude::BASE64_URL_SAFE_NO_PAD;
use base64::Engine;
use deno_core::error::custom_error; use deno_core::error::custom_error;
use deno_core::error::not_supported; use deno_core::error::not_supported;
use deno_core::error::type_error; use deno_core::error::type_error;
@ -120,14 +122,14 @@ deno_core::extension!(deno_crypto,
pub fn op_crypto_base64url_decode( pub fn op_crypto_base64url_decode(
#[string] data: String, #[string] data: String,
) -> Result<ToJsBuffer, AnyError> { ) -> Result<ToJsBuffer, AnyError> {
let data: Vec<u8> = base64::decode_config(data, base64::URL_SAFE_NO_PAD)?; let data: Vec<u8> = BASE64_URL_SAFE_NO_PAD.decode(data)?;
Ok(data.into()) Ok(data.into())
} }
#[op2] #[op2]
#[string] #[string]
pub fn op_crypto_base64url_encode(#[buffer] data: JsBuffer) -> String { pub fn op_crypto_base64url_encode(#[buffer] data: JsBuffer) -> String {
let data: String = base64::encode_config(data, base64::URL_SAFE_NO_PAD); let data: String = BASE64_URL_SAFE_NO_PAD.encode(data);
data data
} }

View file

@ -3,6 +3,8 @@
use async_compression::tokio::write::BrotliEncoder; use async_compression::tokio::write::BrotliEncoder;
use async_compression::tokio::write::GzipEncoder; use async_compression::tokio::write::GzipEncoder;
use async_compression::Level; use async_compression::Level;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use cache_control::CacheControl; use cache_control::CacheControl;
use deno_core::error::custom_error; use deno_core::error::custom_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
@ -990,7 +992,7 @@ fn op_http_websocket_accept_header(
&ring::digest::SHA1_FOR_LEGACY_USE_ONLY, &ring::digest::SHA1_FOR_LEGACY_USE_ONLY,
format!("{key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11").as_bytes(), format!("{key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11").as_bytes(),
); );
Ok(base64::encode(digest)) Ok(BASE64_STANDARD.encode(digest))
} }
#[op2(async)] #[op2(async)]

View file

@ -12,6 +12,8 @@ use std::cell::RefCell;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::rc::Rc; use std::rc::Rc;
use base64::prelude::BASE64_URL_SAFE;
use base64::Engine;
use chrono::Utc; use chrono::Utc;
use codec::decode_key; use codec::decode_key;
use codec::encode_key; use codec::encode_key;
@ -543,11 +545,7 @@ fn encode_cursor(
if !boundary_key.starts_with(common_prefix) { if !boundary_key.starts_with(common_prefix) {
return Err(type_error("invalid boundary key")); return Err(type_error("invalid boundary key"));
} }
Ok(BASE64_URL_SAFE.encode(&boundary_key[common_prefix.len()..]))
Ok(base64::encode_config(
&boundary_key[common_prefix.len()..],
base64::URL_SAFE,
))
} }
fn decode_selector_and_cursor( fn decode_selector_and_cursor(
@ -560,7 +558,8 @@ fn decode_selector_and_cursor(
}; };
let common_prefix = selector.common_prefix(); let common_prefix = selector.common_prefix();
let cursor = base64::decode_config(cursor, base64::URL_SAFE) let cursor = BASE64_URL_SAFE
.decode(cursor)
.map_err(|_| type_error("invalid cursor"))?; .map_err(|_| type_error("invalid cursor"))?;
let first_key: Vec<u8>; let first_key: Vec<u8>;

View file

@ -2,6 +2,8 @@
// Usage: provide a port as argument to run hyper_hello benchmark server // Usage: provide a port as argument to run hyper_hello benchmark server
// otherwise this starts multiple servers on many ports for test endpoints. // otherwise this starts multiple servers on many ports for test endpoints.
use anyhow::anyhow; use anyhow::anyhow;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use futures::Future; use futures::Future;
use futures::FutureExt; use futures::FutureExt;
use futures::Stream; use futures::Stream;
@ -317,7 +319,7 @@ async fn basic_auth_redirect(
{ {
let credentials = let credentials =
format!("{TEST_BASIC_AUTH_USERNAME}:{TEST_BASIC_AUTH_PASSWORD}"); format!("{TEST_BASIC_AUTH_USERNAME}:{TEST_BASIC_AUTH_PASSWORD}");
if auth == format!("Basic {}", base64::encode(credentials)) { if auth == format!("Basic {}", BASE64_STANDARD.encode(credentials)) {
let p = req.uri().path(); let p = req.uri().path();
assert_eq!(&p[0..1], "/"); assert_eq!(&p[0..1], "/");
let url = format!("http://localhost:{PORT}{p}"); let url = format!("http://localhost:{PORT}{p}");

View file

@ -5,6 +5,8 @@ use std::fs;
use anyhow::Context; use anyhow::Context;
use anyhow::Result; use anyhow::Result;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use flate2::write::GzEncoder; use flate2::write::GzEncoder;
use flate2::Compression; use flate2::Compression;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -104,7 +106,7 @@ fn get_npm_package(package_name: &str) -> Result<Option<CustomNpmPackage>> {
let mut hash_ctx = Context::new(&SHA512); let mut hash_ctx = Context::new(&SHA512);
hash_ctx.update(&tarball_bytes); hash_ctx.update(&tarball_bytes);
let digest = hash_ctx.finish(); let digest = hash_ctx.finish();
let tarball_checksum = base64::encode(digest.as_ref()); let tarball_checksum = BASE64_STANDARD.encode(digest.as_ref());
// create the registry file JSON for this version // create the registry file JSON for this version
let mut dist = serde_json::Map::new(); let mut dist = serde_json::Map::new();