summaryrefslogtreecommitdiffstats
path: root/src/hash.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.rs')
-rw-r--r--src/hash.rs13
1 files changed, 0 insertions, 13 deletions
diff --git a/src/hash.rs b/src/hash.rs
index 70c3791..f638542 100644
--- a/src/hash.rs
+++ b/src/hash.rs
@@ -13,15 +13,11 @@ pub fn hex_str(s: &str) -> String {
hex(s.as_bytes())
}
-/// First `n` hex chars — enough for display, not for identity.
pub fn short(bytes: &[u8], n: usize) -> String {
let h = hex(bytes);
h[..n.min(h.len())].to_string()
}
-/// Stream-hash a reader, optionally teeing every byte into `sink` — so a
-/// download can be hashed into the source cache without paying for the
-/// bandwidth twice (§5.3).
pub fn digest_reader<R: Read>(mut r: R, mut sink: Option<&mut dyn Write>) -> io::Result<(String, u64)> {
let mut h = Sha256::new();
let mut buf = vec![0u8; 64 * 1024];
@@ -46,9 +42,6 @@ pub fn digest_file(path: &std::path::Path) -> io::Result<(String, u64)> {
digest_reader(&mut br, None)
}
-/// This is `recipe_hash` (DESIGN.md §3): a digest over *every* file in the AUR
-/// snapshot tree, because a patch shipped in the AUR repo is part of the recipe
-/// and is a classic silent-change vector.
pub fn recipe_hash(entries: &[(String, String)]) -> String {
let mut sorted: Vec<&(String, String)> = entries.iter().collect();
sorted.sort_unstable_by(|a, b| a.0.cmp(&b.0));
@@ -62,12 +55,6 @@ pub fn recipe_hash(entries: &[(String, String)]) -> String {
hex::encode(h.finalize())
}
-/// Serialize to canonical JSON: compact, object keys sorted, so equal values always
-/// produce equal bytes. The value is routed through `serde_json::Value` because a
-/// struct otherwise serializes in field declaration order.
-///
-/// A serialization failure is an error, not `"{}"`: this is the function behind
-/// `Identity::hash` (M-2).
pub fn canonical_json<T: serde::Serialize>(v: &T) -> Result<String, serde_json::Error> {
serde_json::to_string(&serde_json::to_value(v)?)
}