feat: first cut on M0 - base structure of project

This commit is contained in:
2026-04-02 21:00:18 +02:00
parent 1a24027723
commit 1c3a088efb
40 changed files with 7471 additions and 2 deletions

View File

@@ -0,0 +1,48 @@
use sha2::{Digest, Sha256};
/// Compute a hex-encoded SHA-256 hash of the given content.
pub fn content_hash(content: &[u8]) -> String {
let mut hasher = Sha256::new();
hasher.update(content);
let result = hasher.finalize();
hex::encode(result)
}
// sha2 doesn't include hex encoding, so we use a tiny inline helper.
mod hex {
const HEX_CHARS: &[u8; 16] = b"0123456789abcdef";
pub fn encode(bytes: impl AsRef<[u8]>) -> String {
let bytes = bytes.as_ref();
let mut s = String::with_capacity(bytes.len() * 2);
for &b in bytes {
s.push(HEX_CHARS[(b >> 4) as usize] as char);
s.push(HEX_CHARS[(b & 0xf) as usize] as char);
}
s
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn known_hash() {
// SHA-256 of "hello"
let hash = content_hash(b"hello");
assert_eq!(
hash,
"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
);
}
#[test]
fn empty_hash() {
let hash = content_hash(b"");
assert_eq!(
hash,
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
);
}
}