From bda35e4ada93f5cd7416e92e99c76b70fa1da9a8 Mon Sep 17 00:00:00 2001 From: ueno Date: Thu, 8 Mar 2007 10:56:59 +0000 Subject: [PATCH] * epg.el (epg-wait-for-plaintext): New function. (epg--status-PLAINTEXT_LENGTH): New function. (epg-decrypt-string): Don't use a temp output file. --- ChangeLog | 3 +++ epg.el | 30 +++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96c1ed7..dcd824e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 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. 2007-03-08 Daiki Ueno diff --git a/epg.el b/epg.el index 5a3ce86..3b09c8f 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) @@ -1493,6 +1503,15 @@ This function is for internal use only." (defun epg--status-DECRYPTION_OKAY (context string) (epg-context-set-result-for context 'decryption-okay t)) +(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 context 'error @@ -1945,13 +1964,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 'plaintext)) (if (file-exists-p input-file) (delete-file input-file)) (epg-reset context)))) -- 1.7.10.4