Remove hex output from keys; standardize on B64 for CLI output. This (#1831)

aligns with all other interactions which use B64 encoding for bytes.
This commit is contained in:
Jeff Mitchell
2016-09-01 12:59:15 -04:00
committed by GitHub
parent ffb5fd1858
commit 392565fe01
4 changed files with 63 additions and 78 deletions

View File

@@ -89,20 +89,12 @@ func parseDecryptAndTestUnsealKeys(t *testing.T,
priv3Bytes,
}
testFunc := func(b64 bool, bkeys map[string][]string) {
testFunc := func(bkeys map[string][]string) {
var re *regexp.Regexp
if fingerprints {
if b64 {
re, err = regexp.Compile("\\s*Key\\s+\\d+\\s+fingerprint:\\s+([0-9a-fA-F]+);\\s+value\\s+\\(base64\\):\\s+(.*)")
} else {
re, err = regexp.Compile("\\s*Key\\s+\\d+\\s+fingerprint:\\s+([0-9a-fA-F]+);\\s+value\\s+\\(hex\\)\\s+:\\s+(.*)")
}
re, err = regexp.Compile("\\s*Key\\s+\\d+\\s+fingerprint:\\s+([0-9a-fA-F]+);\\s+value:\\s+(.*)")
} else {
if b64 {
re, err = regexp.Compile("\\s*Key\\s+\\d+\\s\\(base64\\):\\s+(.*)")
} else {
re, err = regexp.Compile("\\s*Key\\s+\\d+\\s\\(hex\\)\\s+:\\s+(.*)")
}
re, err = regexp.Compile("\\s*Key\\s+\\d+:\\s+(.*)")
}
if err != nil {
t.Fatalf("Error compiling regex: %s", err)
@@ -152,11 +144,7 @@ func parseDecryptAndTestUnsealKeys(t *testing.T,
t.Fatalf("Error parsing private key %d: %s", i, err)
}
var keyBytes []byte
if b64 {
keyBytes, err = base64.StdEncoding.DecodeString(encodedKeys[i])
} else {
keyBytes, err = hex.DecodeString(encodedKeys[i])
}
keyBytes, err = base64.StdEncoding.DecodeString(encodedKeys[i])
if err != nil {
t.Fatalf("Error decoding key %d: %s", i, err)
}
@@ -189,6 +177,5 @@ func parseDecryptAndTestUnsealKeys(t *testing.T,
}
}
testFunc(false, backupKeys)
testFunc(true, backupKeysB64)
testFunc(backupKeysB64)
}