Update for use with latest DisPass from git

This commit is contained in:
Tom Willemse 2013-05-25 13:34:26 +02:00
parent 38b880e72c
commit 22b72c8460
2 changed files with 32 additions and 19 deletions

10
NEWS
View file

@ -2,6 +2,16 @@
* Changes since * Changes since
- Use the new style of calling DisPass. DisPass has switched from
using several executables with many switches to a command-based
interface.
- Make the =dispass-labels-executable= obsolete, since it is nog
longer provided by DisPass, all its functionality has been moved
into the ~dispass~ executable. Also set it's default value to =nil=.
* Changes in v1.1.2
- Change the description to emphasize the idea that ~dispass.el~ is - Change the description to emphasize the idea that ~dispass.el~ is
only a wrapper around DisPass. only a wrapper around DisPass.

View file

@ -49,12 +49,15 @@
:type '(string) :type '(string)
:risky t) :risky t)
(defcustom dispass-labels-executable "dispass-label" (defcustom dispass-labels-executable nil
"The location of the dispass-label executable." "The location of the dispass-label executable."
:package-version '(dispass . "1.1") :package-version '(dispass . "1.1.3")
:group 'dispass :group 'dispass
:type 'string :type 'string
:risky t) :risky t)
(make-obsolete-variable 'dispass-labels-executable
"dispass-label is no longer used by DisPass."
"dispass 1.1.3")
(defcustom dispass-labelfile nil (defcustom dispass-labelfile nil
"The location of your preferred labelfile. "The location of your preferred labelfile.
@ -127,9 +130,9 @@ passphrase that has been generated."
(clipboard-kill-ring-save (point-min) (point-max)) (clipboard-kill-ring-save (point-min) (point-max))
(message "Password copied to clipboard."))))))) (message "Password copied to clipboard.")))))))
(defun dispass-start-process (label create length (defun dispass-start-process (cmd label create length
&optional algo seqno args) &optional algo seqno args)
"Ask DisPass to generate a passphrase for LABEL. "Ask DisPass call CMD for LABEL.
When CREATE is non-nil send along the -c switch to make it ask When CREATE is non-nil send along the -c switch to make it ask
for a password twice. When LENGTH is an integer and greater than for a password twice. When LENGTH is an integer and greater than
@ -139,26 +142,27 @@ algorithm be used by DisPass to generate the passphrase. SEQNO
asks DisPass to use SEQNO as a sequence number. asks DisPass to use SEQNO as a sequence number.
If specified add ARGS to the command." If specified add ARGS to the command."
(let ((args `("-o" ,@args ,label)) (let ((args `(,cmd ,@args "-o"))
proc) proc)
(when create (when create
(setq args (append '("-c") args))) (setq args (append args '("-v"))))
(when (and (integerp length) (> length 0)) (when (and (integerp length) (> length 0))
(setq args (append `("-l" ,(number-to-string length)) args))) (setq args (append args `("-l" ,(number-to-string length)))))
(when (and algo (not (equal algo "")) (when (and algo (not (equal algo ""))
(member algo dispass-algorithms)) (member algo dispass-algorithms))
(setq args (append `("-a" ,algo) args))) (setq args (append args `("-a" ,algo))))
(when (and seqno (> seqno 0)) (when (and seqno (> seqno 0))
(setq args (append `("-n" ,(number-to-string seqno)) args))) (setq args (append args `("-s" ,(number-to-string seqno)))))
(when dispass-labelfile (when dispass-labelfile
(setq args (append `("-f" ,dispass-labelfile) args))) (setq args (append `("-f" ,dispass-labelfile) args)))
(message "%s" `(,@args ,label))
(setq proc (apply 'start-process "dispass" "*dispass*" (setq proc (apply 'start-process "dispass" "*dispass*"
dispass-executable args)) dispass-executable `(,@args ,label)))
(set-process-sentinel proc 'dispass-process-sentinel) (set-process-sentinel proc 'dispass-process-sentinel)
(set-process-filter proc (dispass-process-filter-for label)))) (set-process-filter proc (dispass-process-filter-for label))))
@ -200,10 +204,10 @@ If specified add ARGS to the command."
(defun dispass-read-labels () (defun dispass-read-labels ()
"Load a list of all labels into a buffer." "Load a list of all labels into a buffer."
(insert (shell-command-to-string (insert (shell-command-to-string
(concat dispass-labels-executable (concat dispass-executable
(when dispass-labelfile (when dispass-labelfile
(concat " -f " dispass-labelfile)) (concat " -f " dispass-labelfile))
" -l --script"))) " list --script")))
(goto-char (point-min))) (goto-char (point-min)))
;;;###autoload ;;;###autoload
@ -219,7 +223,7 @@ the ALGO algorithm with sequence number SEQNO."
(read-from-minibuffer (read-from-minibuffer
"Sequence no. (1): " nil nil t nil "1"))) "Sequence no. (1): " nil nil t nil "1")))
(let ((length (or length dispass-default-length))) (let ((length (or length dispass-default-length)))
(dispass-start-process label t length algo seqno))) (dispass-start-process "generate" label t length algo seqno)))
;;;###autoload ;;;###autoload
(defun dispass (label &optional length algo seqno) (defun dispass (label &optional length algo seqno)
@ -240,8 +244,7 @@ not to have LABEL added to your labelfile for some other reason."
"Sequence no. (1): " nil nil t nil "1"))) "Sequence no. (1): " nil nil t nil "1")))
(let ((length (or length dispass-default-length))) (let ((length (or length dispass-default-length)))
(dispass-start-process (dispass-start-process
label nil length algo seqno "generate" label nil length algo seqno)))
(when (member label (dispass-get-labels)) '("-s")))))
;; Labels management ;; Labels management
;;;###autoload ;;;###autoload
@ -259,8 +262,8 @@ Optionally also specify sequence number SEQNO."
dispass-algorithms nil nil nil nil "dispass1") dispass-algorithms nil nil nil nil "dispass1")
(read-from-minibuffer "Sequnce no. (1): " nil nil t nil "1"))) (read-from-minibuffer "Sequnce no. (1): " nil nil t nil "1")))
(shell-command (shell-command
(format "%s %s --add %s:%d:%s:%s" (format "%s %s add %s:%d:%s:%s"
dispass-labels-executable dispass-executable
(if dispass-labelfile (if dispass-labelfile
(concat "-f " dispass-labelfile) (concat "-f " dispass-labelfile)
"") "")
@ -278,7 +281,7 @@ error is thrown."
(completing-read (completing-read
"Label: " (dispass-get-labels))))) "Label: " (dispass-get-labels)))))
(shell-command (shell-command
(format "%s %s --remove %s" dispass-labels-executable (format "%s %s rm %s" dispass-executable
(if dispass-labelfile (if dispass-labelfile
(concat "-f " dispass-labelfile) (concat "-f " dispass-labelfile)
"") "")