Fixed.
[elisp/epg.git] / epg.el
1 ;;; epg.el --- the EasyPG Library
2 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
3 ;;   2005, 2006 Free Software Foundation, Inc.
4 ;; Copyright (C) 2006 Daiki Ueno
5
6 ;; Author: Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: PGP, GnuPG
8
9 ;; This file is part of EasyPG.
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Code:
27
28 (defgroup epg ()
29   "The EasyPG Library")
30
31 (defcustom epg-gpg-program "gpg"
32   "The `gpg' executable."
33   :group 'epg
34   :type 'string)
35
36 (defconst epg-version-number "0.0.0")
37
38 (defvar epg-user-id nil
39   "GnuPG ID of your default identity.")
40
41 (defvar epg-user-id-alist nil
42   "An alist mapping from key ID to user ID.")
43
44 (defvar epg-read-point nil)
45 (defvar epg-pending-status-list nil)
46 (defvar epg-key-id nil)
47 (defvar epg-context nil)
48 (defvar epg-debug nil)
49
50 ;; from gnupg/include/cipher.h
51 (defconst epg-cipher-algorithm-alist
52   '((0 . "NONE")
53     (1 . "IDEA")
54     (2 . "3DES")
55     (3 . "CAST5")
56     (4 . "BLOWFISH")
57     (7 . "AES")
58     (8 . "AES192")
59     (9 . "AES256")
60     (10 . "TWOFISH")
61     (110 . "DUMMY")))
62
63 ;; from gnupg/include/cipher.h
64 (defconst epg-pubkey-algorithm-alist
65   '((1 . "RSA")
66     (2 . "RSA_E")
67     (3 . "RSA_S")
68     (16 . "ELGAMAL_E")
69     (17 . "DSA")
70     (20 . "ELGAMAL")))
71
72 ;; from gnupg/include/cipher.h
73 (defconst epg-digest-algorithm-alist
74   '((1 . "MD5")
75     (2 . "SHA1")
76     (3 . "RMD160")
77     (8 . "SHA256")
78     (9 . "SHA384")
79     (10 . "SHA512")))
80
81 ;; from gnupg/include/cipher.h
82 (defconst epg-compress-algorithm-alist
83   '((0 . "NONE")
84     (1 . "ZIP")
85     (2 . "ZLIB")
86     (3 . "BZIP2")))
87
88 (defconst epg-invalid-recipients-alist
89   '((0 . "No specific reason given")
90     (1 . "Not Found")
91     (2 . "Ambigious specification")
92     (3 . "Wrong key usage")
93     (4 . "Key revoked")
94     (5 . "Key expired")
95     (6 . "No CRL known")
96     (7 . "CRL too old")
97     (8 . "Policy mismatch")
98     (9 . "Not a secret key")
99     (10 . "Key not trusted")))
100
101 (defconst epg-delete-problem-alist
102   '((1 . "No such key")
103     (2 . "Must delete secret key first")
104     (3 . "Ambigious specification")))
105
106 (defvar epg-key-validity-alist
107   '((?o . unknown)
108     (?i . invalid)
109     (?d . disabled)
110     (?r . revoked)
111     (?e . expired)
112     (?- . none)
113     (?q . undefined)
114     (?n . never)
115     (?m . marginal)
116     (?f . full)
117     (?u . ultimate)))
118
119 (defvar epg-key-capablity-alist
120   '((?e . encrypt)
121     (?s . sign)
122     (?c . certify)
123     (?a . authentication)))
124
125 (defvar epg-prompt-alist nil)
126
127 (defun epg-make-data-from-file (file)
128   "Make a data object from FILE."
129   (vector file nil))
130
131 (defun epg-make-data-from-string (string)
132   "Make a data object from STRING."
133   (vector nil string))
134
135 (defun epg-data-file (data)
136   "Return the file of DATA."
137   (aref data 0))
138
139 (defun epg-data-string (data)
140   "Return the string of DATA."
141   (aref data 1))
142
143 (defun epg-make-context (&optional protocol armor textmode include-certs
144                                    cipher-algorithm digest-algorithm
145                                    compress-algorithm)
146   "Return a context object."
147   (vector protocol armor textmode include-certs
148           cipher-algorithm digest-algorithm compress-algorithm
149           #'epg-passphrase-callback-function
150           #'epg-progress-callback-function
151           nil nil nil nil))
152
153 (defun epg-context-protocol (context)
154   "Return the protocol used within CONTEXT."
155   (aref context 0))
156
157 (defun epg-context-armor (context)
158   "Return t if the output shouled be ASCII armored in CONTEXT."
159   (aref context 1))
160
161 (defun epg-context-textmode (context)
162   "Return t if canonical text mode should be used in CONTEXT."
163   (aref context 2))
164
165 (defun epg-context-include-certs (context)
166   "Return how many certificates should be included in an S/MIME signed
167 message."
168   (aref context 3))
169
170 (defun epg-context-cipher-algorithm (context)
171   "Return the cipher algorithm in CONTEXT."
172   (aref context 4))
173
174 (defun epg-context-digest-algorithm (context)
175   "Return the digest algorithm in CONTEXT."
176   (aref context 5))
177
178 (defun epg-context-compress-algorithm (context)
179   "Return the compress algorithm in CONTEXT."
180   (aref context 6))
181
182 (defun epg-context-passphrase-callback (context)
183   "Return the function used to query passphrase."
184   (aref context 7))
185
186 (defun epg-context-progress-callback (context)
187   "Return the function which handles progress update."
188   (aref context 8))
189
190 (defun epg-context-signers (context)
191   "Return the list of key-id for singning."
192   (aref context 9))
193
194 (defun epg-context-process (context)
195   "Return the process object of `epg-gpg-program'.
196 This function is for internal use only."
197   (aref context 10))
198
199 (defun epg-context-output-file (context)
200   "Return the output file of `epg-gpg-program'.
201 This function is for internal use only."
202   (aref context 11))
203
204 (defun epg-context-result (context)
205   "Return the result of the previous cryptographic operation."
206   (aref context 12))
207
208 (defun epg-context-set-protocol (context protocol)
209   "Set the protocol used within CONTEXT."
210   (aset context 0 protocol))
211
212 (defun epg-context-set-armor (context armor)
213   "Specify if the output shouled be ASCII armored in CONTEXT."
214   (aset context 1 armor))
215
216 (defun epg-context-set-textmode (context textmode)
217   "Specify if canonical text mode should be used in CONTEXT."
218   (aset context 2 textmode))
219
220 (defun epg-context-set-include-certs (context include-certs)
221  "Set how many certificates should be included in an S/MIME signed message."
222   (aset context 3 include-certs))
223
224 (defun epg-context-set-cipher-algorithm (context cipher-algorithm)
225  "Set the cipher algorithm in CONTEXT."
226   (aset context 4 cipher-algorithm))
227
228 (defun epg-context-set-digest-algorithm (context digest-algorithm)
229  "Set the digest algorithm in CONTEXT."
230   (aset context 5 digest-algorithm))
231
232 (defun epg-context-set-compress-algorithm (context compress-algorithm)
233  "Set the compress algorithm in CONTEXT."
234   (aset context 6 compress-algorithm))
235
236 (defun epg-context-set-passphrase-callback (context
237                                                  passphrase-callback)
238   "Set the function used to query passphrase."
239   (aset context 7 passphrase-callback))
240
241 (defun epg-context-set-progress-callback (context progress-callback)
242   "Set the function which handles progress update."
243   (aset context 8 progress-callback))
244
245 (defun epg-context-set-signers (context signers)
246  "Set the list of key-id for singning."
247   (aset context 9 signers))
248
249 (defun epg-context-set-process (context process)
250   "Set the process object of `epg-gpg-program'.
251 This function is for internal use only."
252   (aset context 10 process))
253
254 (defun epg-context-set-output-file (context output-file)
255   "Set the output file of `epg-gpg-program'.
256 This function is for internal use only."
257   (aset context 11 output-file))
258
259 (defun epg-context-set-result (context result)
260   "Set the result of the previous cryptographic operation."
261   (aset context 12 result))
262
263 (defun epg-make-signature (status key-id user-id)
264   "Return a signature object."
265   (vector status key-id user-id nil nil))
266
267 (defun epg-signature-status (signature)
268   "Return the status code of SIGNATURE."
269   (aref signature 0))
270
271 (defun epg-signature-key-id (signature)
272   "Return the key-id of SIGNATURE."
273   (aref signature 1))
274
275 (defun epg-signature-user-id (signature)
276   "Return the user-id of SIGNATURE."
277   (aref signature 2))
278   
279 (defun epg-signature-validity (signature)
280   "Return the validity of SIGNATURE."
281   (aref signature 3))
282
283 (defun epg-signature-fingerprint (signature)
284   "Return the fingerprint of SIGNATURE."
285   (aref signature 4))
286
287 (defun epg-signature-set-status (signature status)
288  "Set the status code of SIGNATURE."
289   (aset signature 0 status))
290
291 (defun epg-signature-set-key-id (signature key-id)
292  "Set the key-id of SIGNATURE."
293   (aset signature 1 key-id))
294
295 (defun epg-signature-set-user-id (signature user-id)
296  "Set the user-id of SIGNATURE."
297   (aset signature 2 user-id))
298   
299 (defun epg-signature-set-validity (signature validity)
300  "Set the validity of SIGNATURE."
301   (aset signature 3 validity))
302
303 (defun epg-signature-set-fingerprint (signature fingerprint)
304  "Set the fingerprint of SIGNATURE."
305   (aset signature 4 fingerprint))
306
307 (defun epg-make-key (owner-trust)
308   "Return a key object."
309   (vector owner-trust nil nil))
310
311 (defun epg-key-owner-trust (key)
312   "Return the owner trust of KEY."
313   (aref key 0))
314
315 (defun epg-key-sub-key-list (key)
316   "Return the sub key list of KEY."
317   (aref key 1))
318
319 (defun epg-key-user-id-list (key)
320   "Return the user ID list of KEY."
321   (aref key 2))
322
323 (defun epg-key-set-sub-key-list (key sub-key-list)
324   "Set the sub key list of KEY."
325   (aset key 1 sub-key-list))
326
327 (defun epg-key-set-user-id-list (key user-id-list)
328   "Set the user ID list of KEY."
329   (aset key 2 user-id-list))
330
331 (defun epg-make-sub-key (validity capability secret algorithm length id
332                                   creation-time expiration-time)
333   "Return a sub key object."
334   (vector validity capability secret algorithm length id creation-time
335           expiration-time nil))
336
337 (defun epg-sub-key-validity (sub-key)
338   "Return the validity of SUB-KEY."
339   (aref sub-key 0))
340
341 (defun epg-sub-key-capability (sub-key)
342   "Return the capability of SUB-KEY."
343   (aref sub-key 1))
344
345 (defun epg-sub-key-secret (sub-key)
346   "Return non-nil if SUB-KEY is a secret key."
347   (aref sub-key 2))
348
349 (defun epg-sub-key-algorithm (sub-key)
350   "Return the algorithm of SUB-KEY."
351   (aref sub-key 3))
352
353 (defun epg-sub-key-length (sub-key)
354   "Return the length of SUB-KEY."
355   (aref sub-key 4))
356
357 (defun epg-sub-key-id (sub-key)
358   "Return the ID of SUB-KEY."
359   (aref sub-key 5))
360
361 (defun epg-sub-key-creation-time (sub-key)
362   "Return the creation time of SUB-KEY."
363   (aref sub-key 6))
364
365 (defun epg-sub-key-expiration-time (sub-key)
366   "Return the expiration time of SUB-KEY."
367   (aref sub-key 7))
368
369 (defun epg-sub-key-fingerprint (sub-key)
370   "Return the fingerprint of SUB-KEY."
371   (aref sub-key 8))
372
373 (defun epg-sub-key-set-fingerprint (sub-key fingerprint)
374   "Set the fingerprint of SUB-KEY.
375 This function is for internal use only."
376   (aset sub-key 8 fingerprint))
377
378 (defun epg-make-user-id (validity name)
379   "Return a user ID object."
380   (vector validity name nil))
381
382 (defun epg-user-id-validity (user-id)
383   "Return the validity of USER-ID."
384   (aref user-id 0))
385
386 (defun epg-user-id-name (user-id)
387   "Return the name of USER-ID."
388   (aref user-id 1))
389
390 (defun epg-user-id-signature-list (user-id)
391   "Return the signature list of USER-ID."
392   (aref user-id 2))
393
394 (defun epg-user-id-set-signature-list (user-id signature-list)
395   "Set the signature list of USER-ID."
396   (aset user-id 2 signature-list))
397
398 (defun epg-context-result-for (context name)
399   (cdr (assq name (epg-context-result context))))
400
401 (defun epg-context-set-result-for (context name value)
402   (let* ((result (epg-context-result context))
403          (entry (assq name result)))
404     (if entry
405         (setcdr entry value)
406       (epg-context-set-result context (cons (cons name value) result)))))
407
408 (defun epg-start (context args)
409   "Start `epg-gpg-program' in a subprocess with given ARGS."
410   (let* ((args (append (list "--no-tty"
411                              "--status-fd" "1"
412                              "--command-fd" "0")
413                        (if (epg-context-armor context) '("--armor"))
414                        (if (epg-context-textmode context) '("--textmode"))
415                        (if (epg-context-output-file context)
416                            (list "--output" (epg-context-output-file context)))
417                        args))
418          (coding-system-for-write 'binary)
419          process-connection-type
420          (orig-mode (default-file-modes))
421          (buffer (generate-new-buffer " *epg*"))
422          process)
423     (if epg-debug
424         (save-excursion
425           (set-buffer (get-buffer-create  " *epg-debug*"))
426           (goto-char (point-max))
427           (insert (format "%s %s\n" epg-gpg-program
428                           (mapconcat #'identity args " ")))))
429     (with-current-buffer buffer
430       (make-local-variable 'epg-read-point)
431       (setq epg-read-point (point-min))
432       (make-local-variable 'epg-pending-status-list)
433       (setq epg-pending-status-list nil)
434       (make-local-variable 'epg-key-id)
435       (setq epg-key-id nil)
436       (make-local-variable 'epg-context)
437       (setq epg-context context))
438     (unwind-protect
439         (progn
440           (set-default-file-modes 448)
441           (setq process
442                 (apply #'start-process "epg" buffer epg-gpg-program args)))
443       (set-default-file-modes orig-mode))
444     (set-process-filter process #'epg-process-filter)
445     (epg-context-set-process context process)))
446
447 (defun epg-process-filter (process input)
448   (if epg-debug
449       (save-excursion
450         (set-buffer (get-buffer-create  " *epg-debug*"))
451         (goto-char (point-max))
452         (insert input)))
453   (if (buffer-live-p (process-buffer process))
454       (save-excursion
455         (set-buffer (process-buffer process))
456         (goto-char (point-max))
457         (insert input)
458         (goto-char epg-read-point)
459         (beginning-of-line)
460         (while (looking-at ".*\n")      ;the input line finished
461           (save-excursion
462             (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\) ?\\(.*\\)")
463                 (let* ((status (match-string 1))
464                        (string (match-string 2))
465                        (symbol (intern-soft (concat "epg-status-" status))))
466                   (if (member status epg-pending-status-list)
467                       (setq epg-pending-status-list nil))
468                   (if (and symbol
469                            (fboundp symbol))
470                       (funcall symbol process string))
471                   (condition-case nil
472                       (run-hook-with-args-until-success
473                        (intern (concat "epg-after-status-" status "-function"))
474                        string)
475                     (error)))))
476           (forward-line))
477         (setq epg-read-point (point)))))
478
479 (defun epg-read-output (context)
480   (with-temp-buffer
481     (if (fboundp 'set-buffer-multibyte)
482         (set-buffer-multibyte nil))
483     (if (file-exists-p (epg-context-output-file context))
484         (let ((coding-system-for-read (if (epg-context-textmode context)
485                                           'raw-text
486                                         'binary)))
487           (insert-file-contents (epg-context-output-file context))
488           (buffer-string)))))
489
490 (defun epg-wait-for-status (context status-list)
491   (with-current-buffer (process-buffer (epg-context-process context))
492     (setq epg-pending-status-list status-list)
493     (while (and (eq (process-status (epg-context-process context)) 'run)
494                 epg-pending-status-list)
495       (accept-process-output (epg-context-process context) 1))))
496
497 (defun epg-wait-for-completion (context &optional no-eof)
498   (if (and (not no-eof)
499            (eq (process-status (epg-context-process context)) 'run))
500       (process-send-eof (epg-context-process context)))
501   (while (eq (process-status (epg-context-process context)) 'run)
502     ;; We can't use accept-process-output instead of sit-for here
503     ;; because it may cause an interrupt during the sentinel execution.
504     (sit-for 0.1)))
505
506 (defun epg-reset (context)
507   (if (and (epg-context-process context)
508            (buffer-live-p (process-buffer (epg-context-process context))))
509       (kill-buffer (process-buffer (epg-context-process context))))
510   (epg-context-set-process context nil))
511
512 (defun epg-delete-output-file (context)
513   (if (and (epg-context-output-file context)
514            (file-exists-p (epg-context-output-file context)))
515       (delete-file (epg-context-output-file context))))
516
517 (defun epg-status-USERID_HINT (process string)
518   (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
519       (let* ((key-id (match-string 1 string))
520              (user-id (match-string 2 string))
521              (entry (assoc key-id epg-user-id-alist)))
522         (if entry
523             (setcdr entry user-id)
524           (setq epg-user-id-alist (cons (cons key-id user-id)
525                                         epg-user-id-alist))))))
526
527 (defun epg-status-NEED_PASSPHRASE (process string)
528   (if (string-match "\\`\\([^ ]+\\)" string)
529       (setq epg-key-id (match-string 1 string))))
530
531 (defun epg-status-NEED_PASSPHRASE_SYM (process string)
532   (setq epg-key-id 'SYM))
533
534 (defun epg-status-NEED_PASSPHRASE_PIN (process string)
535   (setq epg-key-id 'PIN))
536
537 (defun epg-status-GET_HIDDEN (process string)
538   (let ((passphrase
539          (funcall (if (consp (epg-context-passphrase-callback epg-context))
540                       (car (epg-context-passphrase-callback epg-context))
541                     (epg-context-passphrase-callback epg-context))
542                   (if (consp (epg-context-passphrase-callback epg-context))
543                       (cdr (epg-context-passphrase-callback epg-context)))))
544         string)
545     (if passphrase
546         (unwind-protect
547             (progn
548               (setq string (concat passphrase "\n"))
549               (fillarray passphrase 0)
550               (setq passphrase nil)
551               (process-send-string process string))
552           (if string
553               (fillarray string 0))))))
554
555 (defun epg-status-GET_BOOL (process string)
556   (let ((entry (assoc string epg-prompt-alist)))
557     (if (y-or-n-p (if entry (cdr entry) (concat string "? ")))
558         (process-send-string process "y\n")
559       (process-send-string process "n\n"))))
560
561 (defun epg-status-GET_LINE (process string)
562   (let* ((entry (assoc string epg-prompt-alist))
563          (string (read-string (if entry (cdr entry) (concat string ": ")))))
564     (process-send-string process (concat string "\n"))))
565
566 (defun epg-status-GOODSIG (process string)
567   (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
568       (epg-context-set-result-for
569        epg-context
570        'verify
571        (cons (epg-make-signature 'good
572                                  (match-string 1 string)
573                                  (match-string 2 string))
574              (epg-context-result-for epg-context 'verify)))))
575
576 (defun epg-status-EXPSIG (process string)
577   (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
578       (epg-context-set-result-for
579        epg-context
580        'verify
581        (cons (epg-make-signature 'expired
582                                  (match-string 1 string)
583                                  (match-string 2 string))
584              (epg-context-result-for epg-context 'verify)))))
585
586 (defun epg-status-EXPKEYSIG (process string)
587   (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
588       (epg-context-set-result-for
589        epg-context
590        'verify
591        (cons (epg-make-signature 'expired-key
592                                  (match-string 1 string)
593                                  (match-string 2 string))
594              (epg-context-result-for epg-context 'verify)))))
595
596 (defun epg-status-REVKEYSIG (process string)
597   (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
598       (epg-context-set-result-for
599        epg-context
600        'verify
601        (cons (epg-make-signature 'revoked-key
602                                  (match-string 1 string)
603                                  (match-string 2 string))
604              (epg-context-result-for epg-context 'verify)))))
605
606 (defun epg-status-BADSIG (process string)
607   (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
608       (epg-context-set-result-for
609        epg-context
610        'verify
611        (cons (epg-make-signature 'bad
612                                  (match-string 1 string)
613                                  (match-string 2 string))
614              (epg-context-result-for epg-context 'verify)))))
615
616 (defun epg-status-VALIDSIG (process string)
617   (let ((signature (car (epg-context-result-for epg-context 'verify))))
618     (if (and signature
619              (eq (epg-signature-status signature) 'good)
620              (string-match "\\`\\([^ ]+\\) " string))
621         (epg-signature-set-fingerprint signature (match-string 1 string)))))
622
623 (defun epg-status-TRUST_UNDEFINED (process string)
624   (let ((signature (car (epg-context-result-for epg-context 'verify))))
625     (if (and signature
626              (eq (epg-signature-status signature) 'good))
627         (epg-signature-set-validity signature 'undefined))))
628
629 (defun epg-status-TRUST_NEVER (process string)
630   (let ((signature (car (epg-context-result-for epg-context 'verify))))
631     (if (and signature
632              (eq (epg-signature-status signature) 'good))
633         (epg-signature-set-validity signature 'never))))
634
635 (defun epg-status-TRUST_MARGINAL (process string)
636   (let ((signature (car (epg-context-result-for epg-context 'verify))))
637     (if (and signature
638              (eq (epg-signature-status signature) 'marginal))
639         (epg-signature-set-validity signature 'marginal))))
640
641 (defun epg-status-TRUST_FULLY (process string)
642   (let ((signature (car (epg-context-result-for epg-context 'verify))))
643     (if (and signature
644              (eq (epg-signature-status signature) 'good))
645         (epg-signature-set-validity signature 'full))))
646
647 (defun epg-status-TRUST_ULTIMATE (process string)
648   (let ((signature (car (epg-context-result-for epg-context 'verify))))
649     (if (and signature
650              (eq (epg-signature-status signature) 'good))
651         (epg-signature-set-validity signature 'ultimate))))
652
653 (defun epg-status-PROGRESS (process string)
654   (if (string-match "\\`\\([^ ]+\\) \\([^ ]\\) \\([0-9]+\\) \\([0-9]+\\)"
655                     string)
656       (funcall (if (consp (epg-context-progress-callback epg-context))
657                    (car (epg-context-progress-callback epg-context))
658                  (epg-context-progress-callback epg-context))
659                (match-string 1 string)
660                (match-string 2 string)
661                (string-to-number (match-string 3 string))
662                (string-to-number (match-string 4 string))
663                (if (consp (epg-context-progress-callback epg-context))
664                    (cdr (epg-context-progress-callback epg-context))))))
665
666 (defun epg-status-DECRYPTION_FAILED (process string)
667   (epg-context-set-result-for
668    epg-context 'error
669    (cons 'decryption-failed
670          (epg-context-result-for epg-context 'error))))
671
672 (defun epg-status-NODATA (process string)
673   (epg-context-set-result-for
674    epg-context 'error
675    (cons (cons 'no-data (string-to-number string))
676          (epg-context-result-for epg-context 'error))))
677
678 (defun epg-status-UNEXPECTED (process string)
679   (epg-context-set-result-for
680    epg-context 'error
681    (cons (cons 'unexpected (string-to-number string))
682          (epg-context-result-for epg-context 'error))))
683
684 (defun epg-status-KEYEXPIRED (process string)
685   (epg-context-set-result-for
686    epg-context 'error
687    (cons (cons 'key-expired string)
688          (epg-context-result-for epg-context 'error))))
689
690 (defun epg-status-KEYREVOKED (process string)
691   (epg-context-set-result-for
692    epg-context 'error
693    (cons 'key-revoked
694          (epg-context-result-for epg-context 'error))))
695
696 (defun epg-status-BADARMOR (process string)
697   (epg-context-set-result-for
698    epg-context 'error
699    (cons 'bad-armor
700          (epg-context-result-for epg-context 'error))))
701
702 (defun epg-status-INV_RECP (process string)
703   (if (string-match "\\`\\([0-9]+\\) \\(.*\\)" string)
704       (epg-context-set-result-for
705        epg-context 'error
706        (cons (list 'invalid-recipient
707                    (string-to-number (match-string 1 string))
708                    (match-string 2 string))
709              (epg-context-result-for epg-context 'error)))))
710
711 (defun epg-status-NO_RECP (process string)
712   (epg-context-set-result-for
713    epg-context 'error
714    (cons 'no-recipients
715          (epg-context-result-for epg-context 'error))))
716
717 (defun epg-status-DELETE_PROBLEM (process string)
718   (if (string-match "\\`\\([0-9]+\\)" string)
719       (epg-context-set-result-for
720        epg-context 'error
721        (cons (cons 'delete-problem (string-to-number (match-string 1 string)))
722              (epg-context-result-for epg-context 'error)))))
723
724 (defun epg-passphrase-callback-function (handback)
725   (read-passwd
726    (if (eq epg-key-id 'SYM)
727        "Passphrase for symmetric encryption: "
728      (if (eq epg-key-id 'PIN)
729          "Passphrase for PIN: "
730        (let ((entry (assoc epg-key-id epg-user-id-alist)))
731          (if entry
732              (format "Passphrase for %s %s: " epg-key-id (cdr entry))
733            (format "Passphrase for %s: " epg-key-id)))))))
734
735 (defun epg-progress-callback-function (what char current total handback)
736   (message "%s: %d%%/%d%%" what current total))
737
738 (defun epg-configuration ()
739   "Return a list of internal configuration parameters of `epg-gpg-program'."
740   (let (config type)
741     (with-temp-buffer
742       (apply #'call-process epg-gpg-program nil (list t nil) nil
743              '("--with-colons" "--list-config"))
744       (goto-char (point-min))
745       (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t)
746         (setq type (intern (match-string 1))
747               config (cons (cons type
748                                  (if (memq type
749                                            '(pubkey cipher digest compress))
750                                      (mapcar #'string-to-number
751                                              (delete "" (split-string
752                                                          (match-string 2)
753                                                          ";")))
754                                    (match-string 2)))
755                            config))))
756     config))
757
758 (defun epg-list-keys-1 (name mode)
759   (let ((args (append (list "--with-colons" "--no-greeting" "--batch"
760                             "--fixed-list-mode" "--with-fingerprint"
761                             "--with-fingerprint"
762                             (if mode "--list-secret-keys" "--list-keys"))
763                       (if name (list name))))
764         keys string field index)
765     (with-temp-buffer
766       (apply #'call-process epg-gpg-program nil (list t nil) nil args)
767       (goto-char (point-min))
768       (while (re-search-forward "^[a-z][a-z][a-z]:.*" nil t)
769         (setq keys (cons (make-vector 15 nil) keys)
770               string (match-string 0)
771               index 0
772               field 0)
773         (while (eq index
774                    (string-match "\\([^:]+\\)?:" string index))
775           (setq index (match-end 0))
776           (aset (car keys) field (match-string 1 string))
777           (setq field (1+ field))))
778       (nreverse keys))))
779
780 (defun epg-make-sub-key-1 (line)
781   (epg-make-sub-key
782    (if (aref line 1)
783        (cdr (assq (string-to-char (aref line 1)) epg-key-validity-alist)))
784    (delq nil
785          (mapcar (lambda (char) (cdr (assq char epg-key-capablity-alist)))
786                  (aref line 11)))
787    (member (aref line 0) '("sec" "ssb"))
788    (string-to-number (aref line 3))
789    (string-to-number (aref line 2))
790    (aref line 4)
791    (aref line 5)
792    (aref line 6)))
793
794 (defun epg-list-keys (&optional name mode)
795   (let ((lines (epg-list-keys-1 name mode))
796         keys)
797     (while lines
798       (cond
799        ((member (aref (car lines) 0) '("pub" "sec"))
800         (when (car keys)
801           (epg-key-set-sub-key-list
802            (car keys)
803            (nreverse (epg-key-sub-key-list (car keys))))
804           (epg-key-set-user-id-list
805            (car keys)
806            (nreverse (epg-key-user-id-list (car keys)))))
807         (setq keys (cons (epg-make-key
808                           (if (aref (car lines) 8)
809                               (cdr (assq (string-to-char (aref (car lines) 8))
810                                          epg-key-validity-alist))))
811                          keys))
812         (epg-key-set-sub-key-list
813          (car keys)
814          (cons (epg-make-sub-key-1 (car lines))
815                (epg-key-sub-key-list (car keys)))))
816        ((member (aref (car lines) 0) '("sub" "ssb"))
817         (epg-key-set-sub-key-list
818          (car keys)
819          (cons (epg-make-sub-key-1 (car lines))
820                (epg-key-sub-key-list (car keys)))))
821        ((equal (aref (car lines) 0) "uid")
822         (epg-key-set-user-id-list
823          (car keys)
824          (cons (epg-make-user-id
825                 (if (aref (car lines) 1)
826                     (cdr (assq (string-to-char (aref (car lines) 1))
827                                epg-key-validity-alist)))
828                 (aref (car lines) 9))
829                (epg-key-user-id-list (car keys)))))
830        ((equal (aref (car lines) 0) "fpr")
831         (epg-sub-key-set-fingerprint (car (epg-key-sub-key-list (car keys)))
832                                      (aref (car lines) 9))))
833       (setq lines (cdr lines)))
834     (nreverse keys)))
835
836 (if (fboundp 'make-temp-file)
837     (defalias 'epg-make-temp-file 'make-temp-file)
838   ;; stolen from poe.el.
839   (defun epg-make-temp-file (prefix)
840     "Create a temporary file.
841 The returned file name (created by appending some random characters at the end
842 of PREFIX, and expanding against `temporary-file-directory' if necessary),
843 is guaranteed to point to a newly created empty file.
844 You can then use `write-region' to write new data into the file."
845     (let (tempdir tempfile)
846       (unwind-protect
847           (let (file)
848             ;; First, create a temporary directory.
849             (while (condition-case ()
850                        (progn
851                          (setq tempdir (make-temp-name
852                                         (concat
853                                          (file-name-directory prefix)
854                                          "DIR")))
855                          ;; return nil or signal an error.
856                          (make-directory tempdir))
857                      ;; let's try again.
858                      (file-already-exists t)))
859             (set-file-modes tempdir 448)
860             ;; Second, create a temporary file in the tempdir.
861             ;; There *is* a race condition between `make-temp-name'
862             ;; and `write-region', but we don't care it since we are
863             ;; in a private directory now.
864             (setq tempfile (make-temp-name (concat tempdir "/EMU")))
865             (write-region "" nil tempfile nil 'silent)
866             (set-file-modes tempfile 384)
867             ;; Finally, make a hard-link from the tempfile.
868             (while (condition-case ()
869                        (progn
870                          (setq file (make-temp-name prefix))
871                          ;; return nil or signal an error.
872                          (add-name-to-file tempfile file))
873                      ;; let's try again.
874                      (file-already-exists t)))
875             file)
876         ;; Cleanup the tempfile.
877         (and tempfile
878              (file-exists-p tempfile)
879              (delete-file tempfile))
880         ;; Cleanup the tempdir.
881         (and tempdir
882              (file-directory-p tempdir)
883              (delete-directory tempdir))))))
884
885 ;;;###autoload
886 (defun epg-start-decrypt (context cipher)
887   "Initiate a decrypt operation on CIPHER.
888 CIPHER is a data object.
889
890 If you use this function, you will need to wait for the completion of
891 `epg-gpg-program' by using `epg-wait-for-completion' and call
892 `epg-reset' to clear a temporaly output file.
893 If you are unsure, use synchronous version of this function
894 `epg-decrypt-file' or `epg-decrypt-string' instead."
895   (unless (epg-data-file cipher)
896     (error "Not a file"))
897   (epg-context-set-result context nil)
898   (epg-start context (list "--decrypt" (epg-data-file cipher)))
899   (epg-wait-for-status context '("BEGIN_DECRYPTION")))
900
901 ;;;###autoload
902 (defun epg-decrypt-file (context cipher plain)
903   "Decrypt a file CIPHER and store the result to a file PLAIN.
904 If PLAIN is nil, it returns the result as a string."
905   (unwind-protect
906       (progn
907         (if plain
908             (epg-context-set-output-file context plain)
909           (epg-context-set-output-file context
910                                        (epg-make-temp-file "epg-output")))
911         (epg-start-decrypt context (epg-make-data-from-file cipher))
912         (epg-wait-for-completion context t)
913         (if (epg-context-result-for context 'error)
914             (error "Decrypt failed: %S"
915                    (epg-context-result-for context 'error)))
916         (unless plain
917           (epg-read-output context)))
918     (unless plain
919       (epg-delete-output-file context))
920     (epg-reset context)))
921
922 ;;;###autoload
923 (defun epg-decrypt-string (context cipher)
924   "Decrypt a string CIPHER and return the plain text."
925   (let ((input-file (epg-make-temp-file "epg-input"))
926         (coding-system-for-write 'binary))
927     (unwind-protect
928         (progn
929           (write-region cipher nil input-file)
930           (epg-context-set-output-file context
931                                        (epg-make-temp-file "epg-output"))
932           (epg-start-decrypt context (epg-make-data-from-file input-file))
933           (epg-wait-for-completion context)
934           (if (epg-context-result-for context 'error)
935               (error "Decrypt failed: %S"
936                      (epg-context-result-for context 'error)))
937           (epg-read-output context))
938       (epg-delete-output-file context)
939       (if (file-exists-p input-file)
940           (delete-file input-file))
941       (epg-reset context))))
942
943 ;;;###autoload
944 (defun epg-start-verify (context signature &optional signed-text)
945   "Initiate a verify operation on SIGNATURE.
946 SIGNATURE and SIGNED-TEXT are a data object if they are specified.
947
948 For a detached signature, both SIGNATURE and SIGNED-TEXT should be set.
949 For a normal or a clear text signature, SIGNED-TEXT should be nil.
950
951 If you use this function, you will need to wait for the completion of
952 `epg-gpg-program' by using `epg-wait-for-completion' and call
953 `epg-reset' to clear a temporaly output file.
954 If you are unsure, use synchronous version of this function
955 `epg-verify-file' or `epg-verify-string' instead."
956   (epg-context-set-result context nil)
957   (if signed-text
958       ;; Detached signature.
959       (if (epg-data-file signed-text)
960           (epg-start context (list "--verify" (epg-data-file signature)
961                                    (epg-data-file signed-text)))
962         (epg-start context (list "--verify" (epg-data-file signature) "-"))
963         (if (eq (process-status (epg-context-process context)) 'run)
964             (process-send-string (epg-context-process context)
965                                  (epg-data-string signed-text))))
966     ;; Normal (or cleartext) signature.
967     (if (epg-data-file signature)
968         (epg-start context (list "--verify" (epg-data-file signature)))
969       (epg-start context (list "--verify"))
970       (if (eq (process-status (epg-context-process context)) 'run)
971           (process-send-string (epg-context-process context)
972                                (epg-data-string signature))))))
973
974 ;;;###autoload
975 (defun epg-verify-file (context signature &optional signed-text plain)
976   "Verify a file SIGNATURE.
977 SIGNED-TEXT and PLAIN are also a file if they are specified.
978
979 For a detached signature, both SIGNATURE and SIGNED-TEXT should be string.
980 For a normal or a clear text signature, SIGNED-TEXT should be nil."
981   (unwind-protect
982       (progn
983         (if plain
984             (epg-context-set-output-file context plain)
985           (epg-context-set-output-file context
986                                        (epg-make-temp-file "epg-output")))
987         (if signed-text
988             (epg-start-verify context
989                               (epg-make-data-from-file signature)
990                               (epg-make-data-from-file signed-text))
991           (epg-start-verify context
992                             (epg-make-data-from-file signature)))
993         (epg-wait-for-completion context t)
994         (unless plain
995           (epg-read-output context)))
996     (unless plain
997       (epg-delete-output-file context))
998     (epg-reset context)))
999
1000 ;;;###autoload
1001 (defun epg-verify-string (context signature &optional signed-text)
1002   "Verify a string SIGNATURE.
1003 SIGNED-TEXT is a string if it is specified.
1004
1005 For a detached signature, both SIGNATURE and SIGNED-TEXT should be string.
1006 For a normal or a clear text signature, SIGNED-TEXT should be nil."
1007   (let ((coding-system-for-write 'binary)
1008         input-file)
1009     (unwind-protect
1010         (progn
1011           (epg-context-set-output-file context
1012                                        (epg-make-temp-file "epg-output"))
1013           (if signed-text
1014               (progn
1015                 (setq input-file (epg-make-temp-file "epg-signature"))
1016                 (write-region signature nil input-file)
1017                 (epg-start-verify context
1018                                   (epg-make-data-from-file input-file)
1019                                   (epg-make-data-from-string signed-text)))
1020             (epg-start-verify context (epg-make-data-from-string signature)))
1021           (epg-wait-for-completion context)
1022           (epg-read-output context))
1023       (epg-delete-output-file context)
1024       (if (and input-file
1025                (file-exists-p input-file))
1026           (delete-file input-file))
1027       (epg-reset context))))
1028
1029 ;;;###autoload
1030 (defun epg-start-sign (context plain &optional mode)
1031   "Initiate a sign operation on PLAIN.
1032 PLAIN is a data object.
1033
1034 If optional 3rd argument MODE is 'clearsign, it makes a clear text signature.
1035 If MODE is t or 'detached, it makes a detached signature.
1036 Otherwise, it makes a normal signature.
1037
1038 If you use this function, you will need to wait for the completion of
1039 `epg-gpg-program' by using `epg-wait-for-completion' and call
1040 `epg-reset' to clear a temporaly output file.
1041 If you are unsure, use synchronous version of this function
1042 `epg-sign-file' or `epg-sign-string' instead."
1043   (epg-context-set-result context nil)
1044   (epg-start context
1045              (append (list (if (eq mode 'clearsign)
1046                                "--clearsign"
1047                              (if (or (eq mode t) (eq mode 'detached))
1048                                  "--detach-sign"
1049                                "--sign")))
1050                      (apply #'nconc
1051                             (mapcar (lambda (signer)
1052                                       (list "-u" signer))
1053                                     (epg-context-signers context)))
1054                      (if (epg-data-file plain)
1055                          (list (epg-data-file plain)))))
1056   (epg-wait-for-status context '("BEGIN_SIGNING"))
1057   (if (and (epg-data-string plain)
1058            (eq (process-status (epg-context-process context)) 'run))
1059       (process-send-string (epg-context-process context)
1060                            (epg-data-string plain))))
1061
1062 ;;;###autoload
1063 (defun epg-sign-file (context plain signature &optional mode)
1064   "Sign a file PLAIN and store the result to a file SIGNATURE.
1065 If SIGNATURE is nil, it returns the result as a string.
1066 If optional 3rd argument MODE is 'clearsign, it makes a clear text signature.
1067 If MODE is t or 'detached, it makes a detached signature.
1068 Otherwise, it makes a normal signature."
1069   (unwind-protect
1070       (progn
1071         (if signature
1072             (epg-context-set-output-file context signature)
1073           (epg-context-set-output-file context
1074                                        (epg-make-temp-file "epg-output")))
1075         (epg-start-sign context (epg-make-data-from-file plain) mode)
1076         (epg-wait-for-completion context t)
1077         (if (epg-context-result-for context 'error)
1078             (error "Sign failed: %S"
1079                    (epg-context-result-for context 'error)))
1080         (unless signature
1081           (epg-read-output context)))
1082     (unless signature
1083       (epg-delete-output-file context))
1084     (epg-reset context)))
1085
1086 ;;;###autoload
1087 (defun epg-sign-string (context plain &optional mode)
1088   "Sign a string PLAIN and return the output as string.
1089 If optional 3rd argument MODE is 'clearsign, it makes a clear text signature.
1090 If MODE is t or 'detached, it makes a detached signature.
1091 Otherwise, it makes a normal signature."
1092   (unwind-protect
1093       (progn
1094         (epg-context-set-output-file context
1095                                      (epg-make-temp-file "epg-output"))
1096         (epg-start-sign context (epg-make-data-from-string plain) mode)
1097         (epg-wait-for-completion context)
1098         (if (epg-context-result-for context 'error)
1099             (error "Sign failed: %S"
1100                    (epg-context-result-for context 'error)))
1101         (epg-read-output context))
1102     (epg-delete-output-file context)
1103     (epg-reset context)))
1104
1105 ;;;###autoload
1106 (defun epg-start-encrypt (context plain recipients
1107                                   &optional sign always-trust)
1108   "Initiate an encrypt operation on PLAIN.
1109 PLAIN is a data object.
1110 If RECIPIENTS is nil, it performs symmetric encryption.
1111
1112 If you use this function, you will need to wait for the completion of
1113 `epg-gpg-program' by using `epg-wait-for-completion' and call
1114 `epg-reset' to clear a temporaly output file.
1115 If you are unsure, use synchronous version of this function
1116 `epg-encrypt-file' or `epg-encrypt-string' instead."
1117   (epg-context-set-result context nil)
1118   (epg-start context
1119              (append (if always-trust '("--always-trust"))
1120                      (if recipients '("--encrypt") '("--symmetric"))
1121                      (if sign
1122                          (cons "--sign"
1123                                (apply #'nconc
1124                                       (mapcar (lambda (signer)
1125                                                 (list "-u" signer))
1126                                               (epg-context-signers context)))))
1127                      (apply #'nconc
1128                             (mapcar (lambda (recipient)
1129                                       (list "-r" recipient))
1130                                     recipients))
1131                      (if (epg-data-file plain)
1132                          (list (epg-data-file plain)))))
1133   (if sign
1134       (epg-wait-for-status context '("BEGIN_SIGNING")))
1135   (epg-wait-for-status context '("BEGIN_ENCRYPTION"))
1136   (if (and (epg-data-string plain)
1137            (eq (process-status (epg-context-process context)) 'run))
1138       (process-send-string (epg-context-process context)
1139                            (epg-data-string plain))))
1140
1141 ;;;###autoload
1142 (defun epg-encrypt-file (context plain recipients
1143                                  cipher &optional sign always-trust)
1144   "Encrypt a file PLAIN and store the result to a file CIPHER.
1145 If CIPHER is nil, it returns the result as a string.
1146 If RECIPIENTS is nil, it performs symmetric encryption."
1147   (unwind-protect
1148       (progn
1149         (if cipher
1150             (epg-context-set-output-file context cipher)
1151           (epg-context-set-output-file context
1152                                        (epg-make-temp-file "epg-output")))
1153         (epg-start-encrypt context (epg-make-data-from-file plain)
1154                            recipients sign always-trust)
1155         (epg-wait-for-completion context t)
1156         (if (epg-context-result-for context 'error)
1157             (error "Encrypt failed: %S"
1158                    (epg-context-result-for context 'error)))
1159         (unless cipher
1160           (epg-read-output context)))
1161     (unless cipher
1162       (epg-delete-output-file context))
1163     (epg-reset context)))
1164
1165 ;;;###autoload
1166 (defun epg-encrypt-string (context plain recipients
1167                                    &optional sign always-trust)
1168   "Encrypt a string PLAIN.
1169 If RECIPIENTS is nil, it performs symmetric encryption."
1170   (unwind-protect
1171       (progn
1172         (epg-context-set-output-file context
1173                                      (epg-make-temp-file "epg-output"))
1174         (epg-start-encrypt context (epg-make-data-from-string plain)
1175                            recipients sign always-trust)
1176         (epg-wait-for-completion context)
1177         (if (epg-context-result-for context 'error)
1178             (error "Encrypt failed: %S"
1179                    (epg-context-result-for context 'error)))
1180         (epg-read-output context))
1181     (epg-delete-output-file context)
1182     (epg-reset context)))
1183
1184 ;;;###autoload
1185 (defun epg-start-export-keys (context keys)
1186   "Initiate an export keys operation.
1187
1188 If you use this function, you will need to wait for the completion of
1189 `epg-gpg-program' by using `epg-wait-for-completion' and call
1190 `epg-reset' to clear a temporaly output file.
1191 If you are unsure, use synchronous version of this function
1192 `epg-export-keys-to-file' or `epg-export-keys-to-string' instead."
1193   (epg-context-set-result context nil)
1194   (epg-start context (cons "--export"
1195                            (mapcar
1196                             (lambda (key)
1197                               (epg-sub-key-id
1198                                (car (epg-key-sub-key-list key))))
1199                             keys))))
1200
1201 ;;;###autoload
1202 (defun epg-export-keys-to-file (context keys file)
1203   "Extract public KEYS."
1204   (unwind-protect
1205       (progn
1206         (if keys
1207             (epg-context-set-output-file context file)
1208           (epg-context-set-output-file context
1209                                        (epg-make-temp-file "epg-output")))
1210         (epg-start-export-keys context keys)
1211         (epg-wait-for-completion context)
1212         (if (epg-context-result-for context 'error)
1213             (error "Export keys failed"))
1214         (unless file
1215           (epg-read-output context)))
1216     (unless file
1217       (epg-delete-output-file context))
1218     (epg-reset context)))
1219
1220 ;;;###autoload
1221 (defun epg-export-keys-to-string (context keys)
1222   "Extract public KEYS and return them as a string."
1223   (epg-export-keys-to-file context keys nil))
1224
1225 ;;;###autoload
1226 (defun epg-start-import-keys (context keys)
1227   "Initiate an import keys operation.
1228 KEYS is a data object.
1229
1230 If you use this function, you will need to wait for the completion of
1231 `epg-gpg-program' by using `epg-wait-for-completion' and call
1232 `epg-reset' to clear a temporaly output file.
1233 If you are unsure, use synchronous version of this function
1234 `epg-import-keys-from-file' or `epg-import-keys-from-string' instead."
1235   (epg-context-set-result context nil)
1236   (epg-context-set-output-file context (epg-make-temp-file "epg-output"))
1237   (epg-start context (list "--import" (epg-data-file keys)))
1238   (if (and (epg-data-string keys)
1239            (eq (process-status (epg-context-process context)) 'run))
1240       (process-send-string (epg-context-process context)
1241                            (epg-data-string keys))))
1242   
1243 (defun epg-import-keys-1 (context keys)
1244   (unwind-protect
1245       (progn
1246         (epg-start-import-keys context keys)
1247         (epg-wait-for-completion context (epg-data-file keys))
1248         (if (epg-context-result-for context 'error)
1249             (error "Import keys failed"))
1250         (epg-read-output context))
1251     (epg-reset context)))
1252
1253 ;;;###autoload
1254 (defun epg-import-keys-from-file (context keys)
1255   "Add keys from a file KEYS."
1256   (epg-import-keys-1 context (epg-make-data-from-file keys)))
1257
1258 ;;;###autoload
1259 (defun epg-import-keys-from-string (context keys)
1260   "Add keys from a string KEYS."
1261   (epg-import-keys-1 context (epg-make-data-from-string keys)))
1262
1263 ;;;###autoload
1264 (defun epg-start-delete-keys (context keys &optional allow-secret)
1265   "Initiate an delete keys operation.
1266
1267 If you use this function, you will need to wait for the completion of
1268 `epg-gpg-program' by using `epg-wait-for-completion' and call
1269 `epg-reset' to clear a temporaly output file.
1270 If you are unsure, use synchronous version of this function
1271 `epg-delete-keys' instead."
1272   (epg-context-set-result context nil)
1273   (epg-start context (cons (if allow-secret
1274                                "--delete-secret-key"
1275                              "--delete-key")
1276                            (mapcar
1277                             (lambda (key)
1278                               (epg-sub-key-id
1279                                (car (epg-key-sub-key-list key))))
1280                             keys))))
1281
1282 ;;;###autoload
1283 (defun epg-delete-keys (context keys &optional allow-secret)
1284   "Delete KEYS from the key ring."
1285   (unwind-protect
1286       (progn
1287         (epg-start-delete-keys context keys)
1288         (epg-wait-for-completion context t)
1289         (if (epg-context-result-for context 'error)
1290             (error "Delete key failed")))
1291     (epg-reset context)))
1292
1293 (provide 'epg)
1294
1295 ;;; epg.el ends here