diff options
author | Jakob Unterwurzacher | 2016-06-05 14:26:16 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-06-05 14:32:07 +0200 |
commit | 0c80cca674931c9dbfc69c25df24d53abbdd63a9 (patch) | |
tree | c11cae555954fc08f3e28f22b6ed23ea5717a083 /internal | |
parent | ca54b665e32a9b298ea3e70b5da0108db3a71364 (diff) |
toggledlog: convert remaing naked fmt.Print*
Several fatal errors were just printed to stdout, which
meant they were invisible when running the test suite.
Fix this by introducing toggledlog.Fatal and convert as
follows:
Fatal errors -> toggledlog.Fatal
Warnings -> toggledlog.Warn
Password prompts -> fmt.Fprintf
Diffstat (limited to 'internal')
-rw-r--r-- | internal/configfile/kdf.go | 7 | ||||
-rw-r--r-- | internal/prefer_openssl/prefer.go | 7 | ||||
-rw-r--r-- | internal/toggledlog/log.go | 12 |
3 files changed, 17 insertions, 9 deletions
diff --git a/internal/configfile/kdf.go b/internal/configfile/kdf.go index f1a7a40..e77a743 100644 --- a/internal/configfile/kdf.go +++ b/internal/configfile/kdf.go @@ -1,13 +1,14 @@ package configfile import ( - "fmt" + "log" "math" "os" "golang.org/x/crypto/scrypt" "github.com/rfjakob/gocryptfs/internal/cryptocore" + "github.com/rfjakob/gocryptfs/internal/toggledlog" ) const ( @@ -31,7 +32,7 @@ func NewScryptKdf(logN int) scryptKdf { s.N = 1 << ScryptDefaultLogN } else { if logN < 10 { - fmt.Println("Error: scryptn below 10 is too low to make sense. Aborting.") + toggledlog.Fatal.Println("Error: scryptn below 10 is too low to make sense. Aborting.") os.Exit(1) } s.N = 1 << uint32(logN) @@ -45,7 +46,7 @@ func NewScryptKdf(logN int) scryptKdf { func (s *scryptKdf) DeriveKey(pw string) []byte { k, err := scrypt.Key([]byte(pw), s.Salt, s.N, s.R, s.P, s.KeyLen) if err != nil { - panic(fmt.Sprintf("DeriveKey failed: %s", err.Error())) + log.Panicf("DeriveKey failed: %v", err) } return k } diff --git a/internal/prefer_openssl/prefer.go b/internal/prefer_openssl/prefer.go index 16788e0..0bc24b4 100644 --- a/internal/prefer_openssl/prefer.go +++ b/internal/prefer_openssl/prefer.go @@ -1,9 +1,10 @@ package prefer_openssl import ( - "fmt" "io/ioutil" "regexp" + + "github.com/rfjakob/gocryptfs/internal/toggledlog" ) // filePreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine. @@ -17,12 +18,12 @@ import ( func filePreferOpenSSL(file string) bool { ci, err := ioutil.ReadFile(file) if err != nil { - fmt.Println(err) + toggledlog.Warn.Println(err) return true } haveAes, err := regexp.Match(`(?m)^flags.*\baes\b`, ci) if err != nil { - fmt.Println(err) + toggledlog.Warn.Println(err) return true } return !haveAes diff --git a/internal/toggledlog/log.go b/internal/toggledlog/log.go index 7f437c8..23d7347 100644 --- a/internal/toggledlog/log.go +++ b/internal/toggledlog/log.go @@ -49,18 +49,24 @@ func (l *toggledLogger) Println(v ...interface{}) { } } -// As defined by http://elinux.org/Debugging_by_printing#Log_Levels // Debug messages +// Can be enabled by passing "-d" var Debug *toggledLogger -// Informational message e.g. startup information +// Informational message +// Can be disabled by passing "-q" var Info *toggledLogger -// A warning, meaning nothing serious by itself but might indicate problems +// A warning, meaning nothing serious by itself but might indicate problems. +// Passing "-wpanic" will make this function panic after printing the message. var Warn *toggledLogger +// Fatal error, we are about to exit +var Fatal *toggledLogger + func init() { Debug = &toggledLogger{false, false, log.New(os.Stdout, "", 0)} Info = &toggledLogger{true, false, log.New(os.Stdout, "", 0)} Warn = &toggledLogger{true, false, log.New(os.Stderr, "", 0)} + Fatal = &toggledLogger{true, false, log.New(os.Stderr, "", 0)} } |