Function: smime-sign-region
smime-sign-region is a byte-compiled function defined in smime.el.gz.
Signature
(smime-sign-region B E KEYFILE)
Documentation
Sign region with certified key in KEYFILE.
If signing fails, the buffer is not modified. Region is assumed to have proper MIME tags. KEYFILE is expected to contain a PEM encoded private key and certificate as its car, and a list of additional certificates to include in its caar. If no additional certificates is included, KEYFILE may be the file containing the PEM encoded private key and certificate itself.
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/smime.el.gz
;; Sign+encrypt region
(defun smime-sign-region (b e keyfile)
"Sign region with certified key in KEYFILE.
If signing fails, the buffer is not modified. Region is assumed to
have proper MIME tags. KEYFILE is expected to contain a PEM encoded
private key and certificate as its car, and a list of additional
certificates to include in its caar. If no additional certificates is
included, KEYFILE may be the file containing the PEM encoded private
key and certificate itself."
(smime-new-details-buffer)
(let* ((certfiles (and (cdr-safe keyfile) (cadr keyfile)))
(keyfile (or (car-safe keyfile) keyfile))
(buffer (generate-new-buffer " *smime*"))
(passphrase (smime-ask-passphrase (expand-file-name keyfile)))
(tmpfile (make-temp-file "smime")))
(if passphrase
(setenv "GNUS_SMIME_PASSPHRASE" passphrase))
(prog1
(when (prog1
(apply #'smime-call-openssl-region b e (list buffer tmpfile)
"smime" "-sign" "-signer" (expand-file-name keyfile)
(append
(smime-make-certfiles certfiles)
(if passphrase
(list "-passin" "env:GNUS_SMIME_PASSPHRASE"))))
(if passphrase
(setenv "GNUS_SMIME_PASSPHRASE" "" t))
(with-current-buffer smime-details-buffer
(insert-file-contents tmpfile)
(delete-file tmpfile)))
(delete-region b e)
(insert-buffer-substring buffer)
(goto-char b)
(when (looking-at "^MIME-Version: 1.0$")
(delete-region (point) (progn (forward-line 1) (point))))
t)
(with-current-buffer smime-details-buffer
(goto-char (point-max))
(insert-buffer-substring buffer))
(kill-buffer buffer))))