Mercurial > emacs
annotate lisp/epg-config.el @ 91716:5bb2c18b8034
(compilation-next-error): Add clarifying comment.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 10 Feb 2008 03:16:06 +0000 |
parents | bda1e76bc03b |
children | 7efbdc83b944 |
rev | line source |
---|---|
91647 | 1 ;;; epg-config.el --- configuration of the EasyPG Library |
2 ;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Daiki Ueno <ueno@unixuser.org> | |
5 ;; Keywords: PGP, GnuPG | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 3, or (at your option) | |
12 ;; any later version. | |
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 | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 ;; Boston, MA 02110-1301, USA. | |
23 | |
24 ;;; Code: | |
25 | |
26 (require 'epg-package-info) | |
27 | |
28 (defgroup epg () | |
29 "The EasyPG Library" | |
91703
bda1e76bc03b
* epa.el (epa-faces, epa):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
91687
diff
changeset
|
30 :version "23.1" |
91647 | 31 :group 'emacs) |
32 | |
33 (defcustom epg-gpg-program "gpg" | |
34 "The `gpg' executable." | |
35 :group 'epg | |
36 :type 'string) | |
37 | |
38 (defcustom epg-gpgsm-program "gpgsm" | |
39 "The `gpgsm' executable." | |
40 :group 'epg | |
41 :type 'string) | |
42 | |
43 (defcustom epg-gpg-home-directory nil | |
44 "The directory which contains the configuration files of `epg-gpg-program'." | |
45 :group 'epg | |
46 :type '(choice (const :tag "Default" nil) directory)) | |
47 | |
48 (defcustom epg-passphrase-coding-system nil | |
49 "Coding system to use with messages from `epg-gpg-program'." | |
50 :group 'epg | |
51 :type 'symbol) | |
52 | |
53 (defcustom epg-debug nil | |
54 "If non-nil, debug output goes to the \" *epg-debug*\" buffer. | |
55 Note that the buffer name starts with a space." | |
56 :group 'epg | |
57 :type 'boolean) | |
58 | |
59 (defconst epg-gpg-minimum-version "1.4.3") | |
60 | |
61 ;;;###autoload | |
62 (defun epg-configuration () | |
63 "Return a list of internal configuration parameters of `epg-gpg-program'." | |
64 (let (config groups type args) | |
65 (with-temp-buffer | |
66 (apply #'call-process epg-gpg-program nil (list t nil) nil | |
67 (append (if epg-gpg-home-directory | |
68 (list "--homedir" epg-gpg-home-directory)) | |
69 '("--with-colons" "--list-config"))) | |
70 (goto-char (point-min)) | |
71 (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t) | |
72 (setq type (intern (match-string 1)) | |
73 args (match-string 2)) | |
74 (cond | |
75 ((eq type 'group) | |
76 (if (string-match "\\`\\([^:]+\\):" args) | |
77 (setq groups | |
78 (cons (cons (downcase (match-string 1 args)) | |
79 (delete "" (split-string | |
80 (substring args | |
81 (match-end 0)) | |
82 ";"))) | |
83 groups)) | |
84 (if epg-debug | |
85 (message "Invalid group configuration: %S" args)))) | |
86 ((memq type '(pubkey cipher digest compress)) | |
87 (if (string-match "\\`\\([0-9]+\\)\\(;[0-9]+\\)*" args) | |
88 (setq config | |
89 (cons (cons type | |
90 (mapcar #'string-to-number | |
91 (delete "" (split-string args ";")))) | |
92 config)) | |
93 (if epg-debug | |
94 (message "Invalid %S algorithm configuration: %S" | |
95 type args)))) | |
96 (t | |
97 (setq config (cons (cons type args) config)))))) | |
98 (if groups | |
99 (cons (cons 'groups groups) config) | |
100 config))) | |
101 | |
102 (defun epg-config--parse-version (string) | |
103 (let ((index 0) | |
104 version) | |
105 (while (eq index (string-match "\\([0-9]+\\)\\.?" string index)) | |
106 (setq version (cons (string-to-number (match-string 1 string)) | |
107 version) | |
108 index (match-end 0))) | |
109 (nreverse version))) | |
110 | |
111 (defun epg-config--compare-version (v1 v2) | |
112 (while (and v1 v2 (= (car v1) (car v2))) | |
113 (setq v1 (cdr v1) v2 (cdr v2))) | |
114 (- (or (car v1) 0) (or (car v2) 0))) | |
115 | |
116 ;;;###autoload | |
117 (defun epg-check-configuration (config &optional minimum-version) | |
118 "Verify that a sufficient version of GnuPG is installed." | |
119 (let ((entry (assq 'version config)) | |
120 version) | |
121 (unless (and entry | |
122 (stringp (cdr entry))) | |
123 (error "Undetermined version: %S" entry)) | |
124 (setq version (epg-config--parse-version (cdr entry)) | |
125 minimum-version (epg-config--parse-version | |
126 (or minimum-version | |
127 epg-gpg-minimum-version))) | |
128 (unless (>= (epg-config--compare-version version minimum-version) 0) | |
129 (error "Unsupported version: %s" (cdr entry))))) | |
130 | |
131 ;;;###autoload | |
132 (defun epg-expand-group (config group) | |
133 "Look at CONFIG and try to expand GROUP." | |
134 (let ((entry (assq 'groups config))) | |
135 (if (and entry | |
136 (setq entry (assoc (downcase group) (cdr entry)))) | |
137 (cdr entry)))) | |
138 | |
139 (provide 'epg-config) | |
140 | |
91687 | 141 ;; arch-tag: 9aca7cb8-5f63-4bcb-84ee-46fd2db0763f |
91647 | 142 ;;; epg-config.el ends here |