mirror of
https://github.com/octoleo/restic.git
synced 2024-11-23 05:12:10 +00:00
panic if hash returns an error
Add a sanity check that the interface contract is honoured.
This commit is contained in:
parent
51b7e3119b
commit
7c1903e1ee
@ -91,7 +91,10 @@ func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Re
|
|||||||
|
|
||||||
beHash := be.Hasher()
|
beHash := be.Hasher()
|
||||||
// must never fail according to interface
|
// must never fail according to interface
|
||||||
_, _ = beHash.Write(buf)
|
_, err = beHash.Write(buf)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
if !bytes.Equal(beHash.Sum(nil), rd.Hash()) {
|
if !bytes.Equal(beHash.Sum(nil), rd.Hash()) {
|
||||||
return errors.Errorf("invalid file hash or content, got %s expected %s",
|
return errors.Errorf("invalid file hash or content, got %s expected %s",
|
||||||
base64.RawStdEncoding.EncodeToString(beHash.Sum(nil)),
|
base64.RawStdEncoding.EncodeToString(beHash.Sum(nil)),
|
||||||
|
@ -547,7 +547,10 @@ func (s *Suite) TestSave(t *testing.T) {
|
|||||||
if b.Hasher() != nil {
|
if b.Hasher() != nil {
|
||||||
beHasher := b.Hasher()
|
beHasher := b.Hasher()
|
||||||
// must never fail according to interface
|
// must never fail according to interface
|
||||||
_, _ = beHasher.Write(data)
|
_, err := beHasher.Write(data)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
beHash = beHasher.Sum(nil)
|
beHash = beHasher.Sum(nil)
|
||||||
}
|
}
|
||||||
err = b.Save(context.TODO(), h, errorCloser{
|
err = b.Save(context.TODO(), h, errorCloser{
|
||||||
|
@ -56,7 +56,10 @@ func NewByteReader(buf []byte, hasher hash.Hash) *ByteReader {
|
|||||||
var hash []byte
|
var hash []byte
|
||||||
if hasher != nil {
|
if hasher != nil {
|
||||||
// must never fail according to interface
|
// must never fail according to interface
|
||||||
_, _ = hasher.Write(buf)
|
_, err := hasher.Write(buf)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
hash = hasher.Sum(nil)
|
hash = hasher.Sum(nil)
|
||||||
}
|
}
|
||||||
return &ByteReader{
|
return &ByteReader{
|
||||||
|
@ -54,7 +54,10 @@ func TestFileReader(t *testing.T) {
|
|||||||
var hash []byte
|
var hash []byte
|
||||||
if hasher != nil {
|
if hasher != nil {
|
||||||
// must never fail according to interface
|
// must never fail according to interface
|
||||||
_, _ = hasher.Write(buf)
|
_, err := hasher.Write(buf)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
hash = hasher.Sum(nil)
|
hash = hasher.Sum(nil)
|
||||||
}
|
}
|
||||||
rd, err := NewFileReader(f, hash)
|
rd, err := NewFileReader(f, hash)
|
||||||
|
Loading…
Reference in New Issue
Block a user