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

Encrypt comments

This commit is contained in:
Adrian Utrilla
2017-08-15 13:48:55 -07:00
parent 5086288705
commit cdc86da1f3
3 changed files with 88 additions and 36 deletions

View File

@@ -9,6 +9,8 @@ import (
"regexp"
"strconv"
"strings"
"go.mozilla.org/sops"
)
type encryptedValue struct {
@@ -96,6 +98,10 @@ func (c Cipher) Decrypt(value string, key []byte, path string) (plaintext interf
plaintext, err = strconv.ParseBool(decryptedValue)
stashValue.plaintext = plaintext
return plaintext, stashValue, err
case "comment":
plaintext = sops.Comment{Value: decryptedValue}
stashValue.plaintext = plaintext
return plaintext, stashValue, nil
default:
return nil, nil, fmt.Errorf("Unknown datatype: %s", encryptedValue.datatype)
}
@@ -141,6 +147,9 @@ func (c Cipher) Encrypt(value interface{}, key []byte, path string, stash interf
encryptedType = "bool"
// The Python version encodes booleans with Titlecase
plaintext = []byte(strings.Title(strconv.FormatBool(value)))
case sops.Comment:
encryptedType = "comment"
plaintext = []byte(value.Value)
default:
return "", fmt.Errorf("Value to encrypt has unsupported type %T", value)
}