From: ueno Date: Fri, 9 Mar 2007 01:59:46 +0000 (+0000) Subject: New branch for utilizing PLAINTEXT status code. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c517785a90826bf802dacd81c06c5a8eb7b70b43;p=elisp%2Fepg.git New branch for utilizing PLAINTEXT status code. --- diff --git a/ChangeLog b/ChangeLog index 96c1ed7..1240230 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,15 @@ 2007-03-08 Daiki Ueno * epg.el (epg-list-keys): Parse GnuPG's print_string escape. + (epg-wait-for-plaintext): New function. + (epg--status-PLAINTEXT_LENGTH): New function. + (epg-decrypt-string): Don't use a temp output file. + (epg--status-BEGIN_DECRYPTION): New function; reset 'plaintext + result. + (epg--status-DECRYPTION_OKAY): Copy 'plaintext result to + 'decrypted-plaintext. + (epg-verify-file): Don't use a temp output file. + (epg-verify-string): Ditto. 2007-03-08 Daiki Ueno diff --git a/epg.el b/epg.el index 5a3ce86..63d40b5 100644 --- a/epg.el +++ b/epg.el @@ -1120,6 +1120,7 @@ This function is for internal use only." args))) (set-default-file-modes orig-mode)) (set-process-filter process #'epg--process-filter) + (set-process-sentinel process #'ignore) (epg-context-set-process context process))) (defun epg--process-filter (process input) @@ -1147,14 +1148,17 @@ This function is for internal use only." (string (match-string 2)) (symbol (intern-soft (concat "epg--status-" status)))) + (forward-line) + (setq epg-read-point (point)) (if (member status epg-pending-status-list) (setq epg-pending-status-list nil)) (if (and symbol (fboundp symbol)) (funcall symbol epg-context string)) - (setq epg-last-status (cons status string)))) - (forward-line) - (setq epg-read-point (point)))) + (goto-char epg-read-point) + (setq epg-last-status (cons status string))) + (forward-line) + (setq epg-read-point (point))))) (setq epg-process-filter-running nil)))))) (defun epg-read-output (context) @@ -1180,6 +1184,12 @@ This function is for internal use only." (while (eq (process-status (epg-context-process context)) 'run) (accept-process-output (epg-context-process context) 1))) +(defun epg-wait-for-plaintext (context length) + "Wait data from the `epg-gpg-program' process." + (while (and (eq (process-status (epg-context-process context)) 'run) + (< (- (point-max) epg-read-point) length)) + (accept-process-output (epg-context-process context) 1))) + (defun epg-reset (context) "Reset the CONTEXT." (if (and (epg-context-process context) @@ -1487,11 +1497,27 @@ This function is for internal use only." (if (consp (epg-context-progress-callback context)) (cdr (epg-context-progress-callback context)))))) +(defun epg--status-BEGIN_DECRYPTION (context string) + (epg-context-set-result-for context 'plaintext nil)) + (defun epg--status-DECRYPTION_FAILED (context string) (epg-context-set-result-for context 'decryption-failed t)) (defun epg--status-DECRYPTION_OKAY (context string) - (epg-context-set-result-for context 'decryption-okay t)) + (epg-context-set-result-for context 'decryption-okay t) + (epg-context-set-result-for + context + 'decrypted-plaintext + (epg-context-result-for context 'plaintext))) + +(defun epg--status-PLAINTEXT_LENGTH (context string) + (when (string-match "\\`\\([0-9]+\\)" string) + (let ((length (string-to-number (match-string 1 string)))) + (epg-wait-for-plaintext context length) + (epg-context-set-result-for + context 'plaintext + (buffer-substring epg-read-point + (setq epg-read-point (+ epg-read-point length))))))) (defun epg--status-NODATA (context string) (epg-context-set-result-for @@ -1945,13 +1971,10 @@ If PLAIN is nil, it returns the result as a string." (unwind-protect (progn (write-region cipher nil input-file nil 'quiet) - (epg-context-set-output-file context - (epg--make-temp-file "epg-output")) (epg-start-decrypt context (epg-make-data-from-file input-file)) (epg-wait-for-completion context) (epg--check-error-for-decrypt context) - (epg-read-output context)) - (epg-delete-output-file context) + (epg-context-result-for context 'decrypted-plaintext)) (if (file-exists-p input-file) (delete-file input-file)) (epg-reset context)))) @@ -2005,9 +2028,7 @@ stored into the file after successful verification." (unwind-protect (progn (if plain - (epg-context-set-output-file context plain) - (epg-context-set-output-file context - (epg--make-temp-file "epg-output"))) + (epg-context-set-output-file context plain)) (if signed-text (epg-start-verify context (epg-make-data-from-file signature) @@ -2016,9 +2037,7 @@ stored into the file after successful verification." (epg-make-data-from-file signature))) (epg-wait-for-completion context) (unless plain - (epg-read-output context))) - (unless plain - (epg-delete-output-file context)) + (epg-context-result-for context 'plaintext))) (epg-reset context))) ;;;###autoload @@ -2034,8 +2053,6 @@ successful verification." input-file) (unwind-protect (progn - (epg-context-set-output-file context - (epg--make-temp-file "epg-output")) (if signed-text (progn (setq input-file (epg--make-temp-file "epg-signature")) @@ -2045,8 +2062,7 @@ successful verification." (epg-make-data-from-string signed-text))) (epg-start-verify context (epg-make-data-from-string signature))) (epg-wait-for-completion context) - (epg-read-output context)) - (epg-delete-output-file context) + (epg-context-result-for context 'plaintext)) (if (and input-file (file-exists-p input-file)) (delete-file input-file))