aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDaiki Ueno2016-05-19 18:05:19 +0900
committerDaiki Ueno2016-05-20 16:29:04 +0900
commit65e38569e5eca8e4e8a0e38391c07e3862e78cb7 (patch)
tree5360e3d251365b68281a7c7e06263de892113b6a /lisp
parent970074470d7bc332fc36fd30feee93e1d6130177 (diff)
downloademacs-65e38569e5eca8e4e8a0e38391c07e3862e78cb7.tar.gz
emacs-65e38569e5eca8e4e8a0e38391c07e3862e78cb7.zip
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')
-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."
81(defconst epg-config--program-alist 81(defconst epg-config--program-alist
82 '((OpenPGP 82 '((OpenPGP
83 epg-gpg-program 83 epg-gpg-program
84 epg-config--make-gpg-configuration
85 ("gpg2" . "2.1.6") ("gpg" . "1.4.3")) 84 ("gpg2" . "2.1.6") ("gpg" . "1.4.3"))
86 (CMS 85 (CMS
87 epg-gpgsm-program 86 epg-gpgsm-program
88 epg-config--make-gpgsm-configuration
89 ("gpgsm" . "2.0.4"))) 87 ("gpgsm" . "2.0.4")))
90 "Alist used to obtain the usable configuration of executables. 88 "Alist used to obtain the usable configuration of executables.
91The first element of each entry is protocol symbol, which is 89The first element of each entry is protocol symbol, which is
92either `OpenPGP' or `CMS'. The second element is a symbol where 90either `OpenPGP' or `CMS'. The second element is a symbol where
93the executable name is remembered. The third element is a 91the executable name is remembered. The rest of the entry is an
94function which constructs a configuration object (actually a 92alist mapping executable names to the minimum required version
95plist). The rest of the entry is an alist mapping executable 93suitable for the use with Emacs.")
96names to the minimum required version suitable for the use with 94
97Emacs.") 95(defconst epg-config--configuration-constructor-alist
96 '((OpenPGP . epg-config--make-gpg-configuration)
97 (CMS . epg-config--make-gpgsm-configuration))
98 "Alist used to obtain the usable configuration of executables.
99The first element of each entry is protocol symbol, which is
100either `OpenPGP' or `CMS'. The second element is a function
101which constructs a configuration object (actually a plist).")
98 102
99(defvar epg--configurations nil) 103(defvar epg--configurations nil)
100 104
101;;;###autoload 105;;;###autoload
102(defun epg-find-configuration (protocol &optional force) 106(defun epg-find-configuration (protocol &optional no-cache program-alist)
103 "Find or create a usable configuration to handle PROTOCOL. 107 "Find or create a usable configuration to handle PROTOCOL.
104This function first looks at the existing configuration found by 108This function first looks at the existing configuration found by
105the previous invocation of this function, unless FORCE is non-nil. 109the previous invocation of this function, unless NO-CACHE is non-nil.
106 110
107Then it walks through `epg-config--program-alist'. If 111Then it walks through PROGRAM-ALIST or
108`epg-gpg-program' or `epg-gpgsm-program' is already set with 112`epg-config--program-alist'. If `epg-gpg-program' or
109custom, use it. Otherwise, it tries the programs listed in the 113`epg-gpgsm-program' is already set with custom, use it.
110entry until the version requirement is met." 114Otherwise, it tries the programs listed in the entry until the
111 (let ((entry (assq protocol epg-config--program-alist))) 115version requirement is met."
116 (unless program-alist
117 (setq program-alist epg-config--program-alist))
118 (let ((entry (assq protocol program-alist)))
112 (unless entry 119 (unless entry
113 (error "Unknown protocol %S" protocol)) 120 (error "Unknown protocol %S" protocol))
114 (cl-destructuring-bind (symbol constructor . alist) 121 (cl-destructuring-bind (symbol . alist)
115 (cdr entry) 122 (cdr entry)
116 (or (and (not force) (alist-get protocol epg--configurations)) 123 (let ((constructor
117 ;; If the executable value is already set with M-x 124 (alist-get protocol epg-config--configuration-constructor-alist)))
118 ;; customize, use it without checking. 125 (or (and (not no-cache) (alist-get protocol epg--configurations))
119 (if (get symbol 'saved-value) 126 ;; If the executable value is already set with M-x
120 (let ((configuration (funcall constructor (symbol-value symbol)))) 127 ;; customize, use it without checking.
121 (push (cons protocol configuration) epg--configurations) 128 (if (and symbol (get symbol 'saved-value))
122 configuration) 129 (let ((configuration
123 (catch 'found 130 (funcall constructor (symbol-value symbol))))
124 (dolist (program-version alist) 131 (push (cons protocol configuration) epg--configurations)
125 (let ((executable (executable-find (car program-version)))) 132 configuration)
126 (when executable 133 (catch 'found
127 (let ((configuration 134 (dolist (program-version alist)
128 (funcall constructor executable))) 135 (let ((executable (executable-find (car program-version))))
129 (when (ignore-errors 136 (when executable
130 (epg-check-configuration configuration 137 (let ((configuration
131 (cdr program-version)) 138 (funcall constructor executable)))
132 t) 139 (when (ignore-errors
133 (push (cons protocol configuration) epg--configurations) 140 (epg-check-configuration configuration
134 (throw 'found configuration)))))))))))) 141 (cdr program-version))
142 t)
143 (unless no-cache
144 (push (cons protocol configuration)
145 epg--configurations))
146 (throw 'found configuration)))))))))))))
135 147
136;; Create an `epg-configuration' object for `gpg', using PROGRAM. 148;; Create an `epg-configuration' object for `gpg', using PROGRAM.
137(defun epg-config--make-gpg-configuration (program) 149(defun epg-config--make-gpg-configuration (program)