Commit | Line | Data |
---|---|---|
c154c0be | 1 | ;;; epg-config.el --- configuration of the EasyPG Library |
d3135746 | 2 | |
acaf905b | 3 | ;; Copyright (C) 2006-2012 Free Software Foundation, Inc. |
c154c0be MO |
4 | |
5 | ;; Author: Daiki Ueno <ueno@unixuser.org> | |
6 | ;; Keywords: PGP, GnuPG | |
bd78fa1d | 7 | ;; Package: epg |
c154c0be MO |
8 | |
9 | ;; This file is part of GNU Emacs. | |
10 | ||
eb3fa2cf | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
c154c0be | 12 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
c154c0be MO |
15 | |
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
c154c0be MO |
23 | |
24 | ;;; Code: | |
25 | ||
f1914c40 MO |
26 | (defconst epg-package-name "epg" |
27 | "Name of this package.") | |
28 | ||
29 | (defconst epg-version-number "1.0.0" | |
30 | "Version number of this package.") | |
31 | ||
32 | (defconst epg-bug-report-address "ueno@unixuser.org" | |
33 | "Report bugs to this address.") | |
c154c0be MO |
34 | |
35 | (defgroup epg () | |
cf20dee0 CY |
36 | "Interface to the GNU Privacy Guard (GnuPG)." |
37 | :tag "EasyPG" | |
0bd4f317 | 38 | :version "23.1" |
cf20dee0 CY |
39 | :group 'data |
40 | :group 'external) | |
c154c0be | 41 | |
3ec6ca72 DU |
42 | (defcustom epg-gpg-program (or (executable-find "gpg") |
43 | (executable-find "gpg2") | |
44 | "gpg") | |
c154c0be MO |
45 | "The `gpg' executable." |
46 | :group 'epg | |
47 | :type 'string) | |
48 | ||
49 | (defcustom epg-gpgsm-program "gpgsm" | |
50 | "The `gpgsm' executable." | |
51 | :group 'epg | |
52 | :type 'string) | |
53 | ||
54 | (defcustom epg-gpg-home-directory nil | |
55 | "The directory which contains the configuration files of `epg-gpg-program'." | |
56 | :group 'epg | |
57 | :type '(choice (const :tag "Default" nil) directory)) | |
58 | ||
59 | (defcustom epg-passphrase-coding-system nil | |
60 | "Coding system to use with messages from `epg-gpg-program'." | |
61 | :group 'epg | |
62 | :type 'symbol) | |
63 | ||
64 | (defcustom epg-debug nil | |
65 | "If non-nil, debug output goes to the \" *epg-debug*\" buffer. | |
66 | Note that the buffer name starts with a space." | |
67 | :group 'epg | |
68 | :type 'boolean) | |
69 | ||
70 | (defconst epg-gpg-minimum-version "1.4.3") | |
71 | ||
72 | ;;;###autoload | |
73 | (defun epg-configuration () | |
74 | "Return a list of internal configuration parameters of `epg-gpg-program'." | |
75 | (let (config groups type args) | |
76 | (with-temp-buffer | |
77 | (apply #'call-process epg-gpg-program nil (list t nil) nil | |
78 | (append (if epg-gpg-home-directory | |
79 | (list "--homedir" epg-gpg-home-directory)) | |
80 | '("--with-colons" "--list-config"))) | |
81 | (goto-char (point-min)) | |
82 | (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t) | |
83 | (setq type (intern (match-string 1)) | |
84 | args (match-string 2)) | |
85 | (cond | |
86 | ((eq type 'group) | |
87 | (if (string-match "\\`\\([^:]+\\):" args) | |
88 | (setq groups | |
89 | (cons (cons (downcase (match-string 1 args)) | |
90 | (delete "" (split-string | |
91 | (substring args | |
92 | (match-end 0)) | |
93 | ";"))) | |
94 | groups)) | |
95 | (if epg-debug | |
96 | (message "Invalid group configuration: %S" args)))) | |
97 | ((memq type '(pubkey cipher digest compress)) | |
98 | (if (string-match "\\`\\([0-9]+\\)\\(;[0-9]+\\)*" args) | |
99 | (setq config | |
100 | (cons (cons type | |
101 | (mapcar #'string-to-number | |
102 | (delete "" (split-string args ";")))) | |
103 | config)) | |
104 | (if epg-debug | |
105 | (message "Invalid %S algorithm configuration: %S" | |
106 | type args)))) | |
107 | (t | |
108 | (setq config (cons (cons type args) config)))))) | |
109 | (if groups | |
110 | (cons (cons 'groups groups) config) | |
111 | config))) | |
112 | ||
113 | (defun epg-config--parse-version (string) | |
114 | (let ((index 0) | |
115 | version) | |
116 | (while (eq index (string-match "\\([0-9]+\\)\\.?" string index)) | |
117 | (setq version (cons (string-to-number (match-string 1 string)) | |
118 | version) | |
119 | index (match-end 0))) | |
120 | (nreverse version))) | |
121 | ||
122 | (defun epg-config--compare-version (v1 v2) | |
123 | (while (and v1 v2 (= (car v1) (car v2))) | |
124 | (setq v1 (cdr v1) v2 (cdr v2))) | |
125 | (- (or (car v1) 0) (or (car v2) 0))) | |
126 | ||
127 | ;;;###autoload | |
128 | (defun epg-check-configuration (config &optional minimum-version) | |
129 | "Verify that a sufficient version of GnuPG is installed." | |
130 | (let ((entry (assq 'version config)) | |
131 | version) | |
132 | (unless (and entry | |
133 | (stringp (cdr entry))) | |
134 | (error "Undetermined version: %S" entry)) | |
135 | (setq version (epg-config--parse-version (cdr entry)) | |
136 | minimum-version (epg-config--parse-version | |
137 | (or minimum-version | |
138 | epg-gpg-minimum-version))) | |
139 | (unless (>= (epg-config--compare-version version minimum-version) 0) | |
140 | (error "Unsupported version: %s" (cdr entry))))) | |
141 | ||
142 | ;;;###autoload | |
143 | (defun epg-expand-group (config group) | |
144 | "Look at CONFIG and try to expand GROUP." | |
145 | (let ((entry (assq 'groups config))) | |
146 | (if (and entry | |
147 | (setq entry (assoc (downcase group) (cdr entry)))) | |
148 | (cdr entry)))) | |
149 | ||
150 | (provide 'epg-config) | |
151 | ||
152 | ;;; epg-config.el ends here |