(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)
(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)
(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"
(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)
(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"
;; `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)
(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)
(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
(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)))
(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"
(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))