-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
bugSomething isn't workingSomething isn't working
Description
The calculation results do not match those obtained using other tools such as Amule , emule LinkCreator. ChatGPT says Write() will never handle “that last incomplete chunk.”
hashit/vendor/go.felesatra.moe/hash/ed2k/ed2k.go
Lines 52 to 65 in dab96e6
| func (h *Hash) Write(p []byte) (int, error) { | |
| total := len(p) | |
| for len(p) > 0 { | |
| p2 := h.limitNextChunk(p) | |
| n, _ := h.subhash.Write(p2) | |
| h.written += int64(n) | |
| p = p[n:] | |
| if h.written%ChunkSize == 0 { | |
| h.hashlist = h.subhash.Sum(h.hashlist) | |
| h.subhash.Reset() | |
| } | |
| } | |
| return total, nil | |
| } |
hashit/vendor/go.felesatra.moe/hash/ed2k/ed2k.go
Lines 78 to 88 in dab96e6
| func (h *Hash) Sum(b []byte) []byte { | |
| if h.written < ChunkSize { | |
| return h.subhash.Sum(b) | |
| } | |
| if h.written == ChunkSize { | |
| return append(b, h.hashlist...) | |
| } | |
| h2 := md4.New() | |
| h2.Write(h.hashlist) | |
| return h2.Sum(b) | |
| } |
// Provided by ChatGPT
func (h *Hash) Sum(b []byte) []byte {
if h.written == 0 {
return h.subhash.Sum(b)
}
// uncommited chunk
if h.written%ChunkSize != 0 {
h.hashlist = h.subhash.Sum(h.hashlist)
}
if h.written <= ChunkSize {
return append(b, h.hashlist...)
}
h2 := md4.New()
h2.Write(h.hashlist)
return h2.Sum(b)
}
Reference:
https://wiki.anidb.net/Ed2k-hash#How_is_an_ed2k_hash_calculated_exactly?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working