mirror of
https://github.com/restic/restic.git
synced 2024-12-24 00:37:28 +00:00
Key: Use Save() instead of Create()
This commit is contained in:
parent
4735a7f9b5
commit
fe565e17c3
1 changed files with 7 additions and 18 deletions
|
@ -2,8 +2,6 @@ package repository
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -191,26 +189,17 @@ func AddKey(s *Repository, password string, template *crypto.Key) (*Key, error)
|
|||
}
|
||||
|
||||
// store in repository and return
|
||||
blob, err := s.be.Create()
|
||||
h := backend.Handle{
|
||||
Type: backend.Key,
|
||||
Name: backend.Hash(buf).String(),
|
||||
}
|
||||
|
||||
err = s.be.Save(h, buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
plainhw := backend.NewHashingWriter(blob, sha256.New())
|
||||
|
||||
_, err = plainhw.Write(buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
name := hex.EncodeToString(plainhw.Sum(nil))
|
||||
|
||||
err = blob.Finalize(backend.Key, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newkey.name = name
|
||||
newkey.name = h.Name
|
||||
|
||||
return newkey, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue