Refactor dialog procedure to return characters - pee - Pee a password manager;Pee - because you have to...
(HTM) git clone git://vernunftzentrum.de/pee.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 28fc60ad1370b8c5b360c05176233c033186f875
(DIR) parent a09303351df8a4cf928cb0bac8167b631264d025
(HTM) Author: Christian Kellermann <ckeen@pestilenz.org>
Date: Fri, 8 Jan 2016 09:18:51 +0100
Refactor dialog procedure to return characters
Also refactor out the yes-no dialogs.
Diffstat:
pee.scm | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
---
(DIR) diff --git a/pee.scm b/pee.scm
@@ -60,9 +60,12 @@
(cond ((member answer options) =>
(lambda (c)
(printf "\r")
- (car c)))
+ (car (string->list (car c)))))
(else (printf "\r") (loop))))))))
+(define (ask-yes-or-no msg)
+ (eqv? #\y (ask-for-choice msg "y" "n")))
+
(define (new-password)
(define (ask-for-manual-password)
(with-stty
@@ -72,8 +75,7 @@
(read-line)
(print "\r"))))
(let manual-loop ()
- (if (equal? "y"
- (ask-for-choice "Invent your own password?" "y" "n"))
+ (if (ask-yes-or-no "Invent your own password?")
(let ((p1 (ask-for-manual-password))
(p2 (ask-for-manual-password)))
(unless (equal? p1 p2) (print "Passwords do not match.") (manual-loop)))
@@ -84,14 +86,16 @@
(else 32))))
(printf "Length ~a chars, entropy ~a bits~%" (string-length p) (quotient (* (string-length p) entropy-per-char) 100))
(print p)
- (let ((choice (ask-for-choice "Use this password?" "y" "n" "+" "-" " " "?")))
- (cond ((member choice '(" " "n")) (password-loop e))
- ((equal? choice "+") (password-loop (+ e entropy-delta)))
- ((equal? choice "-") (password-loop (max 32 (- e entropy-delta))))
- ((equal? choice "?")
- (printf "y - accept password~%+ - increase password length~%- - decrease password length~%n/space - new password~%")
- (password-loop e))
- (else p))))))))
+ (let dialog-loop ()
+ (let ((choice (ask-for-choice "Use this password?" "y" "n" "+" "-" " " "?")))
+ (case choice
+ ((#\space #\n) (password-loop e))
+ ((#\+) (password-loop (+ e entropy-delta)))
+ ((#\-) (password-loop (max 32 (- e entropy-delta))))
+ ((#\?)
+ (printf "y - accept password~%+ - increase password length~%- - decrease password length~%n/space - new password~%")
+ (dialog-loop))
+ (else p)))))))))
(define (get-hashed-passphrase)
(with-stty
@@ -255,8 +259,7 @@
(lambda (e)
(let ((user (prompt-for "User" (first e)))
(comment (prompt-for "Comment" (third e)))
- (password (if (equal? "y"
- (ask-for-choice "Change password?" "y" "n"))
+ (password (if (ask-yes-or-no "Change password?")
(new-password)
(second e))))
(encrypt-file db-name
@@ -270,7 +273,7 @@
(cond ((alist-ref account db equal?) =>
(lambda (e)
(print-without-password (cons account e))
- (if (equal? "y" (ask-for-choice "Really delete account?" "y" "n"))
+ (if (ask-yes-or-no "Really delete account?")
(encrypt-file db-name (alist-delete account db equal?) p)
(print "Entry '" (car e) "' deleted."))))
(else (print "Error: Entry for '" account "' not found")