Commit ddb94dea authored by Lily Foster's avatar Lily Foster Committed by tomf
Browse files

prefetch-npm-deps: switch to data-encoding

parent c588edaf
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -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",
+1 −1
Original line number Diff line number Diff line
@@ -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 }
+6 −4
Original line number Diff line number Diff line
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<String>,
    ) -> 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)),
            )
        };

+2 −5
Original line number Diff line number Diff line
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<String, NarError> {

    io::copy(&mut encoder, &mut hasher)?;

    Ok(format!(
        "sha256-{}",
        BASE64_STANDARD.encode(hasher.finalize())
    ))
    Ok(format!("sha256-{}", BASE64.encode(&hasher.finalize())))
}