From b85927576bccd00bae74391f4650d4dd9a2719b9 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 26 Jul 2015 18:00:53 +0200 Subject: [PATCH] Address code review comments --- cmd/restic/cmd_cat.go | 4 ++-- repository/repository.go | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 05f58c976..4e76f8237 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -162,12 +162,12 @@ func (cmd CmdCat) Execute(args []string) error { return err case "blob": - _, tpe, _, length, err := repo.Index().Lookup(id) + _, blobType, _, length, err := repo.Index().Lookup(id) if err != nil { return err } - if tpe != pack.Data { + if blobType != pack.Data { return errors.New("wrong type for blob") } diff --git a/repository/repository.go b/repository/repository.go index 40f9cc7ec..0a4630cfa 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -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 -// pack from the backend, the result is stored in buf, which must be large -// enough to hold the complete blob. -func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID, buf []byte) ([]byte, error) { +// pack from the backend, the result is stored in plaintextBuf, which must be +// large enough to hold the complete blob. +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()) // lookup pack 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 } - if length > uint(cap(buf))+crypto.Extension { - return nil, errors.New("buf is too small") + if length > uint(cap(plaintextBuf))+crypto.Extension { + return nil, fmt.Errorf("buf is too small, need %d more bytes", length-uint(cap(plaintextBuf))-crypto.Extension) } 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 - cbuf := make([]byte, length) - _, err = io.ReadFull(rd, cbuf) + ciphertextBuf := make([]byte, length) + _, err = io.ReadFull(rd, ciphertextBuf) if err != nil { return nil, err } @@ -128,17 +128,17 @@ func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID, buf []byte) ([]byt } // decrypt - buf, err = r.decryptTo(buf, cbuf) + plaintextBuf, err = r.decryptTo(plaintextBuf, ciphertextBuf) if err != nil { return nil, err } // check hash - if !backend.Hash(buf).Equal(id) { + if !backend.Hash(plaintextBuf).Equal(id) { return nil, errors.New("invalid data returned") } - return buf, nil + return plaintextBuf, nil } // LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on