- (unwind-protect
- (progn
- (epg-context-set-output-file context
- (epg--make-temp-file "epg-output"))
- (epg-start-encrypt context (epg-make-data-from-string plain)
- recipients sign always-trust)
- (epg-wait-for-completion context)
- (if (and sign
- (not (epg-context-result-for context 'sign)))
- (if (epg-context-result-for context 'error)
- (error "Sign failed: %S"
- (epg-context-result-for context 'error))
- (error "Sign failed")))
- (if (epg-context-result-for context 'error)
- (error "Encrypt failed: %S"
- (epg-context-result-for context 'error)))
- (epg-read-output context))
- (epg-delete-output-file context)
- (epg-reset context)))
+ (let ((input-file
+ (unless (or (not sign)
+ (eq (epg-context-protocol context) 'CMS)
+ (condition-case nil
+ (progn
+ (epg-check-configuration (epg-configuration))
+ t)
+ (error)))
+ (epg--make-temp-file "epg-input")))
+ (coding-system-for-write 'binary))
+ (unwind-protect
+ (progn
+ (epg-context-set-output-file context
+ (epg--make-temp-file "epg-output"))
+ (if input-file
+ (write-region plain nil input-file nil 'quiet))
+ (epg-start-encrypt context
+ (if input-file
+ (epg-make-data-from-file input-file)
+ (epg-make-data-from-string plain))
+ recipients sign always-trust)
+ (epg-wait-for-completion context)
+ (if (and sign
+ (not (epg-context-result-for context 'sign)))
+ (if (epg-context-result-for context 'error)
+ (error "Sign failed: %S"
+ (epg-context-result-for context 'error))
+ (error "Sign failed")))
+ (if (epg-context-result-for context 'error)
+ (error "Encrypt failed: %S"
+ (epg-context-result-for context 'error)))
+ (epg-read-output context))
+ (epg-delete-output-file context)
+ (if input-file
+ (delete-file input-file))
+ (epg-reset context))))