Add more checks befor decrypting data

This commit is contained in:
Alexander Neumann 2014-11-24 22:11:09 +01:00
parent 26cd6c5372
commit 4ab3d51996
3 changed files with 21 additions and 2 deletions

View file

@ -24,6 +24,8 @@ const (
versionFileName = "version"
)
var ErrWrongData = errors.New("wrong data returned by backend, checksum does not match")
type Local struct {
p string
ver uint
@ -218,7 +220,8 @@ func (b *Local) filename(t Type, id ID) string {
return filepath.Join(b.dir(t), id.String())
}
// Get returns the content stored under the given ID.
// Get returns the content stored under the given ID. If the data doesn't match
// the requested ID, ErrWrongData is returned.
func (b *Local) Get(t Type, id ID) ([]byte, error) {
// try to open file
file, err := os.Open(b.filename(t, id))
@ -233,6 +236,11 @@ func (b *Local) Get(t Type, id ID) ([]byte, error) {
return nil, err
}
// check id
if !Hash(buf).Equal(id) {
return nil, ErrWrongData
}
return buf, nil
}