mirror of
https://github.com/restic/restic.git
synced 2024-12-24 16:54:00 +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 (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -191,26 +189,17 @@ func AddKey(s *Repository, password string, template *crypto.Key) (*Key, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// store in repository and return
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
plainhw := backend.NewHashingWriter(blob, sha256.New())
|
newkey.name = h.Name
|
||||||
|
|
||||||
_, 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
|
|
||||||
|
|
||||||
return newkey, nil
|
return newkey, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue