Skip to content

Commit

Permalink
chore: update hash format
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn committed Mar 30, 2024
1 parent db3e10a commit 801446c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ fn generate_cache_key(lockfile: &Lockfile, project: &ProjectRoot) -> Result<Hash
Ok(Hash(
format!(
"{}-{}",
&lockfile_hash.to_string()[..16].to_lowercase(),
&project_hash.to_string()[..16].to_lowercase()
&lockfile_hash.to_string(),
&project_hash.to_string()
)
.to_string(),
))
Expand Down
8 changes: 4 additions & 4 deletions src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ mod tests {
test_generate_hash_each,
"npm" => GenerateHashTestCase {
input: "./tests/fixtures/lockfile/npm",
expected: "XDFOLU2UD2LVKFHRTUP3P33GLGTXQG4IGRLDYMT3P6QFI2F3CTJQ====",
expected: "xdfolu2ud2lvkfhrtup3p33glgtxqg4i",
},
"yarn" => GenerateHashTestCase {
input: "./tests/fixtures/lockfile/yarn",
expected: "OZWLYHFK4D5ZS2ZPB4VJ2JVHBM3LHG7OOOBRAOUVV5M5WOD3DCOQ====",
expected: "ozwlyhfk4d5zs2zpb4vj2jvhbm3lhg7o",
},
"pnpm" => GenerateHashTestCase {
input: "./tests/fixtures/lockfile/pnpm",
expected: "4YOMPZFFG476HX3S6EYC2V3ZTCBGWFEJ3DSSPRYIE6UDYKZJVFFQ====",
expected: "4yompzffg476hx3s6eyc2v3ztcbgwfej",
},
"bun" => GenerateHashTestCase {
input: "./tests/fixtures/lockfile/bun",
expected: "QUBT74WRMOCA7VURUV3XNFAACLZVMVWMVC5VDKNLFBEMOB6KREYA====",
expected: "qubt74wrmoca7vuruv3xnfaaclzvmvwm",
},
);
}
4 changes: 2 additions & 2 deletions src/utils/hash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::{Debug, Display};

use data_encoding::BASE32;
use data_encoding::BASE32_NOPAD;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

Expand Down Expand Up @@ -31,7 +31,7 @@ pub trait Hashable {
let mut generator = Sha256::new();
generator.update(bytes);
let raw_hash = generator.finalize();
let hash = BASE32.encode(&raw_hash);
let hash = BASE32_NOPAD.encode(&raw_hash[..20]).to_lowercase();
Ok(Hash(hash))
}
Err(error) => Err(to_error(error)),
Expand Down

0 comments on commit 801446c

Please sign in to comment.