* epg.el (epg-sign-file): Signal an error only when a signature is not
[elisp/epg.git] / epa.el
diff --git a/epa.el b/epa.el
index 579fcf9..c4f8700 100644 (file)
--- a/epa.el
+++ b/epa.el
                      ? ))
            (epg-sub-key-id primary-sub-key)
            " "
-           (epg-user-id-name primary-user-id))))
+           (if (stringp (epg-user-id-name primary-user-id))
+               (epg-user-id-name primary-user-id)
+             (epg-decode-dn (epg-user-id-name primary-user-id))))))
 
 (defun epa-key-widget-button-face-get (widget)
   (let ((validity (epg-sub-key-validity (car (epg-key-sub-key-list
   ;; if buffer-file-name is not set.
   (font-lock-set-defaults)
   (widget-setup)
+  (make-local-variable 'epa-exit-buffer-function)
   (run-hooks 'epa-keys-mode-hook))
 
 (defvar epa-key-mode-map
   (run-hooks 'epa-key-mode-hook))
 
 ;;;###autoload
-(defun epa-list-keys (&optional name mode)
+(defun epa-list-keys (&optional name mode protocol)
   (interactive
    (if current-prefix-arg
        (let ((name (read-string "Pattern: "
                                (if epa-list-keys-arguments
                                    (car epa-list-keys-arguments)))))
         (list (if (equal name "") nil name)
-              (y-or-n-p "Secret keys? ")))
-     (or epa-list-keys-arguments (list nil nil))))
+              (y-or-n-p "Secret keys? ")
+              (intern (completing-read "Protocol? "
+                                       '(("OpenPGP") ("CMS"))
+                                       nil t))))
+     (or epa-list-keys-arguments (list nil nil nil))))
   (unless (and epa-keys-buffer
               (buffer-live-p epa-keys-buffer))
     (setq epa-keys-buffer (generate-new-buffer "*Keys*")))
   (set-buffer epa-keys-buffer)
   (let ((inhibit-read-only t)
        buffer-read-only
-       (point (point-min)))
+       (point (point-min))
+       (context (epg-make-context protocol)))
     (unless (get-text-property point 'epa-list-keys)
       (setq point (next-single-property-change point 'epa-list-keys)))
     (when point
                     (or (next-single-property-change point 'epa-list-keys)
                         (point-max)))
       (goto-char point))
-    (epa-list-keys-1 name mode)
+    (epa-list-keys-1 context name mode)
     (epa-keys-mode))
   (make-local-variable 'epa-list-keys-arguments)
-  (setq epa-list-keys-arguments (list name mode))
+  (setq epa-list-keys-arguments (list name mode protocol))
   (goto-char (point-min))
   (pop-to-buffer (current-buffer)))
 
-(defun epa-list-keys-1 (name mode)
+(defun epa-list-keys-1 (context name mode)
   (save-restriction
     (narrow-to-region (point) (point))
     (let ((inhibit-read-only t)
          buffer-read-only
-         (keys (epg-list-keys name mode))
+         (keys (epg-list-keys context name mode))
          point)
       (while keys
        (setq point (point))
          (if key
              (list key))))))
 
-(defun epa-select-keys (prompt &optional names mode)
+(defun epa-select-keys (context prompt &optional names mode)
   (save-excursion
     (unless (and epa-keys-buffer
                 (buffer-live-p epa-keys-buffer))
       (if names
          (while names
            (setq point (point))
-           (epa-list-keys-1 (car names) mode)
+           (epa-list-keys-1 context (car names) mode)
            (goto-char point)
            (epa-mark)
            (goto-char (point-max))
            (setq names (cdr names)))
-       (epa-list-keys-1 nil mode))
+       (epa-list-keys-1 context nil mode))
       (epa-keys-mode)
       (setq epa-exit-buffer-function #'abort-recursive-edit)
       (goto-char (point-min))
                               epg-key-validity-alist)))
                " ")
              " "
-             (epg-user-id-name (car pointer))
+             (if (stringp (epg-user-id-name (car pointer)))
+                 (epg-user-id-name (car pointer))
+               (epg-decode-dn (epg-user-id-name (car pointer))))
              "\n")
       (setq pointer (cdr pointer)))
     (setq pointer (epg-key-sub-key-list key))
             (epg-verify-result-to-string
              (epg-context-result-for context 'verify)))))
 
-(defun epa-sign-file (file detached)
+(defun epa-sign-file (file signers detached)
   (interactive
    (list (expand-file-name (read-file-name "File: "))
+        (epa-select-keys (epg-make-context) "Select keys for signing.
+If no one is selected, default secret key is used.  "
+                         nil t)
         (y-or-n-p "Make a detached signature? ")))
   (let ((signature (concat file (if detached ".sig" ".gpg")))
        (context (epg-make-context)))
     (message "Signing %s..." (file-name-nondirectory file))
+    (epg-context-set-signers context signers)
     (epg-sign-file context file signature (not (null detached)))
     (message "Signing %s...done" (file-name-nondirectory file))))
 
 (defun epa-encrypt-file (file recipients)
   (interactive
    (list (expand-file-name (read-file-name "File: "))
-        (epa-select-keys "Select recipents for encryption.
+        (epa-select-keys (epg-make-context) "Select recipents for encryption.
 If no one is selected, symmetric encryption will be performed.  ")))
   (let ((cipher (concat file ".gpg"))
        (context (epg-make-context)))