1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

Do not encrypt and decrypt empty values

Fixes #138
This commit is contained in:
Adrian Utrilla
2016-10-28 15:30:55 +02:00
parent b73a389256
commit f52dc0008d
2 changed files with 6 additions and 3 deletions

View File

@@ -54,6 +54,9 @@ func parse(value string) (*encryptedValue, error) {
// Decrypt takes a sops-format value string and a key and returns the decrypted value and a stash value
func (c Cipher) Decrypt(value string, key []byte, path string) (plaintext interface{}, stash interface{}, err error) {
if value == "" {
return "", nil, nil
}
encryptedValue, err := parse(value)
if err != nil {
return "", nil, err
@@ -100,6 +103,9 @@ func (c Cipher) Decrypt(value string, key []byte, path string) (plaintext interf
// Encrypt takes one of (string, int, float, bool) and encrypts it with the provided key and additional auth data, returning a sops-format encrypted string.
func (c Cipher) Encrypt(value interface{}, key []byte, path string, stash interface{}) (string, error) {
if value == "" {
return "", nil
}
aescipher, err := cryptoaes.NewCipher(key)
if err != nil {
return "", fmt.Errorf("Could not initialize AES GCM encryption cipher: %s", err)

View File

@@ -33,9 +33,6 @@ func TestRoundtripString(t *testing.T) {
f := func(x, aad string) bool {
key := make([]byte, 32)
rand.Read(key)
if x == "" {
return true
}
s, err := Cipher{}.Encrypt(x, key, aad, nil)
if err != nil {
fmt.Println(err)