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