;;; epg.el --- the EasyPG Library -*- lexical-binding: t -*-
-;; Copyright (C) 1999-2000, 2002-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2000, 2002-2014 Free Software Foundation, Inc.
;; Author: Daiki Ueno <ueno@unixuser.org>
;; Keywords: PGP, GnuPG
(?f . full)
(?u . ultimate)))
-(defvar epg-key-capablity-alist
+(defvar epg-key-capability-alist
'((?e . encrypt)
(?s . sign)
(?c . certify)
(defvar epg-prompt-alist nil)
-(put 'epg-error 'error-conditions '(epg-error error))
-(put 'epg-error 'error-message "GPG error")
+(define-error 'epg-error "GPG error")
(defun epg-make-data-from-file (file)
"Make a data object from FILE."
((eq (car error) 'exit)
"Exit")
((eq (car error) 'quit)
- "Cancelled")
+ "Canceled")
((eq (car error) 'no-data)
(let ((entry (assq (cdr error) epg-no-data-reason-alist)))
(if entry
(coding-system-for-read 'binary)
process-connection-type
(process-environment process-environment)
- (orig-mode (default-file-modes))
(buffer (generate-new-buffer " *epg*"))
process
terminal-name
(setq epg-agent-file agent-file)
(make-local-variable 'epg-agent-mtime)
(setq epg-agent-mtime agent-mtime))
- (unwind-protect
- (progn
- (set-default-file-modes 448)
- (setq process
- (apply #'start-process "epg" buffer
- (epg-context-program context)
- args)))
- (set-default-file-modes orig-mode))
+ (with-file-modes 448
+ (setq process (apply #'start-process "epg" buffer
+ (epg-context-program context) args)))
(set-process-filter process #'epg--process-filter)
(epg-context-set-process context process)))
(defun epg--process-filter (process input)
(if epg-debug
- (save-excursion
- (unless epg-debug-buffer
- (setq epg-debug-buffer (generate-new-buffer " *epg-debug*")))
- (set-buffer epg-debug-buffer)
+ (with-current-buffer
+ (or epg-debug-buffer
+ (setq epg-debug-buffer (generate-new-buffer " *epg-debug*")))
(goto-char (point-max))
(insert input)))
(if (buffer-live-p (process-buffer process))
(with-current-buffer (process-buffer process)
- (goto-char (point-max))
- (insert input)
- (unless epg-process-filter-running
- (unwind-protect
- (progn
- (setq epg-process-filter-running t)
- (goto-char epg-read-point)
- (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))))
- (if (member status epg-pending-status-list)
- (setq epg-pending-status-list nil))
- (if (and symbol
- (fboundp symbol))
- (funcall symbol epg-context string))
- (setq epg-last-status (cons status string))))
- (forward-line)
- (setq epg-read-point (point))))
- (setq epg-process-filter-running nil))))))
+ (save-excursion
+ (goto-char (point-max))
+ (insert input)
+ (unless epg-process-filter-running
+ (let ((epg-process-filter-running t))
+ (goto-char epg-read-point)
+ (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))))
+ (if (member status epg-pending-status-list)
+ (setq epg-pending-status-list nil))
+ (if (and symbol
+ (fboundp symbol))
+ (funcall symbol epg-context string))
+ (setq epg-last-status (cons status string))))
+ (forward-line)
+ (setq epg-read-point (point)))))))))
(defun epg-read-output (context)
"Read the output file CONTEXT and return the content as a string."
(> (float-time (or (nth 5 (file-attributes epg-agent-file))
'(0 0 0 0)))
(float-time epg-agent-mtime))))
- (redraw-frame (selected-frame)))
+ (redraw-frame))
(epg-context-set-result-for
context 'error
(nreverse (epg-context-result-for context 'error))))
(if (aref line 1)
(cdr (assq (string-to-char (aref line 1)) epg-key-validity-alist)))
(delq nil
- (mapcar (lambda (char) (cdr (assq char epg-key-capablity-alist)))
+ (mapcar (lambda (char) (cdr (assq char epg-key-capability-alist)))
(aref line 11)))
(member (aref line 0) '("sec" "ssb"))
(string-to-number (aref line 3))
For a detached signature, both SIGNATURE and SIGNED-TEXT should be
string. For a normal or a cleartext signature, SIGNED-TEXT should be
nil. In the latter case, if PLAIN is specified, the plaintext is
-stored into the file after successful verification."
+stored into the file after successful verification.
+
+Note that this function does not return verification result as t
+or nil, nor signal error on failure. That's a design decision to
+handle the case where SIGNATURE has multiple signature.
+
+To check the verification results, use `epg-context-result-for' as follows:
+
+\(epg-context-result-for context 'verify)
+
+which will return a list of `epg-signature' object."
(unwind-protect
(progn
(if plain
For a detached signature, both SIGNATURE and SIGNED-TEXT should be
string. For a normal or a cleartext signature, SIGNED-TEXT should be
nil. In the latter case, this function returns the plaintext after
-successful verification."
+successful verification.
+
+Note that this function does not return verification result as t
+or nil, nor signal error on failure. That's a design decision to
+handle the case where SIGNATURE has multiple signature.
+
+To check the verification results, use `epg-context-result-for' as follows:
+
+\(epg-context-result-for context 'verify)
+
+which will return a list of `epg-signature' object."
(let ((coding-system-for-write 'binary)
input-file)
(unwind-protect
(list "--" (epg-data-file plain)))))
;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
(unless (eq (epg-context-protocol context) 'CMS)
- (if sign
- (epg-wait-for-status context '("BEGIN_SIGNING"))
- (epg-wait-for-status context '("BEGIN_ENCRYPTION"))))
+ (epg-wait-for-status context
+ (if sign '("BEGIN_SIGNING") '("BEGIN_ENCRYPTION"))))
(when (epg-data-string plain)
(if (eq (process-status (epg-context-process context)) 'run)
(process-send-string (epg-context-process context)