+ (epg-delete-output-file context)
+ (epg-reset context)))
+
+;;;###autoload
+(defun epg-start-export-keys (context keys)
+ "Initiate an export keys operation.
+
+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-export-keys-to-file' or `epg-export-keys-to-string' instead."
+ (epg-context-set-result context nil)
+ (epg-start context (cons "--export"
+ (mapcar
+ (lambda (key)
+ (epg-sub-key-id
+ (car (epg-key-sub-key-list key))))
+ keys))))
+
+;;;###autoload
+(defun epg-export-keys-to-file (context keys file)
+ "Extract public KEYS."
+ (unwind-protect
+ (progn
+ (if keys
+ (epg-context-set-output-file context file)
+ (epg-context-set-output-file context
+ (epg-make-temp-file "epg-output")))
+ (epg-start-export-keys context keys)
+ (epg-wait-for-completion context)
+ (if (epg-context-result-for context 'error)
+ (error "Export keys failed"))
+ (unless file
+ (epg-read-output context)))
+ (unless file
+ (epg-delete-output-file context))
+ (epg-reset context)))
+
+;;;###autoload
+(defun epg-export-keys-to-string (context keys)
+ "Extract public KEYS and return them as a string."
+ (epg-export-keys-to-file context keys nil))
+
+;;;###autoload
+(defun epg-start-import-keys (context keys)
+ "Initiate an import keys operation.
+KEYS is a data object.
+
+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-import-keys-from-file' or `epg-import-keys-from-string' instead."
+ (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))))
+
+(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"))
+ (epg-read-output context))
+ (epg-reset context)))
+
+;;;###autoload
+(defun epg-import-keys-from-file (context keys)
+ "Add keys from a file KEYS."
+ (epg-import-keys-1 context (epg-make-data-from-file keys)))
+
+;;;###autoload
+(defun epg-import-keys-from-string (context keys)
+ "Add keys from a string KEYS."
+ (epg-import-keys-1 context (epg-make-data-from-string keys)))
+
+;;;###autoload
+(defun epg-start-delete-keys (context keys &optional allow-secret)
+ "Initiate an delete keys operation.
+
+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-delete-keys' instead."
+ (epg-context-set-result context nil)
+ (epg-start context (cons (if allow-secret
+ "--delete-secret-key"
+ "--delete-key")
+ (mapcar
+ (lambda (key)
+ (epg-sub-key-id
+ (car (epg-key-sub-key-list key))))
+ keys))))
+
+;;;###autoload
+(defun epg-delete-keys (context keys &optional allow-secret)
+ "Delete KEYS from the key ring."
+ (unwind-protect
+ (progn
+ (epg-start-delete-keys context keys)
+ (epg-wait-for-completion context)
+ (if (epg-context-result-for context 'error)
+ (error "Delete key failed")))