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

Use the same formatting for floats and booleans as the Python version.

Fixes #111
This commit is contained in:
Adrian Utrilla
2016-09-07 09:41:29 -07:00
parent 46fc619a9d
commit aac08d7c9b

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"regexp"
"strconv"
"strings"
)
type encryptedValue struct {
@@ -128,10 +129,12 @@ func (c Cipher) Encrypt(value interface{}, key []byte, path string, stash interf
plaintext = []byte(strconv.Itoa(value))
case float64:
encryptedType = "float"
plaintext = []byte(strconv.FormatFloat(value, 'f', 9, 64))
// The Python version encodes floats without padding 0s after the decimal point.
plaintext = []byte(strconv.FormatFloat(value, 'f', -1, 64))
case bool:
encryptedType = "bool"
plaintext = []byte(strconv.FormatBool(value))
// The Python version encodes booleans with Titlecase
plaintext = []byte(strings.Title(strconv.FormatBool(value)))
default:
return "", fmt.Errorf("Value to encrypt has unsupported type %T", value)
}