diff options
| author | Daiki Ueno | 2016-05-19 18:05:19 +0900 |
|---|---|---|
| committer | Daiki Ueno | 2016-05-20 16:29:04 +0900 |
| commit | 65e38569e5eca8e4e8a0e38391c07e3862e78cb7 (patch) | |
| tree | 5360e3d251365b68281a7c7e06263de892113b6a /lisp | |
| parent | 970074470d7bc332fc36fd30feee93e1d6130177 (diff) | |
| download | emacs-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.el | 82 |
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. |
| 91 | The first element of each entry is protocol symbol, which is | 89 | The first element of each entry is protocol symbol, which is |
| 92 | either `OpenPGP' or `CMS'. The second element is a symbol where | 90 | either `OpenPGP' or `CMS'. The second element is a symbol where |
| 93 | the executable name is remembered. The third element is a | 91 | the executable name is remembered. The rest of the entry is an |
| 94 | function which constructs a configuration object (actually a | 92 | alist mapping executable names to the minimum required version |
| 95 | plist). The rest of the entry is an alist mapping executable | 93 | suitable for the use with Emacs.") |
| 96 | names to the minimum required version suitable for the use with | 94 | |
| 97 | Emacs.") | 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. | ||
| 99 | The first element of each entry is protocol symbol, which is | ||
| 100 | either `OpenPGP' or `CMS'. The second element is a function | ||
| 101 | which 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. |
| 104 | This function first looks at the existing configuration found by | 108 | This function first looks at the existing configuration found by |
| 105 | the previous invocation of this function, unless FORCE is non-nil. | 109 | the previous invocation of this function, unless NO-CACHE is non-nil. |
| 106 | 110 | ||
| 107 | Then it walks through `epg-config--program-alist'. If | 111 | Then 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 |
| 109 | custom, use it. Otherwise, it tries the programs listed in the | 113 | `epg-gpgsm-program' is already set with custom, use it. |
| 110 | entry until the version requirement is met." | 114 | Otherwise, it tries the programs listed in the entry until the |
| 111 | (let ((entry (assq protocol epg-config--program-alist))) | 115 | version 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) |