Fix typos.
[emacs.git] / lisp / epg-config.el
blobf3dc9469564a9ea598761dcfafbda226ce396329
1 ;;; epg-config.el --- configuration of the EasyPG Library
2 ;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: PGP, GnuPG
7 ;; This file is part of GNU Emacs.
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.
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.
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.
24 ;;; Code:
26 (defconst epg-package-name "epg"
27 "Name of this package.")
29 (defconst epg-version-number "1.0.0"
30 "Version number of this package.")
32 (defconst epg-bug-report-address "ueno@unixuser.org"
33 "Report bugs to this address.")
35 (defgroup epg ()
36 "The EasyPG Library"
37 :version "23.1"
38 :group 'emacs)
40 (defcustom epg-gpg-program "gpg"
41 "The `gpg' executable."
42 :group 'epg
43 :type 'string)
45 (defcustom epg-gpgsm-program "gpgsm"
46 "The `gpgsm' executable."
47 :group 'epg
48 :type 'string)
50 (defcustom epg-gpg-home-directory nil
51 "The directory which contains the configuration files of `epg-gpg-program'."
52 :group 'epg
53 :type '(choice (const :tag "Default" nil) directory))
55 (defcustom epg-passphrase-coding-system nil
56 "Coding system to use with messages from `epg-gpg-program'."
57 :group 'epg
58 :type 'symbol)
60 (defcustom epg-debug nil
61 "If non-nil, debug output goes to the \" *epg-debug*\" buffer.
62 Note that the buffer name starts with a space."
63 :group 'epg
64 :type 'boolean)
66 (defconst epg-gpg-minimum-version "1.4.3")
68 ;;;###autoload
69 (defun epg-configuration ()
70 "Return a list of internal configuration parameters of `epg-gpg-program'."
71 (let (config groups type args)
72 (with-temp-buffer
73 (apply #'call-process epg-gpg-program nil (list t nil) nil
74 (append (if epg-gpg-home-directory
75 (list "--homedir" epg-gpg-home-directory))
76 '("--with-colons" "--list-config")))
77 (goto-char (point-min))
78 (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t)
79 (setq type (intern (match-string 1))
80 args (match-string 2))
81 (cond
82 ((eq type 'group)
83 (if (string-match "\\`\\([^:]+\\):" args)
84 (setq groups
85 (cons (cons (downcase (match-string 1 args))
86 (delete "" (split-string
87 (substring args
88 (match-end 0))
89 ";")))
90 groups))
91 (if epg-debug
92 (message "Invalid group configuration: %S" args))))
93 ((memq type '(pubkey cipher digest compress))
94 (if (string-match "\\`\\([0-9]+\\)\\(;[0-9]+\\)*" args)
95 (setq config
96 (cons (cons type
97 (mapcar #'string-to-number
98 (delete "" (split-string args ";"))))
99 config))
100 (if epg-debug
101 (message "Invalid %S algorithm configuration: %S"
102 type args))))
104 (setq config (cons (cons type args) config))))))
105 (if groups
106 (cons (cons 'groups groups) config)
107 config)))
109 (defun epg-config--parse-version (string)
110 (let ((index 0)
111 version)
112 (while (eq index (string-match "\\([0-9]+\\)\\.?" string index))
113 (setq version (cons (string-to-number (match-string 1 string))
114 version)
115 index (match-end 0)))
116 (nreverse version)))
118 (defun epg-config--compare-version (v1 v2)
119 (while (and v1 v2 (= (car v1) (car v2)))
120 (setq v1 (cdr v1) v2 (cdr v2)))
121 (- (or (car v1) 0) (or (car v2) 0)))
123 ;;;###autoload
124 (defun epg-check-configuration (config &optional minimum-version)
125 "Verify that a sufficient version of GnuPG is installed."
126 (let ((entry (assq 'version config))
127 version)
128 (unless (and entry
129 (stringp (cdr entry)))
130 (error "Undetermined version: %S" entry))
131 (setq version (epg-config--parse-version (cdr entry))
132 minimum-version (epg-config--parse-version
133 (or minimum-version
134 epg-gpg-minimum-version)))
135 (unless (>= (epg-config--compare-version version minimum-version) 0)
136 (error "Unsupported version: %s" (cdr entry)))))
138 ;;;###autoload
139 (defun epg-expand-group (config group)
140 "Look at CONFIG and try to expand GROUP."
141 (let ((entry (assq 'groups config)))
142 (if (and entry
143 (setq entry (assoc (downcase group) (cdr entry))))
144 (cdr entry))))
146 (provide 'epg-config)
148 ;; arch-tag: 9aca7cb8-5f63-4bcb-84ee-46fd2db0763f
149 ;;; epg-config.el ends here