From 827439e821bbce8d41d4a85709e4a40275aab8a1 Mon Sep 17 00:00:00 2001 From: Teodor Zlatanov Date: Wed, 17 Jan 2007 19:33:51 +0000 Subject: [PATCH] (encrypt-insert-file-contents): Add better prompt to mention filename. Add comments at beginning regarding usage. (encrypt-write-file-contents): Change interactive so a string is acceptable. If the file has no associated model, show an error instead of a nonsense prompt. --- lisp/ChangeLog | 9 +++++ lisp/encrypt.el | 91 +++++++++++++++++++++++++++++++------------------ 2 files changed, 66 insertions(+), 34 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 57aa9bb59..f28ec988a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2007-01-17 Teodor Zlatanov + + * encrypt.el (encrypt-insert-file-contents): Add better prompt + to mention filename. + Add comments at beginning regarding usage. + (encrypt-write-file-contents): Change interactive so a string is + acceptable. If the file has no associated model, show an error instead + of a nonsense prompt. + 2007-01-16 TSUCHIYA Masatoshi * spam.el (spam-bsfilter-ham-switch): Fix typo. diff --git a/lisp/encrypt.el b/lisp/encrypt.el index bbf631a1a..493c7301d 100644 --- a/lisp/encrypt.el +++ b/lisp/encrypt.el @@ -28,6 +28,27 @@ ;;; grouping declarations and documentation relating to each ;;; particular aspect. +;;; Use in Gnus like this: +;;; (setq +;;; nnimap-authinfo-file "~/.authinfo.enc" +;;; nntp-authinfo-file "~/.authinfo.enc" +;;; smtpmail-auth-credentials "~/.authinfo.enc" +;;; ;; using the AES256 cipher, feel free to use your own favorite +;;; encrypt-file-alist (quote (("~/.authinfo.enc" (gpg "AES256")))) +;;; password-cache-expiry 600) + +;;; Then write ~/.authinfo.enc: + +;;; 1) open the old authinfo +;;; C-x C-f ~/.authinfo + +;;; 2) write the new authinfo.enc +;;; M-x encrypt-file-contents ~/.authinfo.enc + +;;; 3) verify the new authinfo is correct (this will show the contents in the minibuffer) +;;; M-: (encrypt-get-file-contents "~/.authinfo.enc") + + ;;; Code: ;; autoload password @@ -108,8 +129,8 @@ Format example: (symbol-name method) cipher file)) (passphrase (password-read-and-add - (format "%s password for cipher %s? " - (symbol-name method) cipher) + (format "%s password for cipher %s (file %s)? " + file (symbol-name method) cipher) password-key)) (buffer-file-coding-system 'binary) (coding-system-for-read 'binary) @@ -151,38 +172,40 @@ Format example: (defun encrypt-write-file-contents (file &optional model) "Encrypt the current buffer to FILE, then continue normally." - (interactive "fFile to write: ") - (let* ((model (or model (encrypt-find-model file))) - (method (nth 0 model)) - (cipher (nth 1 model)) - (password-key (format "encrypt-password-%s-%s %s" - (symbol-name method) cipher file)) - (passphrase - (password-read - (format "%s password for cipher %s? " - (symbol-name method) cipher) - password-key)) - outdata) - - (cond - ((eq method 'gpg) - (setq outdata (encrypt-gpg-encode-buffer passphrase cipher))) - ((eq method 'encrypt-xor) - (setq outdata (encrypt-xor-encode-buffer passphrase cipher)))) - - (if outdata - (progn - (message "%s was encrypted with %s (cipher %s)" - file (symbol-name method) cipher) - (delete-region (point-min) (point-max)) - (goto-char (point-min)) - (insert outdata) - ;; do not confirm overwrites - (write-file file nil)) - ;; the decryption failed, alas - (password-cache-remove password-key) - (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)" - file (symbol-name method) cipher)))) + (interactive "sFile to write: ") + (setq model (or model (encrypt-find-model file))) + (if model + (let* ((method (nth 0 model)) + (cipher (nth 1 model)) + (password-key (format "encrypt-password-%s-%s %s" + (symbol-name method) cipher file)) + (passphrase + (password-read + (format "%s password for cipher %s? " + (symbol-name method) cipher) + password-key)) + outdata) + + (cond + ((eq method 'gpg) + (setq outdata (encrypt-gpg-encode-buffer passphrase cipher))) + ((eq method 'encrypt-xor) + (setq outdata (encrypt-xor-encode-buffer passphrase cipher)))) + + (if outdata + (progn + (message "%s was encrypted with %s (cipher %s)" + file (symbol-name method) cipher) + (delete-region (point-min) (point-max)) + (goto-char (point-min)) + (insert outdata) + ;; do not confirm overwrites + (write-file file nil)) + ;; the decryption failed, alas + (password-cache-remove password-key) + (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)" + file (symbol-name method) cipher))) + (gnus-error 1 "%s has no associated encryption model! See encrypt-file-alist." file))) (defun encrypt-xor-encode-buffer (passphrase cipher) (encrypt-xor-process-buffer passphrase cipher t)) -- 2.25.1