Function: mml-secure-epg-sign

mml-secure-epg-sign is a byte-compiled function defined in mml-sec.el.gz.

Signature

(mml-secure-epg-sign PROTOCOL MODE)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/mml-sec.el.gz
(defun mml-secure-epg-sign (protocol mode)
  ;; Based on code appearing inside mml2015-epg-sign.
  (let* ((context (epg-make-context protocol))
	 (sender (message-options-get 'message-sender))
	 (signer-names (mml-secure-signer-names protocol sender))
	 (signers (mml-secure-signers context signer-names))
	 signature micalg)
    (unless signers
      (if (and (not noninteractive)
	       (mml-secure-sender-sign-query protocol sender))
          (setq signer-names (mml-secure-signer-names protocol sender)
                signers (mml-secure-signers context signer-names)))
      (unless signers
        (let ((maybe-msg
               (if (or mml-secure-smime-sign-with-sender
                       mml-secure-openpgp-sign-with-sender)
                   "."
                 "; try setting `mml-secure-smime-sign-with-sender' or 'mml-secure-openpgp-sign-with-sender'.")))
          ;; If `mml-secure-smime-sign-with-sender' or
          ;; `mml-secure-openpgp-sign-with-sender' are already non-nil
          ;; then there's no point advising the user to examine them.
          ;; If there are any other variables worth examining, please
          ;; improve this error message by having it mention them.
          (error "Couldn't find any signer names%s" maybe-msg))))
    (when (eq 'OpenPGP protocol)
      (setf (epg-context-armor context) t)
      (setf (epg-context-textmode context) t)
      (when mml-secure-openpgp-sign-with-sender
        (setf (epg-context-sender context) sender)))
    (setf (epg-context-signers context) signers)
    (when (mml-secure-cache-passphrase-p protocol)
      (epg-context-set-passphrase-callback
       context
       (cons 'mml-secure-passphrase-callback protocol)))
    (condition-case error
	(setq signature
	      (if (eq 'OpenPGP protocol)
		  (epg-sign-string context (buffer-string) mode)
		(epg-sign-string context
				 (string-replace
				  "\n" "\r\n" (buffer-string))
				 t))
	      mml-secure-secret-key-id-list nil)
      (error
       (mml-secure-clear-secret-key-id-list)
       (signal (car error) (cdr error))))
    (if (epg-context-result-for context 'sign)
	(setq micalg (epg-new-signature-digest-algorithm
		      (car (epg-context-result-for context 'sign)))))
    (cons signature micalg)))