From: ueno Date: Mon, 1 May 2006 02:16:07 +0000 (+0000) Subject: * epg.el (epg-flush): Abolished. X-Git-Tag: epg-0_0_2~59 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c31eeeb1b9d1f575cfa3191fa80f13d8a3440738;p=elisp%2Fepg.git * epg.el (epg-flush): Abolished. (epg-start-generate-key): New function. (epg-generate-key-from-file): New function. (epg-generate-key-from-string): New function. (epg-status-KEY_CREATED): New function. (epg-status-KEY_NOT_CREATED): New function. --- diff --git a/ChangeLog b/ChangeLog index 5c69ecc..1413703 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,12 @@ * epg.el (epg-start): Signal an error if the process of CONTEXT is already running for other operations. + (epg-flush): Abolished. + (epg-start-generate-key): New function. + (epg-generate-key-from-file): New function. + (epg-generate-key-from-string): New function. + (epg-status-KEY_CREATED): New function. + (epg-status-KEY_NOT_CREATED): New function. 2006-04-30 Daiki Ueno diff --git a/epg.el b/epg.el index 376a674..e23e883 100644 --- a/epg.el +++ b/epg.el @@ -718,11 +718,6 @@ This function is for internal use only." (while (eq (process-status (epg-context-process context)) 'run) (accept-process-output (epg-context-process context) 0 1))) -(defun epg-flush (context) - "Flush the input to the `epg-gpg-program' process." - (if (eq (process-status (epg-context-process context)) 'run) - (process-send-eof (epg-context-process context)))) - (defun epg-reset (context) "Reset the CONTEXT." (if (and (epg-context-process context) @@ -1042,6 +1037,20 @@ This function is for internal use only." (cons 'fingerprint (substring string (match-end 0)))) (epg-context-result-for epg-context 'sign))))) +(defun epg-status-KEY_CREATED (process string) + (if (string-match "\\`\\([BPS]\\) \\([^ ]+\\)" string) + (epg-context-set-result-for + epg-context 'generate-key + (cons (list (cons 'type (string-to-char (match-string 1 string))) + (cons 'fingerprint (match-string 2 string))) + (epg-context-result-for epg-context 'generate-key))))) + +(defun epg-status-KEY_NOT_CREATED (process string) + (epg-context-set-result-for + epg-context 'error + (cons '(key-not-created) + (epg-context-result-for epg-context 'error)))) + (defun epg-passphrase-callback-function (context key-id handback) (read-passwd (if (eq key-id 'SYM) @@ -1306,7 +1315,6 @@ If PLAIN is nil, it returns the result as a string." (epg-context-set-output-file context (epg-make-temp-file "epg-output")) (epg-start-decrypt context (epg-make-data-from-file input-file)) - (epg-flush context) (epg-wait-for-completion context) (if (epg-context-result-for context 'error) (error "Decrypt failed: %S" @@ -1339,14 +1347,18 @@ If you are unsure, use synchronous version of this function (epg-start context (list "--verify" (epg-data-file signature) "-")) (if (eq (process-status (epg-context-process context)) 'run) (process-send-string (epg-context-process context) - (epg-data-string signed-text)))) + (epg-data-string signed-text))) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-eof (epg-context-process context)))) ;; Normal (or cleartext) signature. (if (epg-data-file signature) (epg-start context (list "--verify" (epg-data-file signature))) (epg-start context (list "--verify")) (if (eq (process-status (epg-context-process context)) 'run) (process-send-string (epg-context-process context) - (epg-data-string signature)))))) + (epg-data-string signature))) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-eof (epg-context-process context)))))) ;;;###autoload (defun epg-verify-file (context signature &optional signed-text plain) @@ -1398,7 +1410,6 @@ For a normal or a clear text signature, SIGNED-TEXT should be nil." (epg-make-data-from-file input-file) (epg-make-data-from-string signed-text))) (epg-start-verify context (epg-make-data-from-string signature))) - (epg-flush context) (epg-wait-for-completion context) ; (if (epg-context-result-for context 'error) ; (error "Verify failed: %S" @@ -1443,10 +1454,12 @@ If you are unsure, use synchronous version of this function ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed. (unless (eq (epg-context-protocol context) 'CMS) (epg-wait-for-status context '("BEGIN_SIGNING"))) - (if (and (epg-data-string plain) - (eq (process-status (epg-context-process context)) 'run)) - (process-send-string (epg-context-process context) - (epg-data-string plain)))) + (when (epg-data-string plain) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-string (epg-context-process context) + (epg-data-string plain))) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-eof (epg-context-process context)))) ;;;###autoload (defun epg-sign-file (context plain signature &optional mode) @@ -1488,7 +1501,6 @@ Otherwise, it makes a normal signature." (epg-context-set-output-file context (epg-make-temp-file "epg-output")) (epg-start-sign context (epg-make-data-from-string plain) mode) - (epg-flush context) (epg-wait-for-completion context) (unless (epg-context-result-for context 'sign) (if (epg-context-result-for context 'error) @@ -1535,10 +1547,12 @@ If you are unsure, use synchronous version of this function (if sign (epg-wait-for-status context '("BEGIN_SIGNING")) (epg-wait-for-status context '("BEGIN_ENCRYPTION")))) - (if (and (epg-data-string plain) - (eq (process-status (epg-context-process context)) 'run)) - (process-send-string (epg-context-process context) - (epg-data-string plain)))) + (when (epg-data-string plain) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-string (epg-context-process context) + (epg-data-string plain))) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-eof (epg-context-process context))))) ;;;###autoload (defun epg-encrypt-file (context plain recipients @@ -1581,7 +1595,6 @@ If RECIPIENTS is nil, it performs symmetric encryption." (epg-make-temp-file "epg-output")) (epg-start-encrypt context (epg-make-data-from-string plain) recipients sign always-trust) - (epg-flush context) (epg-wait-for-completion context) (if (and sign (not (epg-context-result-for context 'sign))) @@ -1651,17 +1664,17 @@ If you are unsure, use synchronous version of this function (epg-context-set-result context nil) (epg-context-set-output-file context (epg-make-temp-file "epg-output")) (epg-start context (list "--import" (epg-data-file keys))) - (if (and (epg-data-string keys) - (eq (process-status (epg-context-process context)) 'run)) - (process-send-string (epg-context-process context) - (epg-data-string keys)))) - + (when (epg-data-string keys) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-string (epg-context-process context) + (epg-data-string keys))) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-eof (epg-context-process context))))) + (defun epg-import-keys-1 (context keys) (unwind-protect (progn (epg-start-import-keys context keys) - (if (epg-data-file keys) - (epg-flush context)) (epg-wait-for-completion context) (if (epg-context-result-for context 'error) (error "Import keys failed: %S" @@ -1741,6 +1754,53 @@ If you are unsure, use synchronous version of this function (epg-context-result-for context 'error)))) (epg-reset context))) +;;;###autoload +(defun epg-start-generate-key (context parameters) + "Initiate a key generation. +PARAMETERS specifies parameters for the key. + +If you use this function, you will need to wait for the completion of +`epg-gpg-program' by using `epg-wait-for-completion' and call +`epg-reset' to clear a temporaly output file. +If you are unsure, use synchronous version of this function +`epg-generate-key-from-file' or `epg-generate-key-from-string' instead." + (epg-context-set-result context nil) + (if (epg-data-file parameters) + (epg-start context (list "--batch" "--genkey" + (epg-data-file parameters))) + (epg-start context '("--batch" "--genkey")) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-string (epg-context-process context) + (epg-data-string parameters))) + (if (eq (process-status (epg-context-process context)) 'run) + (process-send-eof (epg-context-process context))))) + +;;;###autoload +(defun epg-generate-key-from-file (context parameters) + "Generate a new key pair. +PARAMETERS is a file which tells how to create the key." + (unwind-protect + (progn + (epg-start-generate-key context (epg-make-data-from-file parameters)) + (epg-wait-for-completion context) + (if (epg-context-result-for context 'error) + (error "Generate key failed: %S" + (epg-context-result-for context 'error)))) + (epg-reset context))) + +;;;###autoload +(defun epg-generate-key-from-string (context parameters) + "Generate a new key pair. +PARAMETERS is a file which tells how to create the key." + (unwind-protect + (progn + (epg-start-generate-key context (epg-make-data-from-string parameters)) + (epg-wait-for-completion context) + (if (epg-context-result-for context 'error) + (error "Generate key failed: %S" + (epg-context-result-for context 'error)))) + (epg-reset context))) + (defun epg-decode-hexstring (string) (let ((index 0)) (while (eq index (string-match "[0-9A-Fa-f][0-9A-Fa-f]" string index))