cmd/clef, signer: refresh tutorial, fix noticed issues (#19774)
* cmd/clef, signer: refresh tutorial, fix noticed issues * cmd/clef, signer: support removing stored keys (delpw + rules) * cmd/clef: polishes + Geth integration in the tutorial
This commit is contained in:
@ -53,7 +53,7 @@ func NewAESEncryptedStorage(filename string, key []byte) *AESEncryptedStorage {
|
||||
}
|
||||
}
|
||||
|
||||
// Put stores a value by key. 0-length keys results in no-op
|
||||
// Put stores a value by key. 0-length keys results in noop.
|
||||
func (s *AESEncryptedStorage) Put(key, value string) {
|
||||
if len(key) == 0 {
|
||||
return
|
||||
@ -75,27 +75,41 @@ func (s *AESEncryptedStorage) Put(key, value string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the previously stored value, or the empty string if it does not exist or key is of 0-length
|
||||
func (s *AESEncryptedStorage) Get(key string) string {
|
||||
// Get returns the previously stored value, or an error if it does not exist or
|
||||
// key is of 0-length.
|
||||
func (s *AESEncryptedStorage) Get(key string) (string, error) {
|
||||
if len(key) == 0 {
|
||||
return ""
|
||||
return "", ErrZeroKey
|
||||
}
|
||||
data, err := s.readEncryptedStorage()
|
||||
if err != nil {
|
||||
log.Warn("Failed to read encrypted storage", "err", err, "file", s.filename)
|
||||
return ""
|
||||
return "", err
|
||||
}
|
||||
encrypted, exist := data[key]
|
||||
if !exist {
|
||||
log.Warn("Key does not exist", "key", key)
|
||||
return ""
|
||||
return "", ErrNotFound
|
||||
}
|
||||
entry, err := decrypt(s.key, encrypted.Iv, encrypted.CipherText, []byte(key))
|
||||
if err != nil {
|
||||
log.Warn("Failed to decrypt key", "key", key)
|
||||
return ""
|
||||
return "", err
|
||||
}
|
||||
return string(entry), nil
|
||||
}
|
||||
|
||||
// Del removes a key-value pair. If the key doesn't exist, the method is a noop.
|
||||
func (s *AESEncryptedStorage) Del(key string) {
|
||||
data, err := s.readEncryptedStorage()
|
||||
if err != nil {
|
||||
log.Warn("Failed to read encrypted storage", "err", err, "file", s.filename)
|
||||
return
|
||||
}
|
||||
delete(data, key)
|
||||
if err = s.writeEncryptedStorage(data); err != nil {
|
||||
log.Warn("Failed to write entry", "err", err)
|
||||
}
|
||||
return string(entry)
|
||||
}
|
||||
|
||||
// readEncryptedStorage reads the file with encrypted creds
|
||||
|
Reference in New Issue
Block a user