Mercurial > emacs
annotate lisp/epg-config.el @ 111274:f746433112ea
* lisp/cedet/ede/proj-elisp.el (project-compile-target): Fix previous change.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sun, 31 Oct 2010 15:55:44 -0700 |
parents | 1b078a586243 |
children | 417b1e4d63cd |
rev | line source |
---|---|
91647 | 1 ;;; epg-config.el --- configuration of the EasyPG Library |
106000 | 2 |
106815 | 3 ;; Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
91647 | 4 |
5 ;; Author: Daiki Ueno <ueno@unixuser.org> | |
6 ;; Keywords: PGP, GnuPG | |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
107378
diff
changeset
|
7 ;; Package: epg |
91647 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91731
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
91647 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91731
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91731
diff
changeset
|
14 ;; (at your option) any later version. |
91647 | 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 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91731
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
91647 | 23 |
24 ;;; Code: | |
25 | |
91731
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
26 (defconst epg-package-name "epg" |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
27 "Name of this package.") |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
28 |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
29 (defconst epg-version-number "1.0.0" |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
30 "Version number of this package.") |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
31 |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
32 (defconst epg-bug-report-address "ueno@unixuser.org" |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
33 "Report bugs to this address.") |
91647 | 34 |
35 (defgroup epg () | |
106000 | 36 "The EasyPG library." |
91703
bda1e76bc03b
* epa.el (epa-faces, epa):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
91687
diff
changeset
|
37 :version "23.1" |
107378
904ccd8f2acb
Reorganize Custom groups.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
38 :group 'data) |
91647 | 39 |
111137
1b078a586243
Try to use "gpg2" if "gpg" isn't available.
Daiki Ueno <ueno@unixuser.org>
parents:
110015
diff
changeset
|
40 (defcustom epg-gpg-program (or (executable-find "gpg") |
1b078a586243
Try to use "gpg2" if "gpg" isn't available.
Daiki Ueno <ueno@unixuser.org>
parents:
110015
diff
changeset
|
41 (executable-find "gpg2") |
1b078a586243
Try to use "gpg2" if "gpg" isn't available.
Daiki Ueno <ueno@unixuser.org>
parents:
110015
diff
changeset
|
42 "gpg") |
91647 | 43 "The `gpg' executable." |
44 :group 'epg | |
45 :type 'string) | |
46 | |
47 (defcustom epg-gpgsm-program "gpgsm" | |
48 "The `gpgsm' executable." | |
49 :group 'epg | |
50 :type 'string) | |
51 | |
52 (defcustom epg-gpg-home-directory nil | |
53 "The directory which contains the configuration files of `epg-gpg-program'." | |
54 :group 'epg | |
55 :type '(choice (const :tag "Default" nil) directory)) | |
56 | |
57 (defcustom epg-passphrase-coding-system nil | |
58 "Coding system to use with messages from `epg-gpg-program'." | |
59 :group 'epg | |
60 :type 'symbol) | |
61 | |
62 (defcustom epg-debug nil | |
63 "If non-nil, debug output goes to the \" *epg-debug*\" buffer. | |
64 Note that the buffer name starts with a space." | |
65 :group 'epg | |
66 :type 'boolean) | |
67 | |
68 (defconst epg-gpg-minimum-version "1.4.3") | |
69 | |
70 ;;;###autoload | |
71 (defun epg-configuration () | |
72 "Return a list of internal configuration parameters of `epg-gpg-program'." | |
73 (let (config groups type args) | |
74 (with-temp-buffer | |
75 (apply #'call-process epg-gpg-program nil (list t nil) nil | |
76 (append (if epg-gpg-home-directory | |
77 (list "--homedir" epg-gpg-home-directory)) | |
78 '("--with-colons" "--list-config"))) | |
79 (goto-char (point-min)) | |
80 (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t) | |
81 (setq type (intern (match-string 1)) | |
82 args (match-string 2)) | |
83 (cond | |
84 ((eq type 'group) | |
85 (if (string-match "\\`\\([^:]+\\):" args) | |
86 (setq groups | |
87 (cons (cons (downcase (match-string 1 args)) | |
88 (delete "" (split-string | |
89 (substring args | |
90 (match-end 0)) | |
91 ";"))) | |
92 groups)) | |
93 (if epg-debug | |
94 (message "Invalid group configuration: %S" args)))) | |
95 ((memq type '(pubkey cipher digest compress)) | |
96 (if (string-match "\\`\\([0-9]+\\)\\(;[0-9]+\\)*" args) | |
97 (setq config | |
98 (cons (cons type | |
99 (mapcar #'string-to-number | |
100 (delete "" (split-string args ";")))) | |
101 config)) | |
102 (if epg-debug | |
103 (message "Invalid %S algorithm configuration: %S" | |
104 type args)))) | |
105 (t | |
106 (setq config (cons (cons type args) config)))))) | |
107 (if groups | |
108 (cons (cons 'groups groups) config) | |
109 config))) | |
110 | |
111 (defun epg-config--parse-version (string) | |
112 (let ((index 0) | |
113 version) | |
114 (while (eq index (string-match "\\([0-9]+\\)\\.?" string index)) | |
115 (setq version (cons (string-to-number (match-string 1 string)) | |
116 version) | |
117 index (match-end 0))) | |
118 (nreverse version))) | |
119 | |
120 (defun epg-config--compare-version (v1 v2) | |
121 (while (and v1 v2 (= (car v1) (car v2))) | |
122 (setq v1 (cdr v1) v2 (cdr v2))) | |
123 (- (or (car v1) 0) (or (car v2) 0))) | |
124 | |
125 ;;;###autoload | |
126 (defun epg-check-configuration (config &optional minimum-version) | |
127 "Verify that a sufficient version of GnuPG is installed." | |
128 (let ((entry (assq 'version config)) | |
129 version) | |
130 (unless (and entry | |
131 (stringp (cdr entry))) | |
132 (error "Undetermined version: %S" entry)) | |
133 (setq version (epg-config--parse-version (cdr entry)) | |
134 minimum-version (epg-config--parse-version | |
135 (or minimum-version | |
136 epg-gpg-minimum-version))) | |
137 (unless (>= (epg-config--compare-version version minimum-version) 0) | |
138 (error "Unsupported version: %s" (cdr entry))))) | |
139 | |
140 ;;;###autoload | |
141 (defun epg-expand-group (config group) | |
142 "Look at CONFIG and try to expand GROUP." | |
143 (let ((entry (assq 'groups config))) | |
144 (if (and entry | |
145 (setq entry (assoc (downcase group) (cdr entry)))) | |
146 (cdr entry)))) | |
147 | |
148 (provide 'epg-config) | |
149 | |
91687 | 150 ;; arch-tag: 9aca7cb8-5f63-4bcb-84ee-46fd2db0763f |
91647 | 151 ;;; epg-config.el ends here |