aboutsummaryrefslogtreecommitdiff
path: root/ask
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-07-17 23:55:23 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-07-17 23:55:23 +0200
commitcd6f888802f217ca0cd0509a999696f6c4235c20 (patch)
tree3273a2b84af193e7024c3e721e6a58204dcb3460 /ask
parent450a6898f5062d461d5c0932182e3140c6f16d9e (diff)
Refactor ask
Diffstat (limited to 'ask')
-rw-r--r--ask/ask.go41
1 files changed, 34 insertions, 7 deletions
diff --git a/ask/ask.go b/ask/ask.go
index 7d87e83..d554d32 100644
--- a/ask/ask.go
+++ b/ask/ask.go
@@ -6,6 +6,8 @@ import (
"io"
"os"
+ "dim13.org/signify/bhash"
+
"golang.org/x/crypto/ssh/terminal"
)
@@ -14,18 +16,43 @@ var (
ErrNoMatch = errors.New("passwords don't match")
)
-// Confirmed asks for password twice
-func Confirmed() (string, error) {
+const (
+ promtPassphrase = "passphrase: "
+ promtConfirmed = "confirm passphrase: "
+)
+
+type Passphrase struct{}
+
+func (Passphrase) DeriveKey(salt []byte, rounds int, length int) ([]byte, error) {
+ pass, err := passphrase()
+ if err != nil {
+ return nil, err
+ }
+ return bhash.Pbkdf([]byte(pass), salt, rounds, length), nil
+}
+
+type Confirmed struct{}
+
+func (Confirmed) DeriveKey(salt []byte, rounds int, length int) ([]byte, error) {
+ pass, err := confirmed()
+ if err != nil {
+ return nil, err
+ }
+ return bhash.Pbkdf([]byte(pass), salt, rounds, length), nil
+}
+
+// confirmed asks for password twice
+func confirmed() (string, error) {
restore, err := makeRaw(os.Stdin)
if err != nil {
return "", err
}
defer restore()
- pass, err := ask(os.Stdin, "passphrase: ")
+ pass, err := ask(os.Stdin, promtPassphrase)
if err != nil {
return "", err
}
- pass2, err := ask(os.Stdin, "confirm passphrase: ")
+ pass2, err := ask(os.Stdin, promtConfirmed)
if err != nil {
return "", err
}
@@ -35,14 +62,14 @@ func Confirmed() (string, error) {
return pass, nil
}
-// Password asks for password once
-func Password() (string, error) {
+// passphrase asks for passphrase once
+func passphrase() (string, error) {
restore, err := makeRaw(os.Stdin)
if err != nil {
return "", err
}
defer restore()
- return ask(os.Stdin, "passphrase: ")
+ return ask(os.Stdin, promtPassphrase)
}
func ask(rw io.ReadWriter, prompt string) (string, error) {