summaryrefslogtreecommitdiff
path: root/lisp/epg-config.el
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2016-05-19 18:05:19 +0900
committerDaiki Ueno <ueno@gnu.org>2016-05-19 18:11:06 +0900
commitd4ae6d7033b34e8b75c59aaf1584131e439ef2d5 (patch)
treebf3d9d66e3e2356d3933236e6f0897677d721d5c /lisp/epg-config.el
parentebc3a94e27ec9dcbe24790795741c062bed2c1a0 (diff)
downloademacs-d4ae6d7033b34e8b75c59aaf1584131e439ef2d5.tar.gz
epg: Add a way to detect gpg1 executable for tests
Fixes bug#23561. * test/automated/epg-tests.el (epg-tests-program-alist-for-passphrase-callback): New constant. (epg-tests-find-usable-gpg-configuration): New function, renamed from `epg-tests-gpg-usable'. All callers changed. (epg-tests-gpg-usable): Remove. * lisp/epg-config.el (epg-config--program-alist): Factor out constructor element to... (epg-config--configuration-constructor-alist): ...here. (epg-find-configuration): Rename FORCE argument to NO-CACHE, and add PROGRAM-ALIST argument.
Diffstat (limited to 'lisp/epg-config.el')
-rw-r--r--lisp/epg-config.el82
1 files changed, 47 insertions, 35 deletions
diff --git a/lisp/epg-config.el b/lisp/epg-config.el
index 8a208044cba..9179e04dcc1 100644
--- a/lisp/epg-config.el
+++ b/lisp/epg-config.el
@@ -81,57 +81,69 @@ Note that the buffer name starts with a space."
(defconst epg-config--program-alist
'((OpenPGP
epg-gpg-program
- epg-config--make-gpg-configuration
("gpg2" . "2.1.6") ("gpg" . "1.4.3"))
(CMS
epg-gpgsm-program
- epg-config--make-gpgsm-configuration
("gpgsm" . "2.0.4")))
"Alist used to obtain the usable configuration of executables.
The first element of each entry is protocol symbol, which is
either `OpenPGP' or `CMS'. The second element is a symbol where
-the executable name is remembered. The third element is a
-function which constructs a configuration object (actually a
-plist). The rest of the entry is an alist mapping executable
-names to the minimum required version suitable for the use with
-Emacs.")
+the executable name is remembered. The rest of the entry is an
+alist mapping executable names to the minimum required version
+suitable for the use with Emacs.")
+
+(defconst epg-config--configuration-constructor-alist
+ '((OpenPGP . epg-config--make-gpg-configuration)
+ (CMS . epg-config--make-gpgsm-configuration))
+ "Alist used to obtain the usable configuration of executables.
+The first element of each entry is protocol symbol, which is
+either `OpenPGP' or `CMS'. The second element is a function
+which constructs a configuration object (actually a plist).")
(defvar epg--configurations nil)
;;;###autoload
-(defun epg-find-configuration (protocol &optional force)
+(defun epg-find-configuration (protocol &optional no-cache program-alist)
"Find or create a usable configuration to handle PROTOCOL.
This function first looks at the existing configuration found by
-the previous invocation of this function, unless FORCE is non-nil.
-
-Then it walks through `epg-config--program-alist'. If
-`epg-gpg-program' or `epg-gpgsm-program' is already set with
-custom, use it. Otherwise, it tries the programs listed in the
-entry until the version requirement is met."
- (let ((entry (assq protocol epg-config--program-alist)))
+the previous invocation of this function, unless NO-CACHE is non-nil.
+
+Then it walks through PROGRAM-ALIST or
+`epg-config--program-alist'. If `epg-gpg-program' or
+`epg-gpgsm-program' is already set with custom, use it.
+Otherwise, it tries the programs listed in the entry until the
+version requirement is met."
+ (unless program-alist
+ (setq program-alist epg-config--program-alist))
+ (let ((entry (assq protocol program-alist)))
(unless entry
(error "Unknown protocol %S" protocol))
- (cl-destructuring-bind (symbol constructor . alist)
+ (cl-destructuring-bind (symbol . alist)
(cdr entry)
- (or (and (not force) (alist-get protocol epg--configurations))
- ;; If the executable value is already set with M-x
- ;; customize, use it without checking.
- (if (get symbol 'saved-value)
- (let ((configuration (funcall constructor (symbol-value symbol))))
- (push (cons protocol configuration) epg--configurations)
- configuration)
- (catch 'found
- (dolist (program-version alist)
- (let ((executable (executable-find (car program-version))))
- (when executable
- (let ((configuration
- (funcall constructor executable)))
- (when (ignore-errors
- (epg-check-configuration configuration
- (cdr program-version))
- t)
- (push (cons protocol configuration) epg--configurations)
- (throw 'found configuration))))))))))))
+ (let ((constructor
+ (alist-get protocol epg-config--configuration-constructor-alist)))
+ (or (and (not no-cache) (alist-get protocol epg--configurations))
+ ;; If the executable value is already set with M-x
+ ;; customize, use it without checking.
+ (if (and symbol (get symbol 'saved-value))
+ (let ((configuration
+ (funcall constructor (symbol-value symbol))))
+ (push (cons protocol configuration) epg--configurations)
+ configuration)
+ (catch 'found
+ (dolist (program-version alist)
+ (let ((executable (executable-find (car program-version))))
+ (when executable
+ (let ((configuration
+ (funcall constructor executable)))
+ (when (ignore-errors
+ (epg-check-configuration configuration
+ (cdr program-version))
+ t)
+ (unless no-cache
+ (push (cons protocol configuration)
+ epg--configurations))
+ (throw 'found configuration)))))))))))))
;; Create an `epg-configuration' object for `gpg', using PROGRAM.
(defun epg-config--make-gpg-configuration (program)