From ddb94deafad959c7a3ad1e34bbf2184fcec1a0f9 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 17 Apr 2024 11:31:23 -0400 Subject: prefetch-npm-deps: switch to data-encoding --- pkgs/build-support/node/fetch-npm-deps/Cargo.lock | 14 +++++++------- pkgs/build-support/node/fetch-npm-deps/Cargo.toml | 2 +- pkgs/build-support/node/fetch-npm-deps/src/cacache.rs | 10 ++++++---- pkgs/build-support/node/fetch-npm-deps/src/util.rs | 7 ++----- 4 files changed, 16 insertions(+), 17 deletions(-) (limited to 'pkgs') diff --git a/pkgs/build-support/node/fetch-npm-deps/Cargo.lock b/pkgs/build-support/node/fetch-npm-deps/Cargo.lock index 71b9caba13d5..dcabca0aeafd 100644 --- a/pkgs/build-support/node/fetch-npm-deps/Cargo.lock +++ b/pkgs/build-support/node/fetch-npm-deps/Cargo.lock @@ -93,12 +93,6 @@ dependencies = [ "rand", ] -[[package]] -name = "base64" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" - [[package]] name = "bitflags" version = "1.3.2" @@ -239,6 +233,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "data-encoding" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" + [[package]] name = "digest" version = "0.10.7" @@ -592,7 +592,7 @@ version = "0.1.0" dependencies = [ "anyhow", "backoff", - "base64", + "data-encoding", "digest", "env_logger", "isahc", diff --git a/pkgs/build-support/node/fetch-npm-deps/Cargo.toml b/pkgs/build-support/node/fetch-npm-deps/Cargo.toml index bb164bc6a983..dcb7e28a49dd 100644 --- a/pkgs/build-support/node/fetch-npm-deps/Cargo.toml +++ b/pkgs/build-support/node/fetch-npm-deps/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] anyhow = "1.0.82" backoff = "0.4.0" -base64 = "0.22.0" +data-encoding = "2.5.0" digest = "0.10.7" env_logger = "0.11.3" isahc = { version = "1.7.2", default_features = false } diff --git a/pkgs/build-support/node/fetch-npm-deps/src/cacache.rs b/pkgs/build-support/node/fetch-npm-deps/src/cacache.rs index 8c6845d6ac5a..403c909dee11 100644 --- a/pkgs/build-support/node/fetch-npm-deps/src/cacache.rs +++ b/pkgs/build-support/node/fetch-npm-deps/src/cacache.rs @@ -1,4 +1,4 @@ -use base64::prelude::{Engine, BASE64_STANDARD}; +use data_encoding::BASE64; use digest::{Digest, Update}; use serde::{Deserialize, Serialize}; use sha1::Sha1; @@ -60,16 +60,18 @@ impl Cache { integrity: Option, ) -> anyhow::Result<()> { let (algo, hash, integrity) = if let Some(integrity) = integrity { - let (algo, hash) = integrity.split_once('-').unwrap(); + let (algo, hash) = integrity + .split_once('-') + .expect("hash should be SRI format"); - (algo.to_string(), BASE64_STANDARD.decode(hash)?, integrity) + (algo.to_string(), BASE64.decode(hash.as_bytes())?, integrity) } else { let hash = Sha512::new().chain(data).finalize(); ( String::from("sha512"), hash.to_vec(), - format!("sha512-{}", BASE64_STANDARD.encode(hash)), + format!("sha512-{}", BASE64.encode(&hash)), ) }; diff --git a/pkgs/build-support/node/fetch-npm-deps/src/util.rs b/pkgs/build-support/node/fetch-npm-deps/src/util.rs index 76f15db03d46..023ba56793b9 100644 --- a/pkgs/build-support/node/fetch-npm-deps/src/util.rs +++ b/pkgs/build-support/node/fetch-npm-deps/src/util.rs @@ -1,5 +1,5 @@ use backoff::{retry, ExponentialBackoff}; -use base64::prelude::{Engine, BASE64_STANDARD}; +use data_encoding::BASE64; use digest::Digest; use isahc::{ config::{CaCertificate, Configurable, RedirectPolicy, SslOption}, @@ -79,8 +79,5 @@ pub fn make_sri_hash(path: &Path) -> Result { io::copy(&mut encoder, &mut hasher)?; - Ok(format!( - "sha256-{}", - BASE64_STANDARD.encode(hasher.finalize()) - )) + Ok(format!("sha256-{}", BASE64.encode(&hasher.finalize()))) } -- cgit 1.4.1