* gnus-start.el (gnus-convert-old-newsrc): Fixed numeric
[gnus] / lisp / pgg-pgp.el
index 4ac1b5d..0d7dfac 100644 (file)
@@ -1,22 +1,22 @@
 ;;; pgg-pgp.el --- PGP 2.* and 6.* support for PGG.
 
-;; Copyright (C) 1999,2000 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Created: 1999/11/02
 ;; Keywords: PGP, OpenPGP
 
-;; This file is part of SEMI (Secure Emacs MIME Interface).
+;; This file is part of GNU Emacs.
 
-;; This program is free software; you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as
-;; published by the Free Software Foundation; either version 2, or (at
-;; your option) any later version.
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
 
-;; This program is distributed in the hope that it will be useful, but
-;; WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-;; General Public License for more details.
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
 
 ;; 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
@@ -25,7 +25,9 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'pgg))
+(eval-when-compile
+  (require 'cl)                                ; for pgg macros
+  (require 'pgg))
 
 (defgroup pgg-pgp ()
   "PGP 2.* and 6.* interface"
@@ -58,9 +60,7 @@ Bourne shell or its equivalent \(not tcsh) is needed for \"2>\"."
   "PGP ID of your default identity.")
 
 (defun pgg-pgp-process-region (start end passphrase program args)
-  (let* ((errors-file-name
-         (expand-file-name (make-temp-name "pgg-errors")  
-                           pgg-temporary-file-directory))
+  (let* ((errors-file-name (pgg-make-temp-file "pgg-errors"))
         (args
          (append args
                  pgg-pgp-extra-args
@@ -148,14 +148,16 @@ Bourne shell or its equivalent \(not tcsh) is needed for \"2>\"."
 (defun pgg-pgp-decrypt-region (start end)
   "Decrypt the current region between START and END."
   (let* ((pgg-pgp-user-id (or pgg-pgp-user-id pgg-default-user-id))
+        (key (pgg-pgp-lookup-key pgg-pgp-user-id 'encrypt))
         (passphrase
          (pgg-read-passphrase
-          (format "PGP passphrase for %s: " pgg-pgp-user-id)
-          (pgg-pgp-lookup-key pgg-pgp-user-id 'encrypt)))
+          (format "PGP passphrase for %s: " pgg-pgp-user-id) key))
         (args
          '("+verbose=1" "+batchmode" "+language=us" "-f")))
     (pgg-pgp-process-region start end passphrase pgg-pgp-program args)
-    (pgg-process-when-success nil)))
+    (pgg-process-when-success
+      (if pgg-cache-passphrase
+         (pgg-add-passphrase-cache key passphrase)))))
 
 (defun pgg-pgp-sign-region (start end &optional clearsign)
   "Make detached signature from text between START and END."
@@ -184,8 +186,7 @@ Bourne shell or its equivalent \(not tcsh) is needed for \"2>\"."
 
 (defun pgg-pgp-verify-region (start end &optional signature)
   "Verify region between START and END as the detached signature SIGNATURE."
-  (let* ((basename (expand-file-name "pgg" temporary-file-directory))
-        (orig-file (make-temp-name basename))
+  (let* ((orig-file (pgg-make-temp-file "pgg"))
         (args '("+verbose=1" "+batchmode" "+language=us"))
         (orig-mode (default-file-modes)))
     (unwind-protect
@@ -195,9 +196,11 @@ Bourne shell or its equivalent \(not tcsh) is needed for \"2>\"."
                jka-compr-compression-info-list jam-zcat-filename-list)
            (write-region start end orig-file)))
       (set-default-file-modes orig-mode))
-    (when (stringp signature)
-      (copy-file signature (setq signature (concat orig-file ".asc")))
-      (setq args (append args (list signature orig-file))))
+    (if (stringp signature)
+       (progn
+         (copy-file signature (setq signature (concat orig-file ".asc")))
+         (setq args (append args (list signature orig-file))))
+      (setq args (append args (list orig-file))))
     (pgg-pgp-process-region (point)(point) nil pgg-pgp-program args)
     (delete-file orig-file)
     (if signature (delete-file signature))
@@ -225,8 +228,7 @@ Bourne shell or its equivalent \(not tcsh) is needed for \"2>\"."
 (defun pgg-pgp-snarf-keys-region (start end)
   "Add all public keys in region between START and END to the keyring."
   (let* ((pgg-pgp-user-id (or pgg-pgp-user-id pgg-default-user-id))
-        (basename (expand-file-name "pgg" temporary-file-directory))
-        (key-file (make-temp-name basename))
+        (key-file (pgg-make-temp-file "pgg"))
         (args
          (list "+verbose=1" "+batchmode" "+language=us" "-kaf"
                key-file)))
@@ -238,4 +240,5 @@ Bourne shell or its equivalent \(not tcsh) is needed for \"2>\"."
 
 (provide 'pgg-pgp)
 
+;;; arch-tag: 076b7801-37b2-49a6-97c3-218fdecde33c
 ;;; pgg-pgp.el ends here