Skip to content

Commit a85ae2a

Browse files
committed
revert: restore original Hash function, add TODO for SHA-256 upgrade
1 parent 5013fe1 commit a85ae2a

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

mdl/types/id.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,14 @@ func ValidateID(id string) bool {
106106
return true
107107
}
108108

109-
// Hash computes a SHA-256 hash for content (used for content deduplication).
109+
// Hash computes a hash for content (used for content deduplication).
110+
// TODO: replace with SHA-256 (or similar) — the current positional checksum is
111+
// weak and produces collisions easily. Deferred to avoid breaking callers that
112+
// may depend on the output format/length.
110113
func Hash(content []byte) string {
111-
h := sha256.Sum256(content)
112-
return hex.EncodeToString(h[:])
114+
var sum uint64
115+
for i, b := range content {
116+
sum += uint64(b) * uint64(i+1)
117+
}
118+
return fmt.Sprintf("%016x", sum)
113119
}

mdl/types/id_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ func TestHash_DifferentInputs(t *testing.T) {
187187

188188
func TestHash_EmptyInput(t *testing.T) {
189189
h := Hash([]byte{})
190-
// SHA-256 of empty input is well-defined (not zero).
191-
expected := "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
192-
if h != expected {
193-
t.Errorf("expected SHA-256 of empty input, got %q", h)
190+
if h != "0000000000000000" {
191+
t.Errorf("expected zero hash for empty input, got %q", h)
194192
}
195193
}

0 commit comments

Comments
 (0)