summaryrefslogtreecommitdiff
path: root/shroud
diff options
context:
space:
mode:
authorDavid Thompson <davet@gnu.org>2015-06-10 18:15:56 -0400
committerDavid Thompson <davet@gnu.org>2015-06-10 18:15:56 -0400
commit778963a0da12125e5894e8009bcc91020eb988a5 (patch)
tree042db20cf4d057673ac25ecbd5425fad966265b2 /shroud
parent16360f53d7035a184e56bd9a04968a24014350b0 (diff)
Change <secret> to store arbitrary key/value pairs.
* shroud/secret.scm (secret-username, secret-password): Delete. (secret-contents): New accessor. (secret-ref): New procedure. (alist->secret, secret->alist): Use new format.
Diffstat (limited to 'shroud')
-rw-r--r--shroud/secret.scm21
-rw-r--r--shroud/ui/hide.scm4
-rw-r--r--shroud/ui/show.scm6
3 files changed, 17 insertions, 14 deletions
diff --git a/shroud/secret.scm b/shroud/secret.scm
index 22d2961..a43ba54 100644
--- a/shroud/secret.scm
+++ b/shroud/secret.scm
@@ -23,8 +23,8 @@
#:export (make-secret
secret?
secret-id
- secret-username
- secret-password
+ secret-contents
+ secret-ref
alist->secret
secret->alist
load-secrets
@@ -32,25 +32,26 @@
secrets-by-id))
(define-record-type <secret>
- (make-secret id username password)
+ (make-secret id contents)
secret?
(id secret-id)
- (username secret-username)
- (password secret-password))
+ (contents secret-contents))
+
+(define (secret-ref secret key)
+ "Return the secret data associated with KEY in SECRET."
+ (assoc-ref (secret-contents secret) key))
(define (alist->secret alist)
"Convert ALIST into a <secret> record."
(make-secret (assq-ref alist 'id)
- (assq-ref alist 'username)
- (assq-ref alist 'password)))
+ (assq-ref alist 'contents)))
(define (secret->alist secret)
"Convert SECRET into an alist."
(match secret
- (($ <secret> id username password)
+ (($ <secret> id contents)
`((id . ,id)
- (username . ,username)
- (password . ,password)))))
+ (contents . ,contents)))))
(define (load-secrets file)
"Load secrets from FILE, or return '() if FILE does not exist."
diff --git a/shroud/ui/hide.scm b/shroud/ui/hide.scm
index b09d7c2..9240b54 100644
--- a/shroud/ui/hide.scm
+++ b/shroud/ui/hide.scm
@@ -82,7 +82,9 @@ Add a new secret to the database.~%")
(let* ((db (secrets-by-id (force db)))
(existing (vhash-ref db id))
(vcons (if existing vhash-replace vhash-cons))
- (secret (make-secret id username password)))
+ (contents `(("username" . ,username)
+ ("password" . ,password)))
+ (secret (make-secret id contents)))
(when (and (not replace?) existing)
(leave "~a: secret already defined" id))
diff --git a/shroud/ui/show.scm b/shroud/ui/show.scm
index 88d9ccb..6ad1ba0 100644
--- a/shroud/ui/show.scm
+++ b/shroud/ui/show.scm
@@ -70,10 +70,10 @@ Show secret named ID.~%")
(leave "~a: secret undefined" id))
(if password?
- (display (secret-password secret))
+ (display (secret-ref secret "password"))
(format #t "username: ~a~%password: ~a~%"
- (secret-username secret)
- (secret-password secret)))))
+ (secret-ref secret "username")
+ (secret-ref secret "password")))))
;; We don't alter the database.
db)