signer/storage fix storage to pass all tests

This commit is contained in:
Huiyi Li 2020-02-01 14:52:44 -08:00
parent 2f6298765d
commit 6835af0aa0

View file

@ -63,6 +63,11 @@ func (s *Storage) Get(key string) (string, error) {
return "", err
}
if len(s.key) == 0 {
// if there is no key for decryption, just store the value
return data, nil
}
cred := StoredCredential{}
if err = json.Unmarshal([]byte(data), &cred); err != nil {
log.Warn("Failed to unmarshal encrypted credential", "err", err)
@ -85,6 +90,11 @@ func (s *Storage) Put(key, value string) error {
return ErrZeroKey
}
if len(s.key) == 0 {
// if there is no key for encryption, just store the value
return s.api.Put(key, value)
}
ciphertext, iv, err := Encrypt(s.key, []byte(value), []byte(key))
if err != nil {
log.Warn("Failed to encrypt entry", "err", err)