(encrypt-insert-file-contents): Add better prompt
authorTeodor Zlatanov <tzz@lifelogs.com>
Wed, 17 Jan 2007 19:33:51 +0000 (19:33 +0000)
committerTeodor Zlatanov <tzz@lifelogs.com>
Wed, 17 Jan 2007 19:33:51 +0000 (19:33 +0000)
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
lisp/encrypt.el

index 57aa9bb..f28ec98 100644 (file)
@@ -1,3 +1,12 @@
+2007-01-17  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * 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  <tsuchiya@namazu.org>
 
        * spam.el (spam-bsfilter-ham-switch): Fix typo.
index bbf631a..493c730 100644 (file)
 ;;; 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))