diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 17:09:59 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 17:09:59 +0000 |
| commit | e757979f1a2afdbe7146066345bb9acd19d3b151 (patch) | |
| tree | 30d5f5fbccd25ea7bf01c5202684af463b74e7d3 /src/hash.rs | |
| parent | 94c318f13264bb3c00a9f3057ba2e1aafb57c9e4 (diff) | |
| download | aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.tar.gz aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.zip | |
comments: say why, not what
Every module-level `//!` header is gone, and the comments that remained
either re-explained the line below them or had grown into paragraphs.
Density went from one comment line per 6.7 lines of code to one per 10.
827 insertions against 2194 deletions across 86 files.
What survived: the invariants (I1-I12), the design cross-references into
DESIGN.md, and the notes recording a bug that was found and fixed — those
are the comments that carry weight, because they answer a question the
code cannot answer about itself. What did not: restating a function
signature in prose, and narration of the statement underneath.
Diffstat (limited to 'src/hash.rs')
| -rw-r--r-- | src/hash.rs | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/src/hash.rs b/src/hash.rs index 0321437..70c3791 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -1,6 +1,3 @@ -//! Hashing helpers. `sha256` hex strings are the currency of identity and -//! provenance throughout the system (DESIGN.md §3, §5.3). - use sha2::{Digest, Sha256}; use std::io::{self, Read, Write}; @@ -22,10 +19,9 @@ pub fn short(bytes: &[u8], n: usize) -> String { h[..n.min(h.len())].to_string() } -/// Stream-hash a reader, optionally teeing every byte into `sink`. -/// -/// Used to hash a download while writing it into the source cache, so the -/// bandwidth is paid for once (§5.3 "stream-hash, don't buffer"). +/// 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]; @@ -50,11 +46,8 @@ pub fn digest_file(path: &std::path::Path) -> io::Result<(String, u64)> { digest_reader(&mut br, None) } -/// Hash of a canonical, sorted list of `(path, blob_hash)` pairs. -/// /// This is `recipe_hash` (DESIGN.md §3): a digest over *every* file in the AUR -/// snapshot tree — PKGBUILD, .SRCINFO, *.install and any shipped patches or -/// assets — because a patch file shipped in the AUR repo is part of the recipe +/// 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(); @@ -69,17 +62,12 @@ pub fn recipe_hash(entries: &[(String, String)]) -> String { hex::encode(h.finalize()) } -/// Serialize a value to canonical JSON: compact, with every object's keys in -/// sorted order, so equal values always produce equal bytes. -/// -/// The ordering is not free in `serde_json` — a struct serializes in field -/// declaration order and a map in whatever order it happens to hold — so the -/// value is routed through `serde_json::Value`, whose map is a `BTreeMap`. -/// That makes the name true rather than aspirational. +/// 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. It used to be `"{}"`, which meant every -/// value that failed to serialize hashed to the same digest — and this is the -/// function behind `Identity::hash`, the value an approval echoes (§6 M-2). +/// 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)?) } |
