panic if hash returns an error

Add a sanity check that the interface contract is honoured.
This commit is contained in:
Michael Eischer
2021-08-04 22:17:46 +02:00
parent 51b7e3119b
commit 7c1903e1ee
4 changed files with 16 additions and 4 deletions
+4 -1
View File
@@ -56,7 +56,10 @@ func NewByteReader(buf []byte, hasher hash.Hash) *ByteReader {
var hash []byte
if hasher != nil {
// must never fail according to interface
_, _ = hasher.Write(buf)
_, err := hasher.Write(buf)
if err != nil {
panic(err)
}
hash = hasher.Sum(nil)
}
return &ByteReader{
+4 -1
View File
@@ -54,7 +54,10 @@ func TestFileReader(t *testing.T) {
var hash []byte
if hasher != nil {
// must never fail according to interface
_, _ = hasher.Write(buf)
_, err := hasher.Write(buf)
if err != nil {
panic(err)
}
hash = hasher.Sum(nil)
}
rd, err := NewFileReader(f, hash)