mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +00:00
Address code review comments
This commit is contained in:
parent
d1629e1e4e
commit
b85927576b
@ -162,12 +162,12 @@ func (cmd CmdCat) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
|
|
||||||
case "blob":
|
case "blob":
|
||||||
_, tpe, _, length, err := repo.Index().Lookup(id)
|
_, blobType, _, length, err := repo.Index().Lookup(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if tpe != pack.Data {
|
if blobType != pack.Data {
|
||||||
return errors.New("wrong type for blob")
|
return errors.New("wrong type for blob")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +86,9 @@ func (r *Repository) LoadAndDecrypt(t backend.Type, id backend.ID) ([]byte, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadBlob tries to load and decrypt content identified by t and id from a
|
// LoadBlob tries to load and decrypt content identified by t and id from a
|
||||||
// pack from the backend, the result is stored in buf, which must be large
|
// pack from the backend, the result is stored in plaintextBuf, which must be
|
||||||
// enough to hold the complete blob.
|
// large enough to hold the complete blob.
|
||||||
func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID, buf []byte) ([]byte, error) {
|
func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID, plaintextBuf []byte) ([]byte, error) {
|
||||||
debug.Log("Repo.LoadBlob", "load %v with id %v", t, id.Str())
|
debug.Log("Repo.LoadBlob", "load %v with id %v", t, id.Str())
|
||||||
// lookup pack
|
// lookup pack
|
||||||
packID, tpe, offset, length, err := r.idx.Lookup(id)
|
packID, tpe, offset, length, err := r.idx.Lookup(id)
|
||||||
@ -97,8 +97,8 @@ func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID, buf []byte) ([]byt
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if length > uint(cap(buf))+crypto.Extension {
|
if length > uint(cap(plaintextBuf))+crypto.Extension {
|
||||||
return nil, errors.New("buf is too small")
|
return nil, fmt.Errorf("buf is too small, need %d more bytes", length-uint(cap(plaintextBuf))-crypto.Extension)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tpe != t {
|
if tpe != t {
|
||||||
@ -116,8 +116,8 @@ func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID, buf []byte) ([]byt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make buffer that is large enough for the complete blob
|
// make buffer that is large enough for the complete blob
|
||||||
cbuf := make([]byte, length)
|
ciphertextBuf := make([]byte, length)
|
||||||
_, err = io.ReadFull(rd, cbuf)
|
_, err = io.ReadFull(rd, ciphertextBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -128,17 +128,17 @@ func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID, buf []byte) ([]byt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// decrypt
|
// decrypt
|
||||||
buf, err = r.decryptTo(buf, cbuf)
|
plaintextBuf, err = r.decryptTo(plaintextBuf, ciphertextBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// check hash
|
// check hash
|
||||||
if !backend.Hash(buf).Equal(id) {
|
if !backend.Hash(plaintextBuf).Equal(id) {
|
||||||
return nil, errors.New("invalid data returned")
|
return nil, errors.New("invalid data returned")
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf, nil
|
return plaintextBuf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on
|
// LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on
|
||||||
|
Loading…
Reference in New Issue
Block a user