Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / mml2015.el
1 ;;; mml2015.el --- MIME Security with Pretty Good Privacy (PGP)
2 ;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: PGP MIME MML
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29 (eval-when-compile (require 'gnus-clfns))
30 (require 'mm-decode)
31
32 (defvar mml2015-use (or
33                      (progn
34                        (ignore-errors
35                          (require 'gpg))
36                        (and (fboundp 'gpg-sign-detached)
37                             'gpg))
38                      (progn (ignore-errors
39                               (load "mc-toplev"))
40                             (and (fboundp 'mc-encrypt-generic)
41                                  (fboundp 'mc-sign-generic)
42                                  (fboundp 'mc-cleanup-recipient-headers)
43                                  'mailcrypt)))
44   "The package used for PGP/MIME.")
45
46 ;; Something is not RFC2015.
47 (defvar mml2015-function-alist
48   '((mailcrypt mml2015-mailcrypt-sign
49                mml2015-mailcrypt-encrypt
50                mml2015-mailcrypt-verify
51                mml2015-mailcrypt-decrypt
52                mml2015-mailcrypt-clear-verify
53                mml2015-mailcrypt-clear-decrypt)
54     (gpg mml2015-gpg-sign
55          mml2015-gpg-encrypt
56          mml2015-gpg-verify
57          mml2015-gpg-decrypt
58          mml2015-gpg-clear-verify
59          mml2015-gpg-clear-decrypt))
60   "Alist of PGP/MIME functions.")
61
62 (defvar mml2015-result-buffer nil)
63
64 (defvar mml2015-trust-boundaries-alist
65   '((trust-undefined . nil)
66     (trust-none      . nil)
67     (trust-marginal  . t)
68     (trust-full      . t)
69     (trust-ultimate  . t))
70   "Trust boundaries for a signer's GnuPG key.
71 This alist contains pairs of the form (trust-symbol . boolean), with
72 symbols that are contained in `gpg-unabbrev-trust-alist'. The boolean
73 specifies whether the given trust value is good enough to be trusted
74 by you.")
75
76 ;;; mailcrypt wrapper
77
78 (eval-and-compile
79   (autoload 'mailcrypt-decrypt "mailcrypt")
80   (autoload 'mailcrypt-verify "mailcrypt")
81   (autoload 'mc-pgp-always-sign "mailcrypt")
82   (autoload 'mc-encrypt-generic "mc-toplev")
83   (autoload 'mc-cleanup-recipient-headers "mc-toplev")
84   (autoload 'mc-sign-generic "mc-toplev"))
85
86 (eval-when-compile
87   (defvar mc-default-scheme)
88   (defvar mc-schemes))
89
90 (defvar mml2015-decrypt-function 'mailcrypt-decrypt)
91 (defvar mml2015-verify-function 'mailcrypt-verify)
92
93 (defun mml2015-format-error (err)
94   (if (stringp (cadr err))
95       (cadr err)
96     (format "%S" (cdr err))))
97
98 (defun mml2015-mailcrypt-decrypt (handle ctl)
99   (catch 'error
100     (let (child handles result)
101       (unless (setq child (mm-find-part-by-type
102                            (cdr handle)
103                            "application/octet-stream" nil t))
104         (mm-set-handle-multipart-parameter
105          mm-security-handle 'gnus-info "Corrupted")
106         (throw 'error handle))
107       (with-temp-buffer
108         (mm-insert-part child)
109         (setq result
110               (condition-case err
111                   (funcall mml2015-decrypt-function)
112                 (error
113                  (mm-set-handle-multipart-parameter
114                   mm-security-handle 'gnus-details (mml2015-format-error err))
115                  nil)
116                 (quit
117                  (mm-set-handle-multipart-parameter
118                   mm-security-handle 'gnus-details "Quit.")
119                  nil)))
120         (unless (car result)
121           (mm-set-handle-multipart-parameter
122            mm-security-handle 'gnus-info "Failed")
123           (throw 'error handle))
124         (setq handles (mm-dissect-buffer t)))
125       (mm-destroy-parts handle)
126       (mm-set-handle-multipart-parameter
127        mm-security-handle 'gnus-info "OK")
128       (if (listp (car handles))
129           handles
130         (list handles)))))
131
132 (defun mml2015-mailcrypt-clear-decrypt ()
133   (let (result)
134     (setq result
135           (condition-case err
136               (funcall mml2015-decrypt-function)
137             (error
138              (mm-set-handle-multipart-parameter
139               mm-security-handle 'gnus-details (mml2015-format-error err))
140              nil)
141             (quit
142              (mm-set-handle-multipart-parameter
143               mm-security-handle 'gnus-details "Quit.")
144              nil)))
145     (if (car result)
146         (mm-set-handle-multipart-parameter
147          mm-security-handle 'gnus-info "OK")
148       (mm-set-handle-multipart-parameter
149        mm-security-handle 'gnus-info "Failed"))))
150
151 (defun mml2015-fix-micalg (alg)
152   (and alg
153        ;; Mutt/1.2.5i has seen sending micalg=php-sha1
154        (upcase (if (string-match "^p[gh]p-" alg)
155                    (substring alg (match-end 0))
156                  alg))))
157
158 (defun mml2015-mailcrypt-verify (handle ctl)
159   (catch 'error
160     (let (part)
161       (unless (setq part (mm-find-raw-part-by-type
162                           ctl (or (mm-handle-multipart-ctl-parameter
163                                    ctl 'protocol)
164                                   "application/pgp-signature")
165                           t))
166         (mm-set-handle-multipart-parameter
167          mm-security-handle 'gnus-info "Corrupted")
168         (throw 'error handle))
169       (with-temp-buffer
170         (insert "-----BEGIN PGP SIGNED MESSAGE-----\n")
171         (insert (format "Hash: %s\n\n"
172                         (or (mml2015-fix-micalg
173                              (mm-handle-multipart-ctl-parameter
174                               ctl 'micalg))
175                             "SHA1")))
176         (save-restriction
177           (narrow-to-region (point) (point))
178           (insert part "\n")
179           (goto-char (point-min))
180           (while (not (eobp))
181             (if (looking-at "^-")
182                 (insert "- "))
183             (forward-line)))
184         (unless (setq part (mm-find-part-by-type
185                             (cdr handle) "application/pgp-signature" nil t))
186           (mm-set-handle-multipart-parameter
187            mm-security-handle 'gnus-info "Corrupted")
188           (throw 'error handle))
189         (save-restriction
190           (narrow-to-region (point) (point))
191           (mm-insert-part part)
192           (goto-char (point-min))
193           (if (re-search-forward "^-----BEGIN PGP [^-]+-----\r?$" nil t)
194               (replace-match "-----BEGIN PGP SIGNATURE-----" t t))
195           (if (re-search-forward "^-----END PGP [^-]+-----\r?$" nil t)
196               (replace-match "-----END PGP SIGNATURE-----" t t)))
197         (let ((mc-gpg-debug-buffer (get-buffer-create " *gnus gpg debug*")))
198           (unless (condition-case err
199                       (prog1
200                           (funcall mml2015-verify-function)
201                         (if (get-buffer " *mailcrypt stderr temp")
202                             (mm-set-handle-multipart-parameter
203                              mm-security-handle 'gnus-details
204                              (with-current-buffer " *mailcrypt stderr temp"
205                                (buffer-string))))
206                         (if (get-buffer " *mailcrypt stdout temp")
207                             (kill-buffer " *mailcrypt stdout temp"))
208                         (if (get-buffer " *mailcrypt stderr temp")
209                             (kill-buffer " *mailcrypt stderr temp"))
210                         (if (get-buffer " *mailcrypt status temp")
211                             (kill-buffer " *mailcrypt status temp"))
212                         (if (get-buffer mc-gpg-debug-buffer)
213                             (kill-buffer mc-gpg-debug-buffer)))
214                     (error
215                      (mm-set-handle-multipart-parameter
216                       mm-security-handle 'gnus-details (mml2015-format-error err))
217                      nil)
218                     (quit
219                      (mm-set-handle-multipart-parameter
220                       mm-security-handle 'gnus-details "Quit.")
221                      nil))
222             (mm-set-handle-multipart-parameter
223              mm-security-handle 'gnus-info "Failed")
224             (throw 'error handle))))
225       (mm-set-handle-multipart-parameter
226        mm-security-handle 'gnus-info "OK")
227       handle)))
228
229 (defun mml2015-mailcrypt-clear-verify ()
230   (let ((mc-gpg-debug-buffer (get-buffer-create " *gnus gpg debug*")))
231     (if (condition-case err
232             (prog1
233                 (funcall mml2015-verify-function)
234               (if (get-buffer " *mailcrypt stderr temp")
235                   (mm-set-handle-multipart-parameter
236                    mm-security-handle 'gnus-details
237                    (with-current-buffer " *mailcrypt stderr temp"
238                      (buffer-string))))
239               (if (get-buffer " *mailcrypt stdout temp")
240                   (kill-buffer " *mailcrypt stdout temp"))
241               (if (get-buffer " *mailcrypt stderr temp")
242                   (kill-buffer " *mailcrypt stderr temp"))
243               (if (get-buffer " *mailcrypt status temp")
244                   (kill-buffer " *mailcrypt status temp"))
245               (if (get-buffer mc-gpg-debug-buffer)
246                   (kill-buffer mc-gpg-debug-buffer)))
247           (error
248            (mm-set-handle-multipart-parameter
249             mm-security-handle 'gnus-details (mml2015-format-error err))
250            nil)
251           (quit
252            (mm-set-handle-multipart-parameter
253             mm-security-handle 'gnus-details "Quit.")
254            nil))
255         (mm-set-handle-multipart-parameter
256          mm-security-handle 'gnus-info "OK")
257       (mm-set-handle-multipart-parameter
258        mm-security-handle 'gnus-info "Failed"))))
259
260 (defun mml2015-mailcrypt-sign (cont)
261   (mc-sign-generic (message-options-get 'message-sender)
262                    nil nil nil nil)
263   (let ((boundary
264          (funcall mml-boundary-function (incf mml-multipart-number)))
265         hash point)
266     (goto-char (point-min))
267     (unless (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\r?$" nil t)
268       (error "Cannot find signed begin line"))
269     (goto-char (match-beginning 0))
270     (forward-line 1)
271     (unless (looking-at "Hash:[ \t]*\\([a-zA-Z0-9]+\\)")
272       (error "Cannot not find PGP hash"))
273     (setq hash (match-string 1))
274     (unless (re-search-forward "^$" nil t)
275       (error "Cannot not find PGP message"))
276     (forward-line 1)
277     (delete-region (point-min) (point))
278     (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
279                     boundary))
280     (insert (format "\tmicalg=pgp-%s; protocol=\"application/pgp-signature\"\n"
281                     (downcase hash)))
282     (insert (format "\n--%s\n" boundary))
283     (setq point (point))
284     (goto-char (point-max))
285     (unless (re-search-backward "^-----END PGP SIGNATURE-----\r?$" nil t)
286       (error "Cannot find signature part"))
287     (replace-match "-----END PGP MESSAGE-----" t t)
288     (goto-char (match-beginning 0))
289     (unless (re-search-backward "^-----BEGIN PGP SIGNATURE-----\r?$"
290                                 nil t)
291       (error "Cannot find signature part"))
292     (replace-match "-----BEGIN PGP MESSAGE-----" t t)
293     (goto-char (match-beginning 0))
294     (save-restriction
295       (narrow-to-region point (point))
296       (goto-char point)
297       (while (re-search-forward "^- -" nil t)
298         (replace-match "-" t t))
299       (goto-char (point-max)))
300     (insert (format "--%s\n" boundary))
301     (insert "Content-Type: application/pgp-signature\n\n")
302     (goto-char (point-max))
303     (insert (format "--%s--\n" boundary))
304     (goto-char (point-max))))
305
306 (defun mml2015-mailcrypt-encrypt (cont)
307   (let ((mc-pgp-always-sign
308          (or mc-pgp-always-sign
309              (eq t (or (message-options-get 'message-sign-encrypt)
310                        (message-options-set
311                         'message-sign-encrypt
312                         (or (y-or-n-p "Sign the message? ")
313                             'not))))
314              'never)))
315     (mm-with-unibyte-current-buffer-mule4
316       (mc-encrypt-generic
317        (or (message-options-get 'message-recipients)
318            (message-options-set 'message-recipients
319                                 (mc-cleanup-recipient-headers
320                                  (read-string "Recipients: "))))
321        nil nil nil
322        (message-options-get 'message-sender))))
323   (goto-char (point-min))
324   (unless (looking-at "-----BEGIN PGP MESSAGE-----")
325     (error "Fail to encrypt the message"))
326   (let ((boundary
327          (funcall mml-boundary-function (incf mml-multipart-number))))
328     (insert (format "Content-Type: multipart/encrypted; boundary=\"%s\";\n"
329                     boundary))
330     (insert "\tprotocol=\"application/pgp-encrypted\"\n\n")
331     (insert (format "--%s\n" boundary))
332     (insert "Content-Type: application/pgp-encrypted\n\n")
333     (insert "Version: 1\n\n")
334     (insert (format "--%s\n" boundary))
335     (insert "Content-Type: application/octet-stream\n\n")
336     (goto-char (point-max))
337     (insert (format "--%s--\n" boundary))
338     (goto-char (point-max))))
339
340 ;;; gpg wrapper
341
342 (eval-and-compile
343   (autoload 'gpg-decrypt "gpg")
344   (autoload 'gpg-verify "gpg")
345   (autoload 'gpg-verify-cleartext "gpg")
346   (autoload 'gpg-sign-detached "gpg")
347   (autoload 'gpg-sign-encrypt "gpg")
348   (autoload 'gpg-passphrase-read "gpg"))
349
350 (defun mml2015-gpg-passphrase ()
351   (or (message-options-get 'gpg-passphrase)
352       (message-options-set 'gpg-passphrase (gpg-passphrase-read))))
353
354 (defun mml2015-gpg-decrypt-1 ()
355   (let ((cipher (current-buffer)) plain result)
356     (if (with-temp-buffer
357           (prog1
358               (gpg-decrypt cipher (setq plain (current-buffer))
359                            mml2015-result-buffer nil)
360             (mm-set-handle-multipart-parameter
361              mm-security-handle 'gnus-details
362              (with-current-buffer mml2015-result-buffer
363                (buffer-string)))
364             (set-buffer cipher)
365             (erase-buffer)
366             (insert-buffer plain)
367             (goto-char (point-min))
368             (while (search-forward "\r\n" nil t)
369               (replace-match "\n" t t))))
370         '(t)
371       ;; Some wrong with the return value, check plain text buffer.
372       (if (> (point-max) (point-min))
373           '(t)
374         nil))))
375
376 (defun mml2015-gpg-decrypt (handle ctl)
377   (let ((mml2015-decrypt-function 'mml2015-gpg-decrypt-1))
378     (mml2015-mailcrypt-decrypt handle ctl)))
379
380 (defun mml2015-gpg-clear-decrypt ()
381   (let (result)
382     (setq result (mml2015-gpg-decrypt-1))
383     (if (car result)
384         (mm-set-handle-multipart-parameter
385          mm-security-handle 'gnus-info "OK")
386       (mm-set-handle-multipart-parameter
387        mm-security-handle 'gnus-info "Failed"))))
388
389 (defun mml2015-gpg-pretty-print-fpr (fingerprint)
390   (let* ((result "")
391          (fpr-length (string-width fingerprint))
392          (n-slice 0)
393          slice)
394     (setq fingerprint (string-to-list fingerprint))
395     (while fingerprint
396       (setq fpr-length (- fpr-length 4))
397       (setq slice (butlast fingerprint fpr-length))
398       (setq fingerprint (nthcdr 4 fingerprint))
399       (setq n-slice (1+ n-slice))
400       (setq result
401             (concat
402              result
403              (case n-slice
404                (1  slice)
405                (otherwise (concat " " slice))))))
406     result))
407           
408 (defun mml2015-gpg-extract-signature-details ()
409   (goto-char (point-min))
410   (if (boundp 'gpg-unabbrev-trust-alist)
411       (let* ((signer (and (re-search-forward
412                            "^\\[GNUPG:\\] GOODSIG [0-9A-Za-z]* \\(.*\\)$"
413                            nil t)
414                           (match-string 1)))
415          (fprint (and (re-search-forward
416                        "^\\[GNUPG:\\] VALIDSIG \\([0-9a-zA-Z]*\\) "
417                        nil t)
418                       (match-string 1)))
419          (trust  (and (re-search-forward "^\\[GNUPG:\\] \\(TRUST_.*\\)$" nil t)
420                       (match-string 1)))
421          (trust-good-enough-p
422           (cdr (assoc (cdr (assoc trust gpg-unabbrev-trust-alist))
423                       mml2015-trust-boundaries-alist))))
424         (if (and signer trust fprint)
425             (concat signer
426                     (unless trust-good-enough-p
427                       (concat "\nUntrusted, Fingerprint: "
428                               (mml2015-gpg-pretty-print-fpr fprint))))
429           "From unknown user"))
430     (if (re-search-forward "^gpg: Good signature from \"\\(.*\\)\"$" nil t)
431         (match-string 1)
432       "From unknown user")))
433
434 (defun mml2015-gpg-verify (handle ctl)
435   (catch 'error
436     (let (part message signature info-is-set-p)
437       (unless (setq part (mm-find-raw-part-by-type
438                           ctl (or (mm-handle-multipart-ctl-parameter
439                                    ctl 'protocol)
440                                   "application/pgp-signature")
441                           t))
442         (mm-set-handle-multipart-parameter
443          mm-security-handle 'gnus-info "Corrupted")
444         (throw 'error handle))
445       (with-temp-buffer
446         (setq message (current-buffer))
447         (insert part)
448         (with-temp-buffer
449           (setq signature (current-buffer))
450           (unless (setq part (mm-find-part-by-type
451                               (cdr handle) "application/pgp-signature" nil t))
452             (mm-set-handle-multipart-parameter
453              mm-security-handle 'gnus-info "Corrupted")
454             (throw 'error handle))
455           (mm-insert-part part)
456           (unless (condition-case err
457                       (prog1
458                           (gpg-verify message signature mml2015-result-buffer)
459                         (mm-set-handle-multipart-parameter
460                          mm-security-handle 'gnus-details
461                          (with-current-buffer mml2015-result-buffer
462                            (buffer-string))))
463                     (error
464                      (mm-set-handle-multipart-parameter
465                       mm-security-handle 'gnus-details (mml2015-format-error err))
466                      (mm-set-handle-multipart-parameter
467                       mm-security-handle 'gnus-info "Error.")
468                      (setq info-is-set-p t)
469                      nil)
470                     (quit
471                      (mm-set-handle-multipart-parameter
472                       mm-security-handle 'gnus-details "Quit.")
473                      (mm-set-handle-multipart-parameter
474                       mm-security-handle 'gnus-info "Quit.")
475                      (setq info-is-set-p t)
476                      nil))
477             (unless info-is-set-p
478               (mm-set-handle-multipart-parameter
479                mm-security-handle 'gnus-info "Failed"))
480             (throw 'error handle)))
481         (mm-set-handle-multipart-parameter
482          mm-security-handle 'gnus-info
483          (with-current-buffer mml2015-result-buffer
484            (mml2015-gpg-extract-signature-details))))
485       handle)))
486
487 (defun mml2015-gpg-clear-verify ()
488   (if (condition-case err
489           (prog1
490               (gpg-verify-cleartext (current-buffer) mml2015-result-buffer)
491             (mm-set-handle-multipart-parameter
492              mm-security-handle 'gnus-details
493              (with-current-buffer mml2015-result-buffer
494                (buffer-string))))
495         (error
496          (mm-set-handle-multipart-parameter
497           mm-security-handle 'gnus-details (mml2015-format-error err))
498          nil)
499         (quit
500          (mm-set-handle-multipart-parameter
501           mm-security-handle 'gnus-details "Quit.")
502          nil))
503       (mm-set-handle-multipart-parameter
504        mm-security-handle 'gnus-info
505        (with-current-buffer mml2015-result-buffer
506          (mml2015-gpg-extract-signature-details)))
507     (mm-set-handle-multipart-parameter
508      mm-security-handle 'gnus-info "Failed")))
509
510 (defun mml2015-gpg-sign (cont)
511   (let ((boundary
512          (funcall mml-boundary-function (incf mml-multipart-number)))
513         (text (current-buffer)) signature)
514     (goto-char (point-max))
515     (unless (bolp)
516       (insert "\n"))
517     (with-temp-buffer
518       (unless (gpg-sign-detached text (setq signature (current-buffer))
519                                  mml2015-result-buffer
520                                  nil
521                                  (message-options-get 'message-sender)
522                                  t t) ; armor & textmode
523         (unless (> (point-max) (point-min))
524           (pop-to-buffer mml2015-result-buffer)
525           (error "Sign error")))
526       (goto-char (point-min))
527       (while (re-search-forward "\r+$" nil t)
528         (replace-match "" t t))
529       (set-buffer text)
530       (goto-char (point-min))
531       (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
532                       boundary))
533       ;;; FIXME: what is the micalg?
534       (insert "\tmicalg=pgp-sha1; protocol=\"application/pgp-signature\"\n")
535       (insert (format "\n--%s\n" boundary))
536       (goto-char (point-max))
537       (insert (format "\n--%s\n" boundary))
538       (insert "Content-Type: application/pgp-signature\n\n")
539       (insert-buffer signature)
540       (goto-char (point-max))
541       (insert (format "--%s--\n" boundary))
542       (goto-char (point-max)))))
543
544 (defun mml2015-gpg-encrypt (cont)
545   (let ((boundary
546          (funcall mml-boundary-function (incf mml-multipart-number)))
547         (text (current-buffer))
548         cipher)
549     (mm-with-unibyte-current-buffer-mule4
550       (with-temp-buffer
551         (unless (gpg-sign-encrypt
552                  text (setq cipher (current-buffer))
553                  mml2015-result-buffer
554                  (split-string
555                   (or
556                    (message-options-get 'message-recipients)
557                    (message-options-set 'message-recipients
558                                         (read-string "Recipients: ")))
559                   "[ \f\t\n\r\v,]+")
560                  nil
561                  (message-options-get 'message-sender)
562                  t t) ; armor & textmode
563           (unless (> (point-max) (point-min))
564             (pop-to-buffer mml2015-result-buffer)
565             (error "Encrypt error")))
566         (goto-char (point-min))
567         (while (re-search-forward "\r+$" nil t)
568           (replace-match "" t t))
569         (set-buffer text)
570         (delete-region (point-min) (point-max))
571         (insert (format "Content-Type: multipart/encrypted; boundary=\"%s\";\n"
572                         boundary))
573         (insert "\tprotocol=\"application/pgp-encrypted\"\n\n")
574         (insert (format "--%s\n" boundary))
575         (insert "Content-Type: application/pgp-encrypted\n\n")
576         (insert "Version: 1\n\n")
577         (insert (format "--%s\n" boundary))
578         (insert "Content-Type: application/octet-stream\n\n")
579         (insert-buffer cipher)
580         (goto-char (point-max))
581         (insert (format "--%s--\n" boundary))
582         (goto-char (point-max))))))
583
584 ;;; General wrapper
585
586 (defun mml2015-clean-buffer ()
587   (if (gnus-buffer-live-p mml2015-result-buffer)
588       (with-current-buffer mml2015-result-buffer
589         (erase-buffer)
590         t)
591     (setq mml2015-result-buffer
592           (gnus-get-buffer-create "*MML2015 Result*"))
593     nil))
594
595 (defsubst mml2015-clear-decrypt-function ()
596   (nth 6 (assq mml2015-use mml2015-function-alist)))
597
598 (defsubst mml2015-clear-verify-function ()
599   (nth 5 (assq mml2015-use mml2015-function-alist)))
600
601 ;;;###autoload
602 (defun mml2015-decrypt (handle ctl)
603   (mml2015-clean-buffer)
604   (let ((func (nth 4 (assq mml2015-use mml2015-function-alist))))
605     (if func
606         (funcall func handle ctl)
607       handle)))
608
609 ;;;###autoload
610 (defun mml2015-decrypt-test (handle ctl)
611   mml2015-use)
612
613 ;;;###autoload
614 (defun mml2015-verify (handle ctl)
615   (mml2015-clean-buffer)
616   (let ((func (nth 3 (assq mml2015-use mml2015-function-alist))))
617     (if func
618         (funcall func handle ctl)
619       handle)))
620
621 ;;;###autoload
622 (defun mml2015-verify-test (handle ctl)
623   mml2015-use)
624
625 ;;;###autoload
626 (defun mml2015-encrypt (cont)
627   (mml2015-clean-buffer)
628   (let ((func (nth 2 (assq mml2015-use mml2015-function-alist))))
629     (if func
630         (funcall func cont)
631       (error "Cannot find encrypt function"))))
632
633 ;;;###autoload
634 (defun mml2015-sign (cont)
635   (mml2015-clean-buffer)
636   (let ((func (nth 1 (assq mml2015-use mml2015-function-alist))))
637     (if func
638         (funcall func cont)
639       (error "Cannot find sign function"))))
640
641 ;;;###autoload
642 (defun mml2015-self-encrypt ()
643   (mml2015-encrypt nil))
644
645 (provide 'mml2015)
646
647 ;;; mml2015.el ends here