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        (upcase (if (string-match "^pgp-" 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         '(t)
367       ;; Some wrong with the return value, check plain text buffer.
368       (if (> (point-max) (point-min))
369           '(t)
370         nil))))
371
372 (defun mml2015-gpg-decrypt (handle ctl)
373   (let ((mml2015-decrypt-function 'mml2015-gpg-decrypt-1))
374     (mml2015-mailcrypt-decrypt handle ctl)))
375
376 (defun mml2015-gpg-clear-decrypt ()
377   (let (result)
378     (setq result (mml2015-gpg-decrypt-1))
379     (if (car result)
380         (mm-set-handle-multipart-parameter
381          mm-security-handle 'gnus-info "OK")
382       (mm-set-handle-multipart-parameter
383        mm-security-handle 'gnus-info "Failed"))))
384
385 (defun mml2015-gpg-pretty-print-fpr (fingerprint)
386   (let* ((result "")
387          (fpr-length (string-width fingerprint))
388          (n-slice 0)
389          slice)
390     (setq fingerprint (string-to-list fingerprint))
391     (while fingerprint
392       (setq fpr-length (- fpr-length 4))
393       (setq slice (butlast fingerprint fpr-length))
394       (setq fingerprint (nthcdr 4 fingerprint))
395       (setq n-slice (1+ n-slice))
396       (setq result
397             (concat
398              result
399              (case n-slice
400                (1  slice)
401                (otherwise (concat " " slice))))))
402     result))
403           
404 (defun mml2015-gpg-extract-signature-details ()
405   (goto-char (point-min))
406   (if (boundp 'gpg-unabbrev-trust-alist)
407       (let* ((signer (and (re-search-forward
408                            "^\\[GNUPG:\\] GOODSIG [0-9A-Za-z]* \\(.*\\)$"
409                            nil t)
410                           (match-string 1)))
411          (fprint (and (re-search-forward
412                        "^\\[GNUPG:\\] VALIDSIG \\([0-9a-zA-Z]*\\) "
413                        nil t)
414                       (match-string 1)))
415          (trust  (and (re-search-forward "^\\[GNUPG:\\] \\(TRUST_.*\\)$" nil t)
416                       (match-string 1)))
417          (trust-good-enough-p
418           (cdr (assoc (cdr (assoc trust gpg-unabbrev-trust-alist))
419                       mml2015-trust-boundaries-alist))))
420         (if (and signer trust fprint)
421             (concat signer
422                     (unless trust-good-enough-p
423                       (concat "\nUntrusted, Fingerprint: "
424                               (mml2015-gpg-pretty-print-fpr fprint))))
425           "From unknown user"))
426     (if (re-search-forward "^gpg: Good signature from \"\\(.*\\)\"$" nil t)
427         (match-string 1)
428       "From unknown user")))
429
430 (defun mml2015-gpg-verify (handle ctl)
431   (catch 'error
432     (let (part message signature info-is-set-p)
433       (unless (setq part (mm-find-raw-part-by-type
434                           ctl (or (mm-handle-multipart-ctl-parameter
435                                    ctl 'protocol)
436                                   "application/pgp-signature")
437                           t))
438         (mm-set-handle-multipart-parameter
439          mm-security-handle 'gnus-info "Corrupted")
440         (throw 'error handle))
441       (with-temp-buffer
442         (setq message (current-buffer))
443         (insert part)
444         (with-temp-buffer
445           (setq signature (current-buffer))
446           (unless (setq part (mm-find-part-by-type
447                               (cdr handle) "application/pgp-signature" nil t))
448             (mm-set-handle-multipart-parameter
449              mm-security-handle 'gnus-info "Corrupted")
450             (throw 'error handle))
451           (mm-insert-part part)
452           (unless (condition-case err
453                       (prog1
454                           (gpg-verify message signature mml2015-result-buffer)
455                         (mm-set-handle-multipart-parameter
456                          mm-security-handle 'gnus-details
457                          (with-current-buffer mml2015-result-buffer
458                            (buffer-string))))
459                     (error
460                      (mm-set-handle-multipart-parameter
461                       mm-security-handle 'gnus-details (mml2015-format-error err))
462                      (mm-set-handle-multipart-parameter
463                       mm-security-handle 'gnus-info "Error.")
464                      (setq info-is-set-p t)
465                      nil)
466                     (quit
467                      (mm-set-handle-multipart-parameter
468                       mm-security-handle 'gnus-details "Quit.")
469                      (mm-set-handle-multipart-parameter
470                       mm-security-handle 'gnus-info "Quit.")
471                      (setq info-is-set-p t)
472                      nil))
473             (unless info-is-set-p
474               (mm-set-handle-multipart-parameter
475                mm-security-handle 'gnus-info "Failed"))
476             (throw 'error handle)))
477         (mm-set-handle-multipart-parameter
478          mm-security-handle 'gnus-info
479          (with-current-buffer mml2015-result-buffer
480            (mml2015-gpg-extract-signature-details))))
481       handle)))
482
483 (defun mml2015-gpg-clear-verify ()
484   (if (condition-case err
485           (prog1
486               (gpg-verify-cleartext (current-buffer) mml2015-result-buffer)
487             (mm-set-handle-multipart-parameter
488              mm-security-handle 'gnus-details
489              (with-current-buffer mml2015-result-buffer
490                (buffer-string))))
491         (error
492          (mm-set-handle-multipart-parameter
493           mm-security-handle 'gnus-details (mml2015-format-error err))
494          nil)
495         (quit
496          (mm-set-handle-multipart-parameter
497           mm-security-handle 'gnus-details "Quit.")
498          nil))
499       (mm-set-handle-multipart-parameter
500        mm-security-handle 'gnus-info
501        (with-current-buffer mml2015-result-buffer
502          (mml2015-gpg-extract-signature-details)))
503     (mm-set-handle-multipart-parameter
504      mm-security-handle 'gnus-info "Failed")))
505
506 (defun mml2015-gpg-sign (cont)
507   (let ((boundary
508          (funcall mml-boundary-function (incf mml-multipart-number)))
509         (text (current-buffer)) signature)
510     (goto-char (point-max))
511     (unless (bolp)
512       (insert "\n"))
513     (with-temp-buffer
514       (unless (gpg-sign-detached text (setq signature (current-buffer))
515                                  mml2015-result-buffer
516                                  nil
517                                  (message-options-get 'message-sender)
518                                  t t) ; armor & textmode
519         (unless (> (point-max) (point-min))
520           (pop-to-buffer mml2015-result-buffer)
521           (error "Sign error")))
522       (goto-char (point-min))
523       (while (re-search-forward "\r+$" nil t)
524         (replace-match "" t t))
525       (set-buffer text)
526       (goto-char (point-min))
527       (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
528                       boundary))
529       ;;; FIXME: what is the micalg?
530       (insert "\tmicalg=pgp-sha1; protocol=\"application/pgp-signature\"\n")
531       (insert (format "\n--%s\n" boundary))
532       (goto-char (point-max))
533       (insert (format "\n--%s\n" boundary))
534       (insert "Content-Type: application/pgp-signature\n\n")
535       (insert-buffer signature)
536       (goto-char (point-max))
537       (insert (format "--%s--\n" boundary))
538       (goto-char (point-max)))))
539
540 (defun mml2015-gpg-encrypt (cont)
541   (let ((boundary
542          (funcall mml-boundary-function (incf mml-multipart-number)))
543         (text (current-buffer))
544         cipher)
545     (mm-with-unibyte-current-buffer-mule4
546       (with-temp-buffer
547         (unless (gpg-sign-encrypt
548                  text (setq cipher (current-buffer))
549                  mml2015-result-buffer
550                  (split-string
551                   (or
552                    (message-options-get 'message-recipients)
553                    (message-options-set 'message-recipients
554                                         (read-string "Recipients: ")))
555                   "[ \f\t\n\r\v,]+")
556                  nil
557                  (message-options-get 'message-sender)
558                  t t) ; armor & textmode
559           (unless (> (point-max) (point-min))
560             (pop-to-buffer mml2015-result-buffer)
561             (error "Encrypt error")))
562         (goto-char (point-min))
563         (while (re-search-forward "\r+$" nil t)
564           (replace-match "" t t))
565         (set-buffer text)
566         (delete-region (point-min) (point-max))
567         (insert (format "Content-Type: multipart/encrypted; boundary=\"%s\";\n"
568                         boundary))
569         (insert "\tprotocol=\"application/pgp-encrypted\"\n\n")
570         (insert (format "--%s\n" boundary))
571         (insert "Content-Type: application/pgp-encrypted\n\n")
572         (insert "Version: 1\n\n")
573         (insert (format "--%s\n" boundary))
574         (insert "Content-Type: application/octet-stream\n\n")
575         (insert-buffer cipher)
576         (goto-char (point-max))
577         (insert (format "--%s--\n" boundary))
578         (goto-char (point-max))))))
579
580 ;;; General wrapper
581
582 (defun mml2015-clean-buffer ()
583   (if (gnus-buffer-live-p mml2015-result-buffer)
584       (with-current-buffer mml2015-result-buffer
585         (erase-buffer)
586         t)
587     (setq mml2015-result-buffer
588           (gnus-get-buffer-create "*MML2015 Result*"))
589     nil))
590
591 (defsubst mml2015-clear-decrypt-function ()
592   (nth 6 (assq mml2015-use mml2015-function-alist)))
593
594 (defsubst mml2015-clear-verify-function ()
595   (nth 5 (assq mml2015-use mml2015-function-alist)))
596
597 ;;;###autoload
598 (defun mml2015-decrypt (handle ctl)
599   (mml2015-clean-buffer)
600   (let ((func (nth 4 (assq mml2015-use mml2015-function-alist))))
601     (if func
602         (funcall func handle ctl)
603       handle)))
604
605 ;;;###autoload
606 (defun mml2015-decrypt-test (handle ctl)
607   mml2015-use)
608
609 ;;;###autoload
610 (defun mml2015-verify (handle ctl)
611   (mml2015-clean-buffer)
612   (let ((func (nth 3 (assq mml2015-use mml2015-function-alist))))
613     (if func
614         (funcall func handle ctl)
615       handle)))
616
617 ;;;###autoload
618 (defun mml2015-verify-test (handle ctl)
619   mml2015-use)
620
621 ;;;###autoload
622 (defun mml2015-encrypt (cont)
623   (mml2015-clean-buffer)
624   (let ((func (nth 2 (assq mml2015-use mml2015-function-alist))))
625     (if func
626         (funcall func cont)
627       (error "Cannot find encrypt function"))))
628
629 ;;;###autoload
630 (defun mml2015-sign (cont)
631   (mml2015-clean-buffer)
632   (let ((func (nth 1 (assq mml2015-use mml2015-function-alist))))
633     (if func
634         (funcall func cont)
635       (error "Cannot find sign function"))))
636
637 ;;;###autoload
638 (defun mml2015-self-encrypt ()
639   (mml2015-encrypt nil))
640
641 (provide 'mml2015)
642
643 ;;; mml2015.el ends here