treewide: remove dead code

Also deletes some dead_code annotations from functions that are
*actually used*.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ic815cacc93c464078ead1674e7523d8b6a6a6964
This commit is contained in:
raf 2026-02-28 23:08:26 +03:00
commit f4287de795
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 30 additions and 112 deletions

View file

@ -10,58 +10,6 @@ use sha2::{Sha256, Sha512};
use crate::error::{PakkerError, Result};
/// Compute Murmur2 hash (32-bit) for `CurseForge` fingerprinting
#[allow(dead_code)]
pub fn compute_murmur2_hash(data: &[u8]) -> u32 {
murmur2_hash(data, 1)
}
/// Murmur2 hash implementation
#[allow(dead_code)]
fn murmur2_hash(data: &[u8], seed: u32) -> u32 {
const M: u32 = 0x5BD1E995;
const R: i32 = 24;
let mut h: u32 = seed ^ (data.len() as u32);
let mut chunks = data.chunks_exact(4);
for chunk in chunks.by_ref() {
let mut k = u32::from_le_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]);
k = k.wrapping_mul(M);
k ^= k >> R;
k = k.wrapping_mul(M);
h = h.wrapping_mul(M);
h ^= k;
}
let remainder = chunks.remainder();
match remainder.len() {
3 => {
h ^= u32::from(remainder[2]) << 16;
h ^= u32::from(remainder[1]) << 8;
h ^= u32::from(remainder[0]);
h = h.wrapping_mul(M);
},
2 => {
h ^= u32::from(remainder[1]) << 8;
h ^= u32::from(remainder[0]);
h = h.wrapping_mul(M);
},
1 => {
h ^= u32::from(remainder[0]);
h = h.wrapping_mul(M);
},
_ => {},
}
h ^= h >> 13;
h = h.wrapping_mul(M);
h ^= h >> 15;
h
}
/// Compute SHA1 hash of a file
pub fn compute_sha1<P: AsRef<Path>>(path: P) -> Result<String> {
let file = File::open(path)?;
@ -167,31 +115,6 @@ pub fn verify_hash<P: AsRef<Path>>(
mod tests {
use super::*;
#[test]
fn test_murmur2_hash_deterministic() {
let data = b"hello world";
let hash1 = compute_murmur2_hash(data);
let hash2 = compute_murmur2_hash(data);
assert_eq!(hash1, hash2, "Murmur2 hash must be deterministic");
}
#[test]
fn test_murmur2_hash_empty() {
let data = b"";
let hash = compute_murmur2_hash(data);
assert_ne!(hash, 0, "Empty data should produce a non-zero hash");
}
#[test]
fn test_murmur2_hash_different_inputs() {
let hash1 = compute_murmur2_hash(b"hello");
let hash2 = compute_murmur2_hash(b"world");
assert_ne!(
hash1, hash2,
"Different inputs should produce different hashes"
);
}
#[test]
fn test_sha256_bytes_deterministic() {
let data = b"test data";