]> code.delx.au - gnu-emacs/blobdiff - lisp/epg.el
emacs-lisp/package.el: Fix previous patch
[gnu-emacs] / lisp / epg.el
index e4d8c1e1a024d134733c86d8c3ca252de4fca21a..f66545306dacaa621f88ea19f7daf02e37ac3108 100644 (file)
@@ -1,5 +1,5 @@
 ;;; epg.el --- the EasyPG Library -*- lexical-binding: t -*-
-;; Copyright (C) 1999-2000, 2002-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2000, 2002-2015 Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Keywords: PGP, GnuPG
   compress-algorithm
   (passphrase-callback (list #'epg-passphrase-callback-function))
   progress-callback
+  edit-callback
   signers
   sig-notations
   process
@@ -252,9 +253,9 @@ installing GnuPG 1.x _along with_ GnuPG 2.x, which does passphrase
 query by itself and Emacs can intercept them."
   ;; (declare (obsolete setf "25.1"))
   (setf (epg-context-passphrase-callback context)
-        (if (consp passphrase-callback) ;FIXME: functions can also be consp!
-            passphrase-callback
-          (list passphrase-callback))))
+        (if (functionp passphrase-callback)
+           (list passphrase-callback)
+         passphrase-callback)))
 
 (defun epg-context-set-progress-callback (context
                                          progress-callback)
@@ -268,9 +269,9 @@ description, the character to display a progress unit, the
 current amount done, the total amount to be done, and the
 callback data (if any)."
   (setf (epg-context-progress-callback context)
-        (if (consp progress-callback) ;FIXME: could be a function!
-            progress-callback
-          (list progress-callback))))
+        (if (functionp progress-callback)
+            (list progress-callback)
+          progress-callback)))
 
 (defun epg-context-set-signers (context signers)
   "Set the list of key-id for signing."
@@ -668,15 +669,27 @@ callback data (if any)."
               (beginning-of-line)
               (while (looking-at ".*\n") ;the input line finished
                 (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\) ?\\(.*\\)")
-                    (let* ((status (match-string 1))
-                           (string (match-string 2))
-                           (symbol (intern-soft (concat "epg--status-"
-                                                        status))))
+                    (let ((status (match-string 1))
+                         (string (match-string 2))
+                         symbol)
                       (if (member status epg-pending-status-list)
                           (setq epg-pending-status-list nil))
-                      (if (and symbol
-                               (fboundp symbol))
-                          (funcall symbol epg-context string))
+                     ;; When editing a key, delegate all interaction
+                     ;; to edit-callback.
+                     (if (eq (epg-context-operation epg-context) 'edit-key)
+                         (funcall (car (epg-context-edit-callback
+                                        epg-context))
+                                  epg-context
+                                  status
+                                  string
+                                  (cdr (epg-context-edit-callback
+                                        epg-context)))
+                       ;; Otherwise call epg--status-STATUS function.
+                       (setq symbol (intern-soft (concat "epg--status-"
+                                                         status)))
+                       (if (and symbol
+                                (fboundp symbol))
+                           (funcall symbol epg-context string)))
                       (setq epg-last-status (cons status string)))
                  ;; Record other lines sent to stderr.  This assumes
                  ;; that the process-filter receives output only from
@@ -736,7 +749,8 @@ callback data (if any)."
   (if (and (epg-context-process context)
           (buffer-live-p (process-buffer (epg-context-process context))))
       (kill-buffer (process-buffer (epg-context-process context))))
-  (setf (epg-context-process context) nil))
+  (setf (epg-context-process context) nil)
+  (setf (epg-context-edit-callback context) nil))
 
 (defun epg-delete-output-file (context)
   "Delete the output file of CONTEXT."
@@ -2084,6 +2098,38 @@ PARAMETERS is a string which tells how to create the key."
                            (epg-errors-to-string errors))))))
     (epg-reset context)))
 
+(defun epg-start-edit-key (context key edit-callback handback)
+  "Initiate an edit operation on KEY.
+
+EDIT-CALLBACK is called from process filter and takes 3
+arguments: the context, a status, an argument string, and the
+handback argument.
+
+If you use this function, you will need to wait for the completion of
+`epg-gpg-program' by using `epg-wait-for-completion' and call
+`epg-reset' to clear a temporary output file.
+If you are unsure, use synchronous version of this function
+`epg-edit-key' instead."
+  (setf (epg-context-operation context) 'edit-key)
+  (setf (epg-context-result context) nil)
+  (setf (epg-context-edit-callback context) (cons edit-callback handback))
+  (epg--start context (list "--edit-key"
+                           (epg-sub-key-id
+                            (car (epg-key-sub-key-list key))))))
+
+(defun epg-edit-key (context key edit-callback handback)
+  "Edit KEY in the keyring."
+  (unwind-protect
+      (progn
+       (epg-start-edit-key context key edit-callback handback)
+       (epg-wait-for-completion context)
+       (let ((errors (epg-context-result-for context 'error)))
+         (if errors
+             (signal 'epg-error
+                     (list "Edit key failed"
+                           (epg-errors-to-string errors))))))
+    (epg-reset context)))
+
 (defun epg--decode-percent-escape (string)
   (let ((index 0))
     (while (string-match "%\\(\\(%\\)\\|\\([0-9A-Fa-f][0-9A-Fa-f]\\)\\)"