mirror of
https://github.com/octoleo/restic.git
synced 2025-01-05 08:02:22 +00:00
crypto: Use helpers for size calculations
This commit is contained in:
parent
d6db5a1fc2
commit
243698680a
5
internal/cache/file.go
vendored
5
internal/cache/file.go
vendored
@ -8,7 +8,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/restic/restic/internal/crypto"
|
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
@ -59,7 +58,7 @@ func (c *Cache) load(h restic.Handle, length int, offset int64) (io.ReadCloser,
|
|||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.Size() <= crypto.Extension {
|
if fi.Size() <= int64(restic.CiphertextLength(0)) {
|
||||||
_ = f.Close()
|
_ = f.Close()
|
||||||
_ = c.remove(h)
|
_ = c.remove(h)
|
||||||
return nil, errors.Errorf("cached file %v is truncated, removing", h)
|
return nil, errors.Errorf("cached file %v is truncated, removing", h)
|
||||||
@ -117,7 +116,7 @@ func (c *Cache) Save(h restic.Handle, rd io.Reader) error {
|
|||||||
return errors.Wrap(err, "Copy")
|
return errors.Wrap(err, "Copy")
|
||||||
}
|
}
|
||||||
|
|
||||||
if n <= crypto.Extension {
|
if n <= int64(restic.CiphertextLength(0)) {
|
||||||
_ = f.Close()
|
_ = f.Close()
|
||||||
_ = fs.Remove(f.Name())
|
_ = fs.Remove(f.Name())
|
||||||
debug.Log("trying to cache truncated file %v, removing", h)
|
debug.Log("trying to cache truncated file %v, removing", h)
|
||||||
|
@ -262,7 +262,7 @@ func AddKey(ctx context.Context, s *Repository, password, username, hostname str
|
|||||||
}
|
}
|
||||||
|
|
||||||
nonce := crypto.NewRandomNonce()
|
nonce := crypto.NewRandomNonce()
|
||||||
ciphertext := make([]byte, 0, len(buf)+newkey.user.Overhead()+newkey.user.NonceSize())
|
ciphertext := make([]byte, 0, restic.CiphertextLength(len(buf)))
|
||||||
ciphertext = append(ciphertext, nonce...)
|
ciphertext = append(ciphertext, nonce...)
|
||||||
ciphertext = newkey.user.Seal(ciphertext, nonce, buf, nil)
|
ciphertext = newkey.user.Seal(ciphertext, nonce, buf, nil)
|
||||||
newkey.Data = ciphertext
|
newkey.Data = ciphertext
|
||||||
|
@ -195,7 +195,7 @@ func (r *fileRestorer) downloadPack(ctx context.Context, pack *packInfo) error {
|
|||||||
if packID.Equal(pack.id) {
|
if packID.Equal(pack.id) {
|
||||||
addBlob(blob, fileOffset)
|
addBlob(blob, fileOffset)
|
||||||
}
|
}
|
||||||
fileOffset += int64(blob.Length) - crypto.Extension
|
fileOffset += int64(restic.PlaintextLength(int(blob.Length)))
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// restoreFiles should have caught this error before
|
// restoreFiles should have caught this error before
|
||||||
|
Loading…
Reference in New Issue
Block a user