Lightly obscure secrets

This commit is contained in:
Nick Craig-Wood
2015-09-01 22:33:34 +01:00
parent e2717a031e
commit c98a51b26c
5 changed files with 46 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ package fs
import (
"bufio"
"encoding/base64"
"fmt"
"log"
"math"
@@ -121,6 +122,27 @@ func (x *SizeSuffix) Type() string {
// Check it satisfies the interface
var _ pflag.Value = (*SizeSuffix)(nil)
// Obscure a config value
func Obscure(x string) string {
y := []byte(x)
for i := range y {
y[i] ^= byte(i) ^ 0xAA
}
return base64.StdEncoding.EncodeToString(y)
}
// Reveal a config value
func Reveal(y string) string {
x, err := base64.StdEncoding.DecodeString(y)
if err != nil {
log.Fatalf("Failed to reveal %q: %v", y, err)
}
for i := range x {
x[i] ^= byte(i) ^ 0xAA
}
return string(x)
}
// Filesystem config options
type ConfigInfo struct {
Verbose bool