prefetch-npm-deps: switch to data-encoding

authored by Lily Foster and committed by tomf ddb94dea c588edaf

+16 -17
+7 -7
pkgs/build-support/node/fetch-npm-deps/Cargo.lock
··· 94 94 ] 95 95 96 96 [[package]] 97 - name = "base64" 98 - version = "0.22.0" 99 - source = "registry+https://github.com/rust-lang/crates.io-index" 100 - checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" 101 - 102 - [[package]] 103 97 name = "bitflags" 104 98 version = "1.3.2" 105 99 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 238 232 "vcpkg", 239 233 "windows-sys 0.52.0", 240 234 ] 235 + 236 + [[package]] 237 + name = "data-encoding" 238 + version = "2.5.0" 239 + source = "registry+https://github.com/rust-lang/crates.io-index" 240 + checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" 241 241 242 242 [[package]] 243 243 name = "digest" ··· 592 592 dependencies = [ 593 593 "anyhow", 594 594 "backoff", 595 - "base64", 595 + "data-encoding", 596 596 "digest", 597 597 "env_logger", 598 598 "isahc",
+1 -1
pkgs/build-support/node/fetch-npm-deps/Cargo.toml
··· 8 8 [dependencies] 9 9 anyhow = "1.0.82" 10 10 backoff = "0.4.0" 11 - base64 = "0.22.0" 11 + data-encoding = "2.5.0" 12 12 digest = "0.10.7" 13 13 env_logger = "0.11.3" 14 14 isahc = { version = "1.7.2", default_features = false }
+6 -4
pkgs/build-support/node/fetch-npm-deps/src/cacache.rs
··· 1 - use base64::prelude::{Engine, BASE64_STANDARD}; 1 + use data_encoding::BASE64; 2 2 use digest::{Digest, Update}; 3 3 use serde::{Deserialize, Serialize}; 4 4 use sha1::Sha1; ··· 60 60 integrity: Option<String>, 61 61 ) -> anyhow::Result<()> { 62 62 let (algo, hash, integrity) = if let Some(integrity) = integrity { 63 - let (algo, hash) = integrity.split_once('-').unwrap(); 63 + let (algo, hash) = integrity 64 + .split_once('-') 65 + .expect("hash should be SRI format"); 64 66 65 - (algo.to_string(), BASE64_STANDARD.decode(hash)?, integrity) 67 + (algo.to_string(), BASE64.decode(hash.as_bytes())?, integrity) 66 68 } else { 67 69 let hash = Sha512::new().chain(data).finalize(); 68 70 69 71 ( 70 72 String::from("sha512"), 71 73 hash.to_vec(), 72 - format!("sha512-{}", BASE64_STANDARD.encode(hash)), 74 + format!("sha512-{}", BASE64.encode(&hash)), 73 75 ) 74 76 }; 75 77
+2 -5
pkgs/build-support/node/fetch-npm-deps/src/util.rs
··· 1 1 use backoff::{retry, ExponentialBackoff}; 2 - use base64::prelude::{Engine, BASE64_STANDARD}; 2 + use data_encoding::BASE64; 3 3 use digest::Digest; 4 4 use isahc::{ 5 5 config::{CaCertificate, Configurable, RedirectPolicy, SslOption}, ··· 79 79 80 80 io::copy(&mut encoder, &mut hasher)?; 81 81 82 - Ok(format!( 83 - "sha256-{}", 84 - BASE64_STANDARD.encode(hasher.finalize()) 85 - )) 82 + Ok(format!("sha256-{}", BASE64.encode(&hasher.finalize()))) 86 83 }