X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=epg-config.el;h=c5c5a7f871747c24197c053763b0492183848da2;hb=7b26e29c09ec312968e28014de711a90ec77f6bb;hp=0da6ea12150bf0a46ca9487b3cdabc940e53eb11;hpb=4310c626411ddec85f1ba4b84309722348a04f3b;p=elisp%2Fepg.git diff --git a/epg-config.el b/epg-config.el index 0da6ea1..c5c5a7f 100644 --- a/epg-config.el +++ b/epg-config.el @@ -23,6 +23,8 @@ ;;; Code: +(require 'epg-package-info) + (defgroup epg () "The EasyPG Library" :group 'emacs) @@ -38,53 +40,101 @@ :type 'string) (defcustom epg-gpg-home-directory nil - "The directory which contains the `gpg' configuration files." + "The directory which contains the configuration files of `epg-gpg-program'." :group 'epg :type '(choice (const :tag "Default" nil) directory)) -(defconst epg-version-number "0.0.4") +(defcustom epg-passphrase-coding-system nil + "Coding system to use with messages from `epg-gpg-program'." + :group 'epg + :type 'symbol) + +(defcustom epg-debug nil + "If non-nil, debug output goes to the \" *epg-debug*\" buffer. +Note that the buffer name starts with a space." + :group 'epg + :type 'boolean) + +(defconst epg-gpg-minimum-version "1.4.3") ;;;###autoload (defun epg-configuration () "Return a list of internal configuration parameters of `epg-gpg-program'." - (let (config type) + (let (config groups type args) (with-temp-buffer (apply #'call-process epg-gpg-program nil (list t nil) nil - '("--with-colons" "--list-config")) + (append (if epg-gpg-home-directory + (list "--homedir" epg-gpg-home-directory)) + '("--with-colons" "--list-config"))) (goto-char (point-min)) (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t) (setq type (intern (match-string 1)) - config (cons (cons type - (if (memq type - '(pubkey cipher digest compress)) - (mapcar #'string-to-number - (delete "" (split-string - (match-string 2) - ";"))) - (match-string 2))) - config)))) - config)) + args (match-string 2)) + (cond + ((eq type 'group) + (if (string-match "\\`\\([^:]+\\):" args) + (setq groups + (cons (cons (downcase (match-string 1 args)) + (delete "" (split-string + (substring args + (match-end 0)) + ";"))) + groups)) + (if epg-debug + (message "Invalid group configuration: %S" args)))) + ((memq type '(pubkey cipher digest compress)) + (if (string-match "\\`\\([0-9]+\\)\\(;[0-9]+\\)*" args) + (setq config + (cons (cons type + (mapcar #'string-to-number + (delete "" (split-string args ";")))) + config)) + (if epg-debug + (message "Invalid %S algorithm configuration: %S" + type args)))) + (t + (setq config (cons (cons type args) config)))))) + (if groups + (cons (cons 'groups groups) config) + config))) + +(defun epg-config--parse-version (string) + (let ((index 0) + version) + (while (eq index (string-match "\\([0-9]+\\)\\.?" string index)) + (setq version (cons (string-to-number (match-string 1 string)) + version) + index (match-end 0))) + (nreverse version))) + +(defun epg-config--compare-version (v1 v2) + (while (and v1 v2 (= (car v1) (car v2))) + (setq v1 (cdr v1) v2 (cdr v2))) + (- (or (car v1) 0) (or (car v2) 0))) ;;;###autoload -(defun epg-check-configuration (config) - "Verify that CONFIGURATION is sufficient." +(defun epg-check-configuration (config &optional minimum-version) + "Verify that a sufficient version of GnuPG is installed." (let ((entry (assq 'version config)) - major minor teeny) + version) (unless (and entry - (stringp (cdr entry)) - (string-match "\\`\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" - (cdr entry))) + (stringp (cdr entry))) (error "Undetermined version: %S" entry)) - (setq major (string-to-number (match-string 1 (cdr entry))) - minor (string-to-number (match-string 2 (cdr entry))) - teeny (string-to-number (match-string 3 (cdr entry)))) - (unless (or (> major 1) - (and (= major 1) - (or (> minor 4) - (and (= minor 4) - (>= teeny 3))))) + (setq version (epg-config--parse-version (cdr entry)) + minimum-version (epg-config--parse-version + (or minimum-version + epg-gpg-minimum-version))) + (unless (>= (epg-config--compare-version version minimum-version) 0) (error "Unsupported version: %s" (cdr entry))))) +;;;###autoload +(defun epg-expand-group (config group) + "Look at CONFIG and try to expand GROUP." + (let ((entry (assq 'groups config))) + (if (and entry + (setq entry (assoc (downcase group) (cdr entry)))) + (cdr entry)))) + (provide 'epg-config) ;;; epg-config.el ends here