diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/configfile/config_file.go | 3 | ||||
-rw-r--r-- | internal/exitcodes/exitcodes.go | 38 |
2 files changed, 40 insertions, 1 deletions
diff --git a/internal/configfile/config_file.go b/internal/configfile/config_file.go index c4865d7..1233d8a 100644 --- a/internal/configfile/config_file.go +++ b/internal/configfile/config_file.go @@ -9,6 +9,7 @@ import ( "github.com/rfjakob/gocryptfs/internal/contentenc" "github.com/rfjakob/gocryptfs/internal/cryptocore" + "github.com/rfjakob/gocryptfs/internal/exitcodes" "github.com/rfjakob/gocryptfs/internal/tlog" ) import "os" @@ -163,7 +164,7 @@ func LoadConfFile(filename string, password string) ([]byte, *ConfFile, error) { tlog.Warn.Enabled = true if err != nil { tlog.Warn.Printf("failed to unlock master key: %s", err.Error()) - return nil, nil, fmt.Errorf("Password incorrect.") + return nil, nil, exitcodes.NewErr("Password incorrect.", exitcodes.PasswordIncorrect) } return key, &cf, err diff --git a/internal/exitcodes/exitcodes.go b/internal/exitcodes/exitcodes.go new file mode 100644 index 0000000..908e714 --- /dev/null +++ b/internal/exitcodes/exitcodes.go @@ -0,0 +1,38 @@ +// Package exitcodes contains all well-defined exit codes that gocryptfs +// can return. +package exitcodes + +import ( + "fmt" + "os" +) + +const ( + // Other error - please inspect the message + Other = 11 + // The password was incorrect + PasswordIncorrect = 12 + // TODO several other exit codes are defined in main.go. These will be + // ported over here. +) + +type Err struct { + error + code int +} + +// NewErr returns an error containing "msg" and the exit code "code". +func NewErr(msg string, code int) Err { + return Err{ + error: fmt.Errorf(msg), + code: code, + } +} + +func Exit(err error) { + err2, ok := err.(Err) + if !ok { + os.Exit(Other) + } + os.Exit(err2.code) +} |