Revision: miles@gnu.org--gnu-2005/gnus--devo--0--patch-182
[gnus] / lisp / pgg.el
index 047a4cf..c9287ab 100644 (file)
@@ -1,6 +1,7 @@
 ;;; pgg.el --- glue for the various PGP implementations.
 
-;; Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
+;;   2005 Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Created: 1999/10/28
@@ -20,8 +21,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 
 (require 'pgg-def)
 (require 'pgg-parse)
-(autoload 'run-at-time "timer")
+(require 'password)
 
 ;; Don't merge these two `eval-when-compile's.
 (eval-when-compile
   (require 'cl))
-;; Fixme: This would be better done with an autoload for
-;; `url-insert-file-contents', and the url stuff rationalized.
-;; (`locate-library' can say whether the url code is available.)
-(eval-when-compile
-  (ignore-errors
-    (require 'w3)
-    (require 'url)))
 
 ;;; @ utility functions
 ;;;
 
-(defvar pgg-fetch-key-function (if (fboundp 'url-insert-file-contents)
-                                  (function pgg-fetch-key-with-w3)))
-
 (defun pgg-invoke (func scheme &rest args)
   (progn
     (require (intern (format "pgg-%s" scheme)))
        (set-buffer standard-output)
        (insert-buffer-substring pgg-errors-buffer)))))
 
-(defvar pgg-passphrase-cache (make-vector 7 0))
-
 (defun pgg-read-passphrase (prompt &optional key)
-  (or (and pgg-cache-passphrase
-          key (setq key (pgg-truncate-key-identifier key))
-          (symbol-value (intern-soft key pgg-passphrase-cache)))
-      (read-passwd prompt)))
-
-(eval-when-compile
-  (autoload 'delete-itimer "itimer")
-  (autoload 'set-itimer-function "itimer")
-  (autoload 'set-itimer-function-arguments "itimer")
-  (autoload 'set-itimer-restart "itimer"))
-
-(eval-and-compile
-  (defalias
-    'pgg-run-at-time
-    (if (featurep 'xemacs)
-       (lambda (time repeat function &rest args)
-         "Emulating function run as `run-at-time' in the right way.
-TIME should be nil meaning now or a number of seconds from now.
-Return an itimer object which can be used in either `delete-itimer'
-or `cancel-timer'."
-         (let ((itimers (list nil)))
-           (setcar
-            itimers
-            (apply #'start-itimer "pgg-run-at-time"
-                   (lambda (itimers repeat function &rest args)
-                     (let ((itimer (car itimers)))
-                       (if repeat
-                           (progn
-                             (set-itimer-function
-                              itimer
-                              (lambda (itimer repeat function &rest args)
-                                (set-itimer-restart itimer repeat)
-                                (set-itimer-function itimer function)
-                                (set-itimer-function-arguments itimer args)
-                                (apply function args)))
-                             (set-itimer-function-arguments
-                              itimer
-                              (append (list itimer repeat function) args)))
-                         (set-itimer-function
-                          itimer
-                          (lambda (itimer function &rest args)
-                            (delete-itimer itimer)
-                            (apply function args)))
-                         (set-itimer-function-arguments
-                          itimer
-                          (append (list itimer function) args)))))
-                   1e-9 (if time (max time 1e-9) 1e-9)
-                   nil t itimers repeat function args))))
-      'run-at-time)))
+  (when pgg-cache-passphrase
+    (password-read prompt (setq key (pgg-truncate-key-identifier key)))))
 
 (defun pgg-add-passphrase-cache (key passphrase)
-  (setq key (pgg-truncate-key-identifier key))
-  (set (intern key pgg-passphrase-cache)
-       passphrase)
-  (pgg-run-at-time pgg-passphrase-cache-expiry nil
-                  #'pgg-remove-passphrase-cache
-                  key))
+  (let ((password-cache-expiry pgg-passphrase-cache-expiry))
+    (password-cache-add (setq key (pgg-truncate-key-identifier key))
+                       passphrase)))
 
 (defun pgg-remove-passphrase-cache (key)
-  (let ((passphrase (symbol-value (intern-soft key pgg-passphrase-cache))))
-    (when passphrase
-      (fillarray passphrase ?_)
-      (unintern key pgg-passphrase-cache))))
+  (password-cache-remove key))
 
 (defmacro pgg-convert-lbt-region (start end lbt)
   `(let ((pgg-conversion-end (set-marker (make-marker) ,end)))
@@ -353,7 +289,8 @@ within the region."
        (with-output-to-temp-buffer pgg-echo-buffer
          (set-buffer standard-output)
          (insert-buffer-substring (if status pgg-output-buffer
-                                    pgg-errors-buffer)))))))
+                                    pgg-errors-buffer)))))
+    status))
 
 ;;;###autoload
 (defun pgg-insert-key ()
@@ -382,7 +319,6 @@ within the region."
 
 (defun pgg-insert-url-with-w3 (url)
   (ignore-errors
-    (require 'w3)
     (require 'url)
     (let (buffer-file-name)
       (url-insert-file-contents url))))
@@ -431,4 +367,5 @@ within the region."
 
 (provide 'pgg)
 
+;;; arch-tag: 9cc705dd-1e6a-4c90-8dce-c3561f9a2cf4
 ;;; pgg.el ends here