+ (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))))
+
+;;;###autoload
+(defun epg-sign-file (context plain signature &optional mode)
+ "Sign a file PLAIN and store the result to a file SIGNATURE.
+If SIGNATURE is nil, it returns the result as a string.
+If optional 3rd argument MODE is 'clearsign, it makes a clear text signature.
+If MODE is t or 'detached, it makes a detached signature.
+Otherwise, it makes a normal signature."
+ (unwind-protect
+ (progn
+ (if signature
+ (epg-context-set-output-file context signature)
+ (epg-context-set-output-file context
+ (epg-make-temp-file "epg-output")))
+ (epg-start-sign context (epg-make-data-from-file plain) mode)
+ (epg-wait-for-completion context)
+ (if (epg-context-result-for context 'error)
+ (error "Sign failed"))
+ (unless signature
+ (epg-read-output context)))
+ (unless signature
+ (epg-delete-output-file context))
+ (epg-reset context)))