X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=epg.el;h=0191a018164d74b1318339598a20d09d37dcdaab;hb=cfc87dbe5b4de5e0770c36553c6a44d4171d8bfc;hp=7da1518af290b2cfebf6fdc9e0f1c9e882bba7e2;hpb=c3d5cd3ec695ad9053a4425bab51843fdd21a516;p=elisp%2Fepg.git diff --git a/epg.el b/epg.el index 7da1518..0191a01 100644 --- a/epg.el +++ b/epg.el @@ -25,31 +25,7 @@ ;;; Code: -(defgroup epg () - "The EasyPG Library" - :group 'emacs) - -(defcustom epg-gpg-program "gpg" - "The `gpg' executable." - :group 'epg - :type 'string) - -(defcustom epg-gpgsm-program "gpgsm" - "The `gpgsm' executable." - :group 'epg - :type 'string) - -(defcustom epg-gpg-home-directory nil - "The directory which contains the `gpg' configuration files." - :group 'epg - :type '(choice (const :tag "Default" nil) directory)) - -(defcustom epg-gpgsm-home-directory nil - "The directory which contains the `gpgsm' configuration files." - :group 'epg - :type '(choice (const :tag "Default" nil) directory)) - -(defconst epg-version-number "0.0.4") +(require 'epg-config) (defvar epg-user-id nil "GnuPG ID of your default identity.") @@ -810,13 +786,11 @@ This function is for internal use only." (if (eq (epg-context-protocol context) 'CMS) epg-gpgsm-program epg-gpg-program))) - (let* ((home-directory (if (eq (epg-context-protocol context) 'CMS) - epg-gpgsm-home-directory - epg-gpg-home-directory)) - (args (append (list "--no-tty" + (let* ((args (append (list "--no-tty" "--status-fd" "1" "--yes") - (if home-directory (list "--homedir" home-directory)) + (if epg-gpg-home-directory + (list "--homedir" epg-gpg-home-directory)) (unless (eq (epg-context-protocol context) 'CMS) (list "--command-fd" "0")) (if (epg-context-armor context) '("--armor")) @@ -959,7 +933,8 @@ This function is for internal use only." (string-match "\\`passphrase\\." string)) (let (inhibit-quit passphrase - passphrase-with-new-line) + passphrase-with-new-line + encoded-passphrase-with-new-line) (unwind-protect (condition-case nil (progn @@ -974,10 +949,21 @@ This function is for internal use only." (cdr (epg-context-passphrase-callback context))))) (when passphrase (setq passphrase-with-new-line (concat passphrase "\n")) - (fillarray passphrase 0) + (epg--clear-string passphrase) (setq passphrase nil) + (if epg-locale-coding-system + (progn + (setq encoded-passphrase-with-new-line + (encode-coding-string + passphrase-with-new-line + epg-locale-coding-system)) + (epg--clear-string passphrase-with-new-line) + (setq passphrase-with-new-line nil)) + (setq encoded-passphrase-with-new-line + passphrase-with-new-line + passphrase-with-new-line nil)) (process-send-string (epg-context-process context) - passphrase-with-new-line))) + encoded-passphrase-with-new-line))) (quit (epg-context-set-result-for context 'error @@ -985,9 +971,11 @@ This function is for internal use only." (epg-context-result-for context 'error))) (delete-process (epg-context-process context)))) (if passphrase - (fillarray passphrase 0)) + (epg--clear-string passphrase)) (if passphrase-with-new-line - (fillarray passphrase-with-new-line 0)))))) + (epg--clear-string passphrase-with-new-line)) + (if encoded-passphrase-with-new-line + (epg--clear-string encoded-passphrase-with-new-line)))))) (defun epg--status-GET_BOOL (context string) (let ((entry (assoc string epg-prompt-alist)) @@ -1319,49 +1307,10 @@ This function is for internal use only." handback) (message "%s: %d%%/%d%%" what current total)) -;;;###autoload -(defun epg-configuration () - "Return a list of internal configuration parameters of `epg-gpg-program'." - (let (config type) - (with-temp-buffer - (apply #'call-process epg-gpg-program nil (list t nil) nil - '("--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)) - -;;;###autoload -(defun epg-check-configuration (config) - "Verify that CONFIGURATION is sufficient." - (let ((entry (assq 'version config)) - major minor teeny) - (unless (and entry - (stringp (cdr entry)) - (string-match "\\`\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" - (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))))) - (error "Unsupported version: %s" (cdr entry))))) - (defun epg--list-keys-1 (context name mode) - (let ((args (append (list "--with-colons" "--no-greeting" "--batch" + (let ((args (append (if epg-gpg-home-directory + (list "--homedir" epg-gpg-home-directory)) + (list "--with-colons" "--no-greeting" "--batch" "--with-fingerprint" "--with-fingerprint" (if (memq mode '(t secret)) @@ -1538,6 +1487,11 @@ You can then use `write-region' to write new data into the file." (file-directory-p tempdir) (delete-directory tempdir)))))) +(if (fboundp 'clear-string) + (defalias 'epg--clear-string 'clear-string) + (defun epg--clear-string (string) + (fillarray string 0))) + ;;;###autoload (defun epg-cancel (context) (if (buffer-live-p (process-buffer (epg-context-process context)))