Mercurial > emacs
annotate lisp/epg-config.el @ 101707:4bb10611bac4
(rmail-redecode-body): Don't change EOL conversion of the new encoding if
the old one left it unspecified.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 31 Jan 2009 10:08:37 +0000 |
parents | a9dc0e7c3f2b |
children | 44a26392fd09 |
rev | line source |
---|---|
91647 | 1 ;;; epg-config.el --- configuration of the EasyPG Library |
100908 | 2 ;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
91647 | 3 |
4 ;; Author: Daiki Ueno <ueno@unixuser.org> | |
5 ;; Keywords: PGP, GnuPG | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91731
diff
changeset
|
9 ;; GNU Emacs is free software: you can redistribute it and/or modify |
91647 | 10 ;; 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
|
11 ;; 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
|
12 ;; (at your option) any later version. |
91647 | 13 |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; 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
|
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
91647 | 21 |
22 ;;; Code: | |
23 | |
91731
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
24 (defconst epg-package-name "epg" |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
25 "Name of this package.") |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
26 |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
27 (defconst epg-version-number "1.0.0" |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
28 "Version number of this package.") |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
29 |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91703
diff
changeset
|
30 (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
|
31 "Report bugs to this address.") |
91647 | 32 |
33 (defgroup epg () | |
34 "The EasyPG Library" | |
91703
bda1e76bc03b
* epa.el (epa-faces, epa):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
91687
diff
changeset
|
35 :version "23.1" |
91647 | 36 :group 'emacs) |
37 | |
38 (defcustom epg-gpg-program "gpg" | |
39 "The `gpg' executable." | |
40 :group 'epg | |
41 :type 'string) | |
42 | |
43 (defcustom epg-gpgsm-program "gpgsm" | |
44 "The `gpgsm' executable." | |
45 :group 'epg | |
46 :type 'string) | |
47 | |
48 (defcustom epg-gpg-home-directory nil | |
49 "The directory which contains the configuration files of `epg-gpg-program'." | |
50 :group 'epg | |
51 :type '(choice (const :tag "Default" nil) directory)) | |
52 | |
53 (defcustom epg-passphrase-coding-system nil | |
54 "Coding system to use with messages from `epg-gpg-program'." | |
55 :group 'epg | |
56 :type 'symbol) | |
57 | |
58 (defcustom epg-debug nil | |
59 "If non-nil, debug output goes to the \" *epg-debug*\" buffer. | |
60 Note that the buffer name starts with a space." | |
61 :group 'epg | |
62 :type 'boolean) | |
63 | |
64 (defconst epg-gpg-minimum-version "1.4.3") | |
65 | |
66 ;;;###autoload | |
67 (defun epg-configuration () | |
68 "Return a list of internal configuration parameters of `epg-gpg-program'." | |
69 (let (config groups type args) | |
70 (with-temp-buffer | |
71 (apply #'call-process epg-gpg-program nil (list t nil) nil | |
72 (append (if epg-gpg-home-directory | |
73 (list "--homedir" epg-gpg-home-directory)) | |
74 '("--with-colons" "--list-config"))) | |
75 (goto-char (point-min)) | |
76 (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t) | |
77 (setq type (intern (match-string 1)) | |
78 args (match-string 2)) | |
79 (cond | |
80 ((eq type 'group) | |
81 (if (string-match "\\`\\([^:]+\\):" args) | |
82 (setq groups | |
83 (cons (cons (downcase (match-string 1 args)) | |
84 (delete "" (split-string | |
85 (substring args | |
86 (match-end 0)) | |
87 ";"))) | |
88 groups)) | |
89 (if epg-debug | |
90 (message "Invalid group configuration: %S" args)))) | |
91 ((memq type '(pubkey cipher digest compress)) | |
92 (if (string-match "\\`\\([0-9]+\\)\\(;[0-9]+\\)*" args) | |
93 (setq config | |
94 (cons (cons type | |
95 (mapcar #'string-to-number | |
96 (delete "" (split-string args ";")))) | |
97 config)) | |
98 (if epg-debug | |
99 (message "Invalid %S algorithm configuration: %S" | |
100 type args)))) | |
101 (t | |
102 (setq config (cons (cons type args) config)))))) | |
103 (if groups | |
104 (cons (cons 'groups groups) config) | |
105 config))) | |
106 | |
107 (defun epg-config--parse-version (string) | |
108 (let ((index 0) | |
109 version) | |
110 (while (eq index (string-match "\\([0-9]+\\)\\.?" string index)) | |
111 (setq version (cons (string-to-number (match-string 1 string)) | |
112 version) | |
113 index (match-end 0))) | |
114 (nreverse version))) | |
115 | |
116 (defun epg-config--compare-version (v1 v2) | |
117 (while (and v1 v2 (= (car v1) (car v2))) | |
118 (setq v1 (cdr v1) v2 (cdr v2))) | |
119 (- (or (car v1) 0) (or (car v2) 0))) | |
120 | |
121 ;;;###autoload | |
122 (defun epg-check-configuration (config &optional minimum-version) | |
123 "Verify that a sufficient version of GnuPG is installed." | |
124 (let ((entry (assq 'version config)) | |
125 version) | |
126 (unless (and entry | |
127 (stringp (cdr entry))) | |
128 (error "Undetermined version: %S" entry)) | |
129 (setq version (epg-config--parse-version (cdr entry)) | |
130 minimum-version (epg-config--parse-version | |
131 (or minimum-version | |
132 epg-gpg-minimum-version))) | |
133 (unless (>= (epg-config--compare-version version minimum-version) 0) | |
134 (error "Unsupported version: %s" (cdr entry))))) | |
135 | |
136 ;;;###autoload | |
137 (defun epg-expand-group (config group) | |
138 "Look at CONFIG and try to expand GROUP." | |
139 (let ((entry (assq 'groups config))) | |
140 (if (and entry | |
141 (setq entry (assoc (downcase group) (cdr entry)))) | |
142 (cdr entry)))) | |
143 | |
144 (provide 'epg-config) | |
145 | |
91687 | 146 ;; arch-tag: 9aca7cb8-5f63-4bcb-84ee-46fd2db0763f |
91647 | 147 ;;; epg-config.el ends here |