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
6 ;; Author: Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: PGP, GnuPG
9 ;; This file is part of EasyPG.
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)
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.
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.
31 (defcustom epg-gpg-program "gpg"
32 "The `gpg' executable."
36 (defcustom epg-gpgsm-program "gpgsm"
37 "The `gpgsm' executable."
41 (defconst epg-version-number "0.0.1")
43 (defvar epg-user-id nil
44 "GnuPG ID of your default identity.")
46 (defvar epg-user-id-alist nil
47 "An alist mapping from key ID to user ID.")
49 (defvar epg-read-point nil)
50 (defvar epg-pending-status-list nil)
51 (defvar epg-key-id nil)
52 (defvar epg-context nil)
53 (defvar epg-debug nil)
54 (defvar epg-debug-buffer nil)
56 ;; from gnupg/include/cipher.h
57 (defconst epg-cipher-algorithm-alist
69 ;; from gnupg/include/cipher.h
70 (defconst epg-pubkey-algorithm-alist
78 ;; from gnupg/include/cipher.h
79 (defconst epg-digest-algorithm-alist
87 ;; from gnupg/include/cipher.h
88 (defconst epg-compress-algorithm-alist
94 (defconst epg-invalid-recipients-reason-alist
95 '((0 . "No specific reason given")
97 (2 . "Ambigious specification")
98 (3 . "Wrong key usage")
103 (8 . "Policy mismatch")
104 (9 . "Not a secret key")
105 (10 . "Key not trusted")))
107 (defconst epg-delete-problem-reason-alist
108 '((1 . "No such key")
109 (2 . "Must delete secret key first")
110 (3 . "Ambigious specification")))
112 (defconst epg-import-ok-reason-alist
113 '((0 . "Not actually changed")
114 (1 . "Entirely new key")
116 (4 . "New signatures")
118 (16 . "Contains private key")))
120 (defconst epg-import-problem-reason-alist
121 '((0 . "No specific reason given")
122 (1 . "Invalid Certificate")
123 (2 . "Issuer Certificate missing")
124 (3 . "Certificate Chain too long")
125 (4 . "Error storing certificate")))
127 (defvar epg-key-validity-alist
140 (defvar epg-key-capablity-alist
144 (?a . authentication)))
146 (defvar epg-new-signature-type-alist
151 (defvar epg-dn-type-alist
152 '(("1.2.840.113549.1.9.1" . "EMail")
156 ("0.2.262.1.10.7.20" . "NameDistinguisher")
157 ("2.5.4.16" . "ADDR")
160 ("2.5.4.17" . "PostalCode")
161 ("2.5.4.65" . "Pseudo")
162 ("2.5.4.5" . "SerialNumber")))
164 (defvar epg-prompt-alist nil)
166 (defun epg-make-data-from-file (file)
167 "Make a data object from FILE."
168 (cons 'epg-data (vector file nil)))
170 (defun epg-make-data-from-string (string)
171 "Make a data object from STRING."
172 (cons 'epg-data (vector nil string)))
174 (defun epg-data-file (data)
175 "Return the file of DATA."
176 (unless (eq (car data) 'epg-data)
177 (signal 'wrong-type-argument (list 'epg-data-p data)))
180 (defun epg-data-string (data)
181 "Return the string of DATA."
182 (unless (eq (car data) 'epg-data)
183 (signal 'wrong-type-argument (list 'epg-data-p data)))
186 (defun epg-make-context (&optional protocol armor textmode include-certs
187 cipher-algorithm digest-algorithm
189 "Return a context object."
191 (vector (or protocol 'OpenPGP) armor textmode include-certs
192 cipher-algorithm digest-algorithm compress-algorithm
193 #'epg-passphrase-callback-function
194 #'epg-progress-callback-function
197 (defun epg-context-protocol (context)
198 "Return the protocol used within CONTEXT."
199 (unless (eq (car context) 'epg-context)
200 (signal 'wrong-type-argument (list 'epg-context-p context)))
201 (aref (cdr context) 0))
203 (defun epg-context-armor (context)
204 "Return t if the output shouled be ASCII armored in CONTEXT."
205 (unless (eq (car context) 'epg-context)
206 (signal 'wrong-type-argument (list 'epg-context-p context)))
207 (aref (cdr context) 1))
209 (defun epg-context-textmode (context)
210 "Return t if canonical text mode should be used in CONTEXT."
211 (unless (eq (car context) 'epg-context)
212 (signal 'wrong-type-argument (list 'epg-context-p context)))
213 (aref (cdr context) 2))
215 (defun epg-context-include-certs (context)
216 "Return how many certificates should be included in an S/MIME signed
218 (unless (eq (car context) 'epg-context)
219 (signal 'wrong-type-argument (list 'epg-context-p context)))
220 (aref (cdr context) 3))
222 (defun epg-context-cipher-algorithm (context)
223 "Return the cipher algorithm in CONTEXT."
224 (unless (eq (car context) 'epg-context)
225 (signal 'wrong-type-argument (list 'epg-context-p context)))
226 (aref (cdr context) 4))
228 (defun epg-context-digest-algorithm (context)
229 "Return the digest algorithm in CONTEXT."
230 (unless (eq (car context) 'epg-context)
231 (signal 'wrong-type-argument (list 'epg-context-p context)))
232 (aref (cdr context) 5))
234 (defun epg-context-compress-algorithm (context)
235 "Return the compress algorithm in CONTEXT."
236 (unless (eq (car context) 'epg-context)
237 (signal 'wrong-type-argument (list 'epg-context-p context)))
238 (aref (cdr context) 6))
240 (defun epg-context-passphrase-callback (context)
241 "Return the function used to query passphrase."
242 (unless (eq (car context) 'epg-context)
243 (signal 'wrong-type-argument (list 'epg-context-p context)))
244 (aref (cdr context) 7))
246 (defun epg-context-progress-callback (context)
247 "Return the function which handles progress update."
248 (unless (eq (car context) 'epg-context)
249 (signal 'wrong-type-argument (list 'epg-context-p context)))
250 (aref (cdr context) 8))
252 (defun epg-context-signers (context)
253 "Return the list of key-id for singning."
254 (unless (eq (car context) 'epg-context)
255 (signal 'wrong-type-argument (list 'epg-context-p context)))
256 (aref (cdr context) 9))
258 (defun epg-context-process (context)
259 "Return the process object of `epg-gpg-program'.
260 This function is for internal use only."
261 (unless (eq (car context) 'epg-context)
262 (signal 'wrong-type-argument (list 'epg-context-p context)))
263 (aref (cdr context) 10))
265 (defun epg-context-output-file (context)
266 "Return the output file of `epg-gpg-program'.
267 This function is for internal use only."
268 (unless (eq (car context) 'epg-context)
269 (signal 'wrong-type-argument (list 'epg-context-p context)))
270 (aref (cdr context) 11))
272 (defun epg-context-result (context)
273 "Return the result of the previous cryptographic operation."
274 (unless (eq (car context) 'epg-context)
275 (signal 'wrong-type-argument (list 'epg-context-p context)))
276 (aref (cdr context) 12))
278 (defun epg-context-set-protocol (context protocol)
279 "Set the protocol used within CONTEXT."
280 (unless (eq (car context) 'epg-context)
281 (signal 'wrong-type-argument (list 'epg-context-p context)))
282 (aset (cdr context) 0 protocol))
284 (defun epg-context-set-armor (context armor)
285 "Specify if the output shouled be ASCII armored in CONTEXT."
286 (unless (eq (car context) 'epg-context)
287 (signal 'wrong-type-argument (list 'epg-context-p context)))
288 (aset (cdr context) 1 armor))
290 (defun epg-context-set-textmode (context textmode)
291 "Specify if canonical text mode should be used in CONTEXT."
292 (unless (eq (car context) 'epg-context)
293 (signal 'wrong-type-argument (list 'epg-context-p context)))
294 (aset (cdr context) 2 textmode))
296 (defun epg-context-set-include-certs (context include-certs)
297 "Set how many certificates should be included in an S/MIME signed message."
298 (unless (eq (car context) 'epg-context)
299 (signal 'wrong-type-argument (list 'epg-context-p context)))
300 (aset (cdr context) 3 include-certs))
302 (defun epg-context-set-cipher-algorithm (context cipher-algorithm)
303 "Set the cipher algorithm in CONTEXT."
304 (unless (eq (car context) 'epg-context)
305 (signal 'wrong-type-argument (list 'epg-context-p context)))
306 (aset (cdr context) 4 cipher-algorithm))
308 (defun epg-context-set-digest-algorithm (context digest-algorithm)
309 "Set the digest algorithm in CONTEXT."
310 (unless (eq (car context) 'epg-context)
311 (signal 'wrong-type-argument (list 'epg-context-p context)))
312 (aset (cdr context) 5 digest-algorithm))
314 (defun epg-context-set-compress-algorithm (context compress-algorithm)
315 "Set the compress algorithm in CONTEXT."
316 (unless (eq (car context) 'epg-context)
317 (signal 'wrong-type-argument (list 'epg-context-p context)))
318 (aset (cdr context) 6 compress-algorithm))
320 (defun epg-context-set-passphrase-callback (context
322 "Set the function used to query passphrase."
323 (unless (eq (car context) 'epg-context)
324 (signal 'wrong-type-argument (list 'epg-context-p context)))
325 (aset (cdr context) 7 passphrase-callback))
327 (defun epg-context-set-progress-callback (context progress-callback)
328 "Set the function which handles progress update."
329 (unless (eq (car context) 'epg-context)
330 (signal 'wrong-type-argument (list 'epg-context-p context)))
331 (aset (cdr context) 8 progress-callback))
333 (defun epg-context-set-signers (context signers)
334 "Set the list of key-id for singning."
335 (unless (eq (car context) 'epg-context)
336 (signal 'wrong-type-argument (list 'epg-context-p context)))
337 (aset (cdr context) 9 signers))
339 (defun epg-context-set-process (context process)
340 "Set the process object of `epg-gpg-program'.
341 This function is for internal use only."
342 (unless (eq (car context) 'epg-context)
343 (signal 'wrong-type-argument (list 'epg-context-p context)))
344 (aset (cdr context) 10 process))
346 (defun epg-context-set-output-file (context output-file)
347 "Set the output file of `epg-gpg-program'.
348 This function is for internal use only."
349 (unless (eq (car context) 'epg-context)
350 (signal 'wrong-type-argument (list 'epg-context-p context)))
351 (aset (cdr context) 11 output-file))
353 (defun epg-context-set-result (context result)
354 "Set the result of the previous cryptographic operation."
355 (unless (eq (car context) 'epg-context)
356 (signal 'wrong-type-argument (list 'epg-context-p context)))
357 (aset (cdr context) 12 result))
359 (defun epg-make-signature (status &optional key-id)
360 "Return a signature object."
361 (cons 'epg-signature (vector status key-id nil nil nil nil nil nil nil nil)))
363 (defun epg-signature-status (signature)
364 "Return the status code of SIGNATURE."
365 (unless (eq (car signature) 'epg-signature)
366 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
367 (aref (cdr signature) 0))
369 (defun epg-signature-key-id (signature)
370 "Return the key-id of SIGNATURE."
371 (unless (eq (car signature) 'epg-signature)
372 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
373 (aref (cdr signature) 1))
375 (defun epg-signature-validity (signature)
376 "Return the validity of SIGNATURE."
377 (unless (eq (car signature) 'epg-signature)
378 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
379 (aref (cdr signature) 2))
381 (defun epg-signature-fingerprint (signature)
382 "Return the fingerprint of SIGNATURE."
383 (unless (eq (car signature) 'epg-signature)
384 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
385 (aref (cdr signature) 3))
387 (defun epg-signature-creation-time (signature)
388 "Return the creation time of SIGNATURE."
389 (unless (eq (car signature) 'epg-signature)
390 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
391 (aref (cdr signature) 4))
393 (defun epg-signature-expiration-time (signature)
394 "Return the expiration time of SIGNATURE."
395 (unless (eq (car signature) 'epg-signature)
396 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
397 (aref (cdr signature) 5))
399 (defun epg-signature-pubkey-algorithm (signature)
400 "Return the public key algorithm of SIGNATURE."
401 (unless (eq (car signature) 'epg-signature)
402 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
403 (aref (cdr signature) 6))
405 (defun epg-signature-digest-algorithm (signature)
406 "Return the digest algorithm of SIGNATURE."
407 (unless (eq (car signature) 'epg-signature)
408 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
409 (aref (cdr signature) 7))
411 (defun epg-signature-class (signature)
412 "Return the class of SIGNATURE."
413 (unless (eq (car signature) 'epg-signature)
414 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
415 (aref (cdr signature) 8))
417 (defun epg-signature-version (signature)
418 "Return the version of SIGNATURE."
419 (unless (eq (car signature) 'epg-signature)
420 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
421 (aref (cdr signature) 9))
423 (defun epg-signature-set-status (signature status)
424 "Set the status code of SIGNATURE."
425 (unless (eq (car signature) 'epg-signature)
426 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
427 (aset (cdr signature) 0 status))
429 (defun epg-signature-set-key-id (signature key-id)
430 "Set the key-id of SIGNATURE."
431 (unless (eq (car signature) 'epg-signature)
432 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
433 (aset (cdr signature) 1 key-id))
435 (defun epg-signature-set-validity (signature validity)
436 "Set the validity of SIGNATURE."
437 (unless (eq (car signature) 'epg-signature)
438 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
439 (aset (cdr signature) 2 validity))
441 (defun epg-signature-set-fingerprint (signature fingerprint)
442 "Set the fingerprint of SIGNATURE."
443 (unless (eq (car signature) 'epg-signature)
444 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
445 (aset (cdr signature) 3 fingerprint))
447 (defun epg-signature-set-creation-time (signature creation-time)
448 "Set the creation time of SIGNATURE."
449 (unless (eq (car signature) 'epg-signature)
450 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
451 (aset (cdr signature) 4 creation-time))
453 (defun epg-signature-set-expiration-time (signature expiration-time)
454 "Set the expiration time of SIGNATURE."
455 (unless (eq (car signature) 'epg-signature)
456 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
457 (aset (cdr signature) 5 expiration-time))
459 (defun epg-signature-set-pubkey-algorithm (signature pubkey-algorithm)
460 "Set the public key algorithm of SIGNATURE."
461 (unless (eq (car signature) 'epg-signature)
462 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
463 (aset (cdr signature) 6 pubkey-algorithm))
465 (defun epg-signature-set-digest-algorithm (signature digest-algorithm)
466 "Set the digest algorithm of SIGNATURE."
467 (unless (eq (car signature) 'epg-signature)
468 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
469 (aset (cdr signature) 7 digest-algorithm))
471 (defun epg-signature-set-class (signature class)
472 "Set the class of SIGNATURE."
473 (unless (eq (car signature) 'epg-signature)
474 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
475 (aset (cdr signature) 8 class))
477 (defun epg-signature-set-version (signature version)
478 "Set the version of SIGNATURE."
479 (unless (eq (car signature) 'epg-signature)
480 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
481 (aset (cdr signature) 9 version))
483 (defun epg-make-new-signature (type pubkey-algorithm digest-algorithm
484 class creation-time fingerprint)
485 "Return a new signature object."
486 (cons 'epg-new-signature (vector type pubkey-algorithm digest-algorithm
487 class creation-time fingerprint)))
489 (defun epg-new-signature-type (new-signature)
490 "Return the type of NEW-SIGNATURE."
491 (unless (eq (car new-signature) 'epg-new-signature)
492 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
493 (aref (cdr new-signature) 0))
495 (defun epg-new-signature-pubkey-algorithm (new-signature)
496 "Return the public key algorithm of NEW-SIGNATURE."
497 (unless (eq (car new-signature) 'epg-new-signature)
498 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
499 (aref (cdr new-signature) 1))
501 (defun epg-new-signature-digest-algorithm (new-signature)
502 "Return the digest algorithm of NEW-SIGNATURE."
503 (unless (eq (car new-signature) 'epg-new-signature)
504 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
505 (aref (cdr new-signature) 2))
507 (defun epg-new-signature-class (new-signature)
508 "Return the class of NEW-SIGNATURE."
509 (unless (eq (car new-signature) 'epg-new-signature)
510 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
511 (aref (cdr new-signature) 3))
513 (defun epg-new-signature-creation-time (new-signature)
514 "Return the creation time of NEW-SIGNATURE."
515 (unless (eq (car new-signature) 'epg-new-signature)
516 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
517 (aref (cdr new-signature) 4))
519 (defun epg-new-signature-fingerprint (new-signature)
520 "Return the fingerprint of NEW-SIGNATURE."
521 (unless (eq (car new-signature) 'epg-new-signature)
522 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
523 (aref (cdr new-signature) 5))
525 (defun epg-make-key (owner-trust)
526 "Return a key object."
527 (cons 'epg-key (vector owner-trust nil nil)))
529 (defun epg-key-owner-trust (key)
530 "Return the owner trust of KEY."
531 (unless (eq (car key) 'epg-key)
532 (signal 'wrong-type-argument (list 'epg-key-p key)))
535 (defun epg-key-sub-key-list (key)
536 "Return the sub key list of KEY."
537 (unless (eq (car key) 'epg-key)
538 (signal 'wrong-type-argument (list 'epg-key-p key)))
541 (defun epg-key-user-id-list (key)
542 "Return the user ID list of KEY."
543 (unless (eq (car key) 'epg-key)
544 (signal 'wrong-type-argument (list 'epg-key-p key)))
547 (defun epg-key-set-sub-key-list (key sub-key-list)
548 "Set the sub key list of KEY."
549 (unless (eq (car key) 'epg-key)
550 (signal 'wrong-type-argument (list 'epg-key-p key)))
551 (aset (cdr key) 1 sub-key-list))
553 (defun epg-key-set-user-id-list (key user-id-list)
554 "Set the user ID list of KEY."
555 (unless (eq (car key) 'epg-key)
556 (signal 'wrong-type-argument (list 'epg-key-p key)))
557 (aset (cdr key) 2 user-id-list))
559 (defun epg-make-sub-key (validity capability secret algorithm length id
560 creation-time expiration-time)
561 "Return a sub key object."
563 (vector validity capability secret algorithm length id creation-time
564 expiration-time nil)))
566 (defun epg-sub-key-validity (sub-key)
567 "Return the validity of SUB-KEY."
568 (unless (eq (car sub-key) 'epg-sub-key)
569 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
570 (aref (cdr sub-key) 0))
572 (defun epg-sub-key-capability (sub-key)
573 "Return the capability of SUB-KEY."
574 (unless (eq (car sub-key) 'epg-sub-key)
575 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
576 (aref (cdr sub-key) 1))
578 (defun epg-sub-key-secret (sub-key)
579 "Return non-nil if SUB-KEY is a secret key."
580 (unless (eq (car sub-key) 'epg-sub-key)
581 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
582 (aref (cdr sub-key) 2))
584 (defun epg-sub-key-algorithm (sub-key)
585 "Return the algorithm of SUB-KEY."
586 (unless (eq (car sub-key) 'epg-sub-key)
587 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
588 (aref (cdr sub-key) 3))
590 (defun epg-sub-key-length (sub-key)
591 "Return the length of SUB-KEY."
592 (unless (eq (car sub-key) 'epg-sub-key)
593 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
594 (aref (cdr sub-key) 4))
596 (defun epg-sub-key-id (sub-key)
597 "Return the ID of SUB-KEY."
598 (unless (eq (car sub-key) 'epg-sub-key)
599 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
600 (aref (cdr sub-key) 5))
602 (defun epg-sub-key-creation-time (sub-key)
603 "Return the creation time of SUB-KEY."
604 (unless (eq (car sub-key) 'epg-sub-key)
605 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
606 (aref (cdr sub-key) 6))
608 (defun epg-sub-key-expiration-time (sub-key)
609 "Return the expiration time of SUB-KEY."
610 (unless (eq (car sub-key) 'epg-sub-key)
611 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
612 (aref (cdr sub-key) 7))
614 (defun epg-sub-key-fingerprint (sub-key)
615 "Return the fingerprint of SUB-KEY."
616 (unless (eq (car sub-key) 'epg-sub-key)
617 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
618 (aref (cdr sub-key) 8))
620 (defun epg-sub-key-set-fingerprint (sub-key fingerprint)
621 "Set the fingerprint of SUB-KEY.
622 This function is for internal use only."
623 (unless (eq (car sub-key) 'epg-sub-key)
624 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
625 (aset (cdr sub-key) 8 fingerprint))
627 (defun epg-make-user-id (validity string)
628 "Return a user ID object."
629 (cons 'epg-user-id (vector validity string nil)))
631 (defun epg-user-id-validity (user-id)
632 "Return the validity of USER-ID."
633 (unless (eq (car user-id) 'epg-user-id)
634 (signal 'wrong-type-argument (list 'epg-user-id-p user-id)))
635 (aref (cdr user-id) 0))
637 (defun epg-user-id-string (user-id)
638 "Return the name of USER-ID."
639 (unless (eq (car user-id) 'epg-user-id)
640 (signal 'wrong-type-argument (list 'epg-user-id-p user-id)))
641 (aref (cdr user-id) 1))
643 (defun epg-user-id-signature-list (user-id)
644 "Return the signature list of USER-ID."
645 (unless (eq (car user-id) 'epg-user-id)
646 (signal 'wrong-type-argument (list 'epg-user-id-p user-id)))
647 (aref (cdr user-id) 2))
649 (defun epg-user-id-set-signature-list (user-id signature-list)
650 "Set the signature list of USER-ID."
651 (unless (eq (car user-id) 'epg-user-id)
652 (signal 'wrong-type-argument (list 'epg-user-id-p user-id)))
653 (aset (cdr user-id) 2 signature-list))
655 (defun epg-context-result-for (context name)
656 "Return the result of CONTEXT associated with NAME."
657 (cdr (assq name (epg-context-result context))))
659 (defun epg-context-set-result-for (context name value)
660 "Set the result of CONTEXT associated with NAME to VALUE."
661 (let* ((result (epg-context-result context))
662 (entry (assq name result)))
665 (epg-context-set-result context (cons (cons name value) result)))))
667 (defun epg-signature-to-string (signature)
668 "Convert SIGNATURE to a human readable string."
669 (let ((user-id (cdr (assoc (epg-signature-key-id signature)
670 epg-user-id-alist))))
672 (cond ((eq (epg-signature-status signature) 'good)
673 "Good signature from ")
674 ((eq (epg-signature-status signature) 'bad)
675 "Bad signature from ")
676 ((eq (epg-signature-status signature) 'expired)
677 "Expired signature from ")
678 ((eq (epg-signature-status signature) 'expired-key)
679 "Signature made by expired key ")
680 ((eq (epg-signature-status signature) 'revoked-key)
681 "Signature made by revoked key ")
682 ((eq (epg-signature-status signature) 'no-pubkey)
683 "No public key for "))
684 (epg-signature-key-id signature)
687 (concat (if (stringp user-id)
689 (epg-decode-dn user-id))
692 (if (epg-signature-validity signature)
693 (format "(trust %s)" (epg-signature-validity signature))
696 (defun epg-verify-result-to-string (verify-result)
697 "Convert VERIFY-RESULT to a human readable string."
698 (mapconcat #'epg-signature-to-string verify-result "\n"))
700 (defun epg-new-signature-to-string (new-signature)
701 "Convert NEW-SIGNATURE to a human readable string."
703 (cond ((eq (epg-new-signature-type new-signature) 'detached)
704 "Detached signature ")
705 ((eq (epg-new-signature-type new-signature) 'clear)
706 "Clear text signature ")
709 (cdr (assq (epg-new-signature-pubkey-algorithm new-signature)
710 epg-pubkey-algorithm-alist))
712 (cdr (assq (epg-new-signature-digest-algorithm new-signature)
713 epg-digest-algorithm-alist))
715 (format "%02X " (epg-new-signature-class new-signature))
716 (epg-new-signature-fingerprint new-signature)))
718 (defun epg-start (context args)
719 "Start `epg-gpg-program' in a subprocess with given ARGS."
720 (if (and (epg-context-process context)
721 (eq (process-status (epg-context-process context)) 'run))
722 (error "%s is already running in this context"
723 (if (eq (epg-context-protocol context) 'CMS)
726 (let* ((args (append (list "--no-tty"
729 (unless (eq (epg-context-protocol context) 'CMS)
730 (list "--command-fd" "0"))
731 (if (epg-context-armor context) '("--armor"))
732 (if (epg-context-textmode context) '("--textmode"))
733 (if (epg-context-output-file context)
734 (list "--output" (epg-context-output-file context)))
736 (coding-system-for-write 'binary)
737 process-connection-type
738 (orig-mode (default-file-modes))
739 (buffer (generate-new-buffer " *epg*"))
743 (unless epg-debug-buffer
744 (setq epg-debug-buffer (generate-new-buffer " *epg-debug*")))
745 (set-buffer epg-debug-buffer)
746 (goto-char (point-max))
747 (insert (format "%s %s\n"
748 (if (eq (epg-context-protocol context) 'CMS)
751 (mapconcat #'identity args " ")))))
752 (with-current-buffer buffer
753 (make-local-variable 'epg-read-point)
754 (setq epg-read-point (point-min))
755 (make-local-variable 'epg-pending-status-list)
756 (setq epg-pending-status-list nil)
757 (make-local-variable 'epg-key-id)
758 (setq epg-key-id nil)
759 (make-local-variable 'epg-context)
760 (setq epg-context context))
763 (set-default-file-modes 448)
765 (apply #'start-process "epg" buffer
766 (if (eq (epg-context-protocol context) 'CMS)
770 (set-default-file-modes orig-mode))
771 (set-process-filter process #'epg-process-filter)
772 (epg-context-set-process context process)))
774 (defun epg-process-filter (process input)
777 (unless epg-debug-buffer
778 (setq epg-debug-buffer (generate-new-buffer " *epg-debug*")))
779 (set-buffer epg-debug-buffer)
780 (goto-char (point-max))
782 (if (buffer-live-p (process-buffer process))
784 (set-buffer (process-buffer process))
785 (goto-char (point-max))
787 (goto-char epg-read-point)
789 (while (looking-at ".*\n") ;the input line finished
791 (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\) ?\\(.*\\)")
792 (let* ((status (match-string 1))
793 (string (match-string 2))
794 (symbol (intern-soft (concat "epg-status-" status))))
795 (if (member status epg-pending-status-list)
796 (setq epg-pending-status-list nil))
799 (funcall symbol process string)))))
801 (setq epg-read-point (point)))))
803 (defun epg-read-output (context)
804 "Read the output file CONTEXT and return the content as a string."
806 (if (fboundp 'set-buffer-multibyte)
807 (set-buffer-multibyte nil))
808 (if (file-exists-p (epg-context-output-file context))
809 (let ((coding-system-for-read 'binary))
810 (insert-file-contents (epg-context-output-file context))
813 (defun epg-wait-for-status (context status-list)
814 "Wait until one of elements in STATUS-LIST arrives."
815 (with-current-buffer (process-buffer (epg-context-process context))
816 (setq epg-pending-status-list status-list)
817 (while (and (eq (process-status (epg-context-process context)) 'run)
818 epg-pending-status-list)
819 (accept-process-output (epg-context-process context) 0 1))))
821 (defun epg-wait-for-completion (context)
822 "Wait until the `epg-gpg-program' process completes."
823 (while (eq (process-status (epg-context-process context)) 'run)
824 (accept-process-output (epg-context-process context) 0 1)))
826 (defun epg-reset (context)
828 (if (and (epg-context-process context)
829 (buffer-live-p (process-buffer (epg-context-process context))))
830 (kill-buffer (process-buffer (epg-context-process context))))
831 (epg-context-set-process context nil))
833 (defun epg-delete-output-file (context)
834 "Delete the output file of CONTEXT."
835 (if (and (epg-context-output-file context)
836 (file-exists-p (epg-context-output-file context)))
837 (delete-file (epg-context-output-file context))))
839 (defun epg-status-USERID_HINT (process string)
840 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
841 (let* ((key-id (match-string 1 string))
842 (user-id (match-string 2 string))
843 (entry (assoc key-id epg-user-id-alist)))
845 (setcdr entry user-id)
846 (setq epg-user-id-alist (cons (cons key-id user-id)
847 epg-user-id-alist))))))
849 (defun epg-status-NEED_PASSPHRASE (process string)
850 (if (string-match "\\`\\([^ ]+\\)" string)
851 (setq epg-key-id (match-string 1 string))))
853 (defun epg-status-NEED_PASSPHRASE_SYM (process string)
854 (setq epg-key-id 'SYM))
856 (defun epg-status-NEED_PASSPHRASE_PIN (process string)
857 (setq epg-key-id 'PIN))
859 (defun epg-status-GET_HIDDEN (process string)
861 (string-match "\\`passphrase\\." string))
864 passphrase-with-new-line)
870 (if (consp (epg-context-passphrase-callback
872 (car (epg-context-passphrase-callback
874 (epg-context-passphrase-callback epg-context))
877 (if (consp (epg-context-passphrase-callback
879 (cdr (epg-context-passphrase-callback
882 (setq passphrase-with-new-line (concat passphrase "\n"))
883 (fillarray passphrase 0)
884 (setq passphrase nil)
885 (process-send-string process passphrase-with-new-line)))
887 (epg-context-set-result-for
890 (epg-context-result-for epg-context 'error)))
891 (delete-process process)))
893 (fillarray passphrase 0))
894 (if passphrase-with-new-line
895 (fillarray passphrase-with-new-line 0))))))
897 (defun epg-status-GET_BOOL (process string)
898 (let ((entry (assoc string epg-prompt-alist))
901 (if (y-or-n-p (if entry (cdr entry) (concat string "? ")))
902 (process-send-string process "y\n")
903 (process-send-string process "n\n"))
905 (epg-context-set-result-for
908 (epg-context-result-for epg-context 'error)))
909 (delete-process process)))))
911 (defun epg-status-GET_LINE (process string)
912 (let ((entry (assoc string epg-prompt-alist))
917 (concat (read-string (if entry (cdr entry) (concat string ": ")))
920 (epg-context-set-result-for
923 (epg-context-result-for epg-context 'error)))
924 (delete-process process)))))
926 (defun epg-status-*SIG (status string)
927 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
928 (let* ((key-id (match-string 1 string))
929 (user-id (match-string 2 string))
930 (entry (assoc key-id epg-user-id-alist)))
931 (epg-context-set-result-for
934 (cons (epg-make-signature status key-id)
935 (epg-context-result-for epg-context 'verify)))
936 (if (eq (epg-context-protocol epg-context) 'CMS)
938 (setq user-id (epg-dn-from-string user-id))
941 (setcdr entry user-id)
942 (setq epg-user-id-alist
943 (cons (cons key-id user-id) epg-user-id-alist))))
944 (epg-context-set-result-for
947 (cons (epg-make-signature status)
948 (epg-context-result-for epg-context 'verify)))))
950 (defun epg-status-GOODSIG (process string)
951 (epg-status-*SIG 'good string))
953 (defun epg-status-EXPSIG (process string)
954 (epg-status-*SIG 'expired string))
956 (defun epg-status-EXPKEYSIG (process string)
957 (epg-status-*SIG 'expired-key string))
959 (defun epg-status-REVKEYSIG (process string)
960 (epg-status-*SIG 'revoked-key string))
962 (defun epg-status-BADSIG (process string)
963 (epg-status-*SIG 'bad string))
965 (defun epg-status-NO_PUBKEY (process string)
966 (epg-context-set-result-for
969 (cons (epg-make-signature 'no-pubkey string)
970 (epg-context-result-for epg-context 'verify))))
972 (defun epg-status-ERRSIG (process string)
973 (let ((signatures (car (epg-context-result-for epg-context 'verify))))
975 (setq signatures (list (epg-make-signature 'error)))
976 (epg-context-set-result-for epg-context 'verify signatures))
977 (when (and (not (eq (epg-signature-status (car signatures)) 'good))
978 (string-match "\\`\\([^ ]+\\) \\([0-9]+\\) \\([0-9]+\\) \
979 \\([0-9A-Fa-f][0-9A-Fa-f]\\) \\([^ ]+\\) \\([0-9]+\\)"
981 (epg-signature-set-key-id
983 (match-string 1 string))
984 (epg-signature-set-pubkey-algorithm
986 (string-to-number (match-string 2 string)))
987 (epg-signature-set-digest-algorithm
989 (string-to-number (match-string 3 string)))
990 (epg-signature-set-class
992 (string-to-number (match-string 4 string) 16))
993 (epg-signature-set-creation-time
995 (match-string 5 string)))))
997 (defun epg-status-VALIDSIG (process string)
998 (let ((signature (car (epg-context-result-for epg-context 'verify))))
1000 (eq (epg-signature-status signature) 'good)
1001 (string-match "\\`\\([^ ]+\\) [^ ]+ \\([^ ]+\\) \\([^ ]+\\) \
1002 \\([0-9]+\\) [^ ]+ \\([0-9]+\\) \\([0-9]+\\) \\([0-9A-Fa-f][0-9A-Fa-f]\\) \
1005 (epg-signature-set-fingerprint
1007 (match-string 1 string))
1008 (epg-signature-set-creation-time
1010 (match-string 2 string))
1011 (epg-signature-set-expiration-time
1013 (match-string 3 string))
1014 (epg-signature-set-version
1016 (string-to-number (match-string 4 string)))
1017 (epg-signature-set-pubkey-algorithm
1019 (string-to-number (match-string 5 string)))
1020 (epg-signature-set-digest-algorithm
1022 (string-to-number (match-string 6 string)))
1023 (epg-signature-set-class
1025 (string-to-number (match-string 7 string) 16)))))
1027 (defun epg-status-TRUST_UNDEFINED (process string)
1028 (let ((signature (car (epg-context-result-for epg-context 'verify))))
1030 (eq (epg-signature-status signature) 'good))
1031 (epg-signature-set-validity signature 'undefined))))
1033 (defun epg-status-TRUST_NEVER (process string)
1034 (let ((signature (car (epg-context-result-for epg-context 'verify))))
1036 (eq (epg-signature-status signature) 'good))
1037 (epg-signature-set-validity signature 'never))))
1039 (defun epg-status-TRUST_MARGINAL (process string)
1040 (let ((signature (car (epg-context-result-for epg-context 'verify))))
1042 (eq (epg-signature-status signature) 'marginal))
1043 (epg-signature-set-validity signature 'marginal))))
1045 (defun epg-status-TRUST_FULLY (process string)
1046 (let ((signature (car (epg-context-result-for epg-context 'verify))))
1048 (eq (epg-signature-status signature) 'good))
1049 (epg-signature-set-validity signature 'full))))
1051 (defun epg-status-TRUST_ULTIMATE (process string)
1052 (let ((signature (car (epg-context-result-for epg-context 'verify))))
1054 (eq (epg-signature-status signature) 'good))
1055 (epg-signature-set-validity signature 'ultimate))))
1057 (defun epg-status-PROGRESS (process string)
1058 (if (string-match "\\`\\([^ ]+\\) \\([^ ]\\) \\([0-9]+\\) \\([0-9]+\\)"
1060 (funcall (if (consp (epg-context-progress-callback epg-context))
1061 (car (epg-context-progress-callback epg-context))
1062 (epg-context-progress-callback epg-context))
1064 (match-string 1 string)
1065 (match-string 2 string)
1066 (string-to-number (match-string 3 string))
1067 (string-to-number (match-string 4 string))
1068 (if (consp (epg-context-progress-callback epg-context))
1069 (cdr (epg-context-progress-callback epg-context))))))
1071 (defun epg-status-DECRYPTION_FAILED (process string)
1072 (epg-context-set-result-for
1074 (cons '(decryption-failed)
1075 (epg-context-result-for epg-context 'error))))
1077 (defun epg-status-NODATA (process string)
1078 (epg-context-set-result-for
1080 (cons (list 'no-data (cons 'reason (string-to-number string)))
1081 (epg-context-result-for epg-context 'error))))
1083 (defun epg-status-UNEXPECTED (process string)
1084 (epg-context-set-result-for
1086 (cons (list 'unexpected (cons 'reason (string-to-number string)))
1087 (epg-context-result-for epg-context 'error))))
1089 (defun epg-status-KEYEXPIRED (process string)
1090 (epg-context-set-result-for
1092 (cons (list 'key-expired (cons 'expiration-time string))
1093 (epg-context-result-for epg-context 'error))))
1095 (defun epg-status-KEYREVOKED (process string)
1096 (epg-context-set-result-for
1098 (cons '(key-revoked)
1099 (epg-context-result-for epg-context 'error))))
1101 (defun epg-status-BADARMOR (process string)
1102 (epg-context-set-result-for
1105 (epg-context-result-for epg-context 'error))))
1107 (defun epg-status-INV_RECP (process string)
1108 (if (string-match "\\`\\([0-9]+\\) \\(.*\\)" string)
1109 (epg-context-set-result-for
1111 (cons (list 'invalid-recipient
1113 (string-to-number (match-string 1 string)))
1114 (cons 'requested-recipient
1115 (match-string 2 string)))
1116 (epg-context-result-for epg-context 'error)))))
1118 (defun epg-status-NO_RECP (process string)
1119 (epg-context-set-result-for
1121 (cons '(no-recipients)
1122 (epg-context-result-for epg-context 'error))))
1124 (defun epg-status-DELETE_PROBLEM (process string)
1125 (if (string-match "\\`\\([0-9]+\\)" string)
1126 (epg-context-set-result-for
1128 (cons (list 'delete-problem
1129 (cons 'reason (string-to-number (match-string 1 string))))
1130 (epg-context-result-for epg-context 'error)))))
1132 (defun epg-status-SIG_CREATED (process string)
1133 (if (string-match "\\`\\([DCS]\\) \\([0-9]+\\) \\([0-9]+\\) \
1134 \\([0-9A-Fa-F][0-9A-Fa-F]\\) \\(.*\\) " string)
1135 (epg-context-set-result-for
1137 (cons (epg-make-new-signature
1138 (cdr (assq (aref (match-string 1 string) 0)
1139 epg-new-signature-type-alist))
1140 (string-to-number (match-string 2 string))
1141 (string-to-number (match-string 3 string))
1142 (string-to-number (match-string 4 string) 16)
1143 (match-string 5 string)
1144 (substring string (match-end 0)))
1145 (epg-context-result-for epg-context 'sign)))))
1147 (defun epg-status-KEY_CREATED (process string)
1148 (if (string-match "\\`\\([BPS]\\) \\([^ ]+\\)" string)
1149 (epg-context-set-result-for
1150 epg-context 'generate-key
1151 (cons (list (cons 'type (string-to-char (match-string 1 string)))
1152 (cons 'fingerprint (match-string 2 string)))
1153 (epg-context-result-for epg-context 'generate-key)))))
1155 (defun epg-status-KEY_NOT_CREATED (process string)
1156 (epg-context-set-result-for
1158 (cons '(key-not-created)
1159 (epg-context-result-for epg-context 'error))))
1161 (defun epg-status-IMPORTED (process string)
1162 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
1163 (let* ((key-id (match-string 1 string))
1164 (user-id (match-string 2 string))
1165 (entry (assoc key-id epg-user-id-alist)))
1167 (setcdr entry user-id)
1168 (setq epg-user-id-alist (cons (cons key-id user-id)
1169 epg-user-id-alist)))
1170 (epg-context-set-result-for
1172 (cons (list (cons 'key-id key-id)
1173 (cons 'user-id user-id))
1174 (epg-context-result-for epg-context 'import))))))
1176 (defun epg-status-IMPORT_OK (process string)
1177 (let ((result (epg-context-result-for epg-context 'import)))
1179 (string-match "\\`\\([0-9]+\\)\\( \\(.+\\)\\)?" string))
1181 (append (list (cons 'reason
1183 (match-string 1 string))))
1184 (if (match-beginning 2)
1185 (list (cons 'fingerprint
1186 (match-string 3 string))))
1189 (defun epg-status-IMPORT_PROBLEM (process string)
1190 (if (string-match "\\`\\([0-9]+\\)\\( \\(.+\\)\\)?" string)
1191 (epg-context-set-result-for
1193 (cons (cons 'import-problem
1194 (append (list (cons 'reason
1196 (match-string 1 string))))
1197 (if (match-beginning 2)
1198 (list (cons 'fingerprint
1199 (match-string 3 string))))))
1200 (epg-context-result-for epg-context 'error)))))
1202 (defun epg-passphrase-callback-function (context key-id handback)
1204 (if (eq key-id 'SYM)
1205 "Passphrase for symmetric encryption: "
1206 (if (eq key-id 'PIN)
1207 "Passphrase for PIN: "
1208 (let ((entry (assoc key-id epg-user-id-alist)))
1210 (format "Passphrase for %s %s: " key-id (cdr entry))
1211 (format "Passphrase for %s: " key-id)))))))
1213 (defun epg-progress-callback-function (context what char current total
1215 (message "%s: %d%%/%d%%" what current total))
1217 (defun epg-configuration ()
1218 "Return a list of internal configuration parameters of `epg-gpg-program'."
1221 (apply #'call-process epg-gpg-program nil (list t nil) nil
1222 '("--with-colons" "--list-config"))
1223 (goto-char (point-min))
1224 (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t)
1225 (setq type (intern (match-string 1))
1226 config (cons (cons type
1228 '(pubkey cipher digest compress))
1229 (mapcar #'string-to-number
1230 (delete "" (split-string
1237 (defun epg-list-keys-1 (context name mode)
1238 (let ((args (append (list "--with-colons" "--no-greeting" "--batch"
1239 "--with-fingerprint"
1240 "--with-fingerprint"
1241 (if (memq mode '(t secret))
1242 "--list-secret-keys"
1246 (unless (eq (epg-context-protocol context) 'CMS)
1247 '("--fixed-list-mode"))
1248 (if name (list name))))
1249 keys string field index)
1251 (apply #'call-process
1252 (if (eq (epg-context-protocol context) 'CMS)
1255 nil (list t nil) nil args)
1256 (goto-char (point-min))
1257 (while (re-search-forward "^[a-z][a-z][a-z]:.*" nil t)
1258 (setq keys (cons (make-vector 15 nil) keys)
1259 string (match-string 0)
1263 (string-match "\\([^:]+\\)?:" string index))
1264 (setq index (match-end 0))
1265 (aset (car keys) field (match-string 1 string))
1266 (setq field (1+ field))))
1269 (defun epg-make-sub-key-1 (line)
1272 (cdr (assq (string-to-char (aref line 1)) epg-key-validity-alist)))
1274 (mapcar (lambda (char) (cdr (assq char epg-key-capablity-alist)))
1276 (member (aref line 0) '("sec" "ssb"))
1277 (string-to-number (aref line 3))
1278 (string-to-number (aref line 2))
1283 (defun epg-list-keys-postprocess-one-key (key)
1284 (let (key-id user-id-string entry)
1285 (epg-key-set-sub-key-list
1287 (nreverse (epg-key-sub-key-list key)))
1288 (epg-key-set-user-id-list
1290 (nreverse (epg-key-user-id-list key)))
1292 (epg-sub-key-id (car (epg-key-sub-key-list key)))
1294 (epg-user-id-string (car (epg-key-user-id-list key)))
1295 entry (assoc key-id epg-user-id-alist))
1297 (setcdr entry user-id-string)
1298 (setq epg-user-id-alist (cons (cons key-id user-id-string)
1299 epg-user-id-alist)))))
1301 (defun epg-list-keys (context &optional name mode)
1302 "Return a list of epg-key objects matched with NAME.
1303 If MODE is nil, only public keyring should be searched.
1304 If MODE is t or 'secret, only secret keyring should be searched.
1305 Otherwise, only public keyring should be searched and the key
1306 signatures should be included."
1307 (let ((lines (epg-list-keys-1 context name mode))
1311 ((member (aref (car lines) 0) '("pub" "sec" "crt" "crs"))
1313 (epg-list-keys-postprocess-one-key (car keys)))
1314 (setq cert (member (aref (car lines) 0) '("crt" "crs"))
1315 keys (cons (epg-make-key
1316 (if (aref (car lines) 8)
1317 (cdr (assq (string-to-char (aref (car lines) 8))
1318 epg-key-validity-alist))))
1320 (epg-key-set-sub-key-list
1322 (cons (epg-make-sub-key-1 (car lines))
1323 (epg-key-sub-key-list (car keys)))))
1324 ((member (aref (car lines) 0) '("sub" "ssb"))
1325 (epg-key-set-sub-key-list
1327 (cons (epg-make-sub-key-1 (car lines))
1328 (epg-key-sub-key-list (car keys)))))
1329 ((equal (aref (car lines) 0) "uid")
1330 (epg-key-set-user-id-list
1332 (cons (epg-make-user-id
1333 (if (aref (car lines) 1)
1334 (cdr (assq (string-to-char (aref (car lines) 1))
1335 epg-key-validity-alist)))
1338 (epg-dn-from-string (aref (car lines) 9))
1339 (error (aref (car lines) 9)))
1340 (aref (car lines) 9)))
1341 (epg-key-user-id-list (car keys)))))
1342 ((equal (aref (car lines) 0) "fpr")
1343 (epg-sub-key-set-fingerprint (car (epg-key-sub-key-list (car keys)))
1344 (aref (car lines) 9))))
1345 (setq lines (cdr lines)))
1347 (epg-list-keys-postprocess-one-key (car keys)))
1350 (if (fboundp 'make-temp-file)
1351 (defalias 'epg-make-temp-file 'make-temp-file)
1352 (defvar temporary-file-directory)
1353 ;; stolen from poe.el.
1354 (defun epg-make-temp-file (prefix)
1355 "Create a temporary file.
1356 The returned file name (created by appending some random characters at the end
1357 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1358 is guaranteed to point to a newly created empty file.
1359 You can then use `write-region' to write new data into the file."
1360 (let (tempdir tempfile)
1361 (setq prefix (expand-file-name prefix
1362 (if (featurep 'xemacs)
1364 temporary-file-directory)))
1367 ;; First, create a temporary directory.
1368 (while (condition-case ()
1370 (setq tempdir (make-temp-name
1372 (file-name-directory prefix)
1374 ;; return nil or signal an error.
1375 (make-directory tempdir))
1377 (file-already-exists t)))
1378 (set-file-modes tempdir 448)
1379 ;; Second, create a temporary file in the tempdir.
1380 ;; There *is* a race condition between `make-temp-name'
1381 ;; and `write-region', but we don't care it since we are
1382 ;; in a private directory now.
1383 (setq tempfile (make-temp-name (concat tempdir "/EMU")))
1384 (write-region "" nil tempfile nil 'silent)
1385 (set-file-modes tempfile 384)
1386 ;; Finally, make a hard-link from the tempfile.
1387 (while (condition-case ()
1389 (setq file (make-temp-name prefix))
1390 ;; return nil or signal an error.
1391 (add-name-to-file tempfile file))
1393 (file-already-exists t)))
1395 ;; Cleanup the tempfile.
1397 (file-exists-p tempfile)
1398 (delete-file tempfile))
1399 ;; Cleanup the tempdir.
1401 (file-directory-p tempdir)
1402 (delete-directory tempdir))))))
1405 (defun epg-cancel (context)
1406 (if (buffer-live-p (process-buffer (epg-context-process context)))
1408 (set-buffer (process-buffer (epg-context-process context)))
1409 (epg-context-set-result-for
1412 (epg-context-result-for epg-context 'error)))))
1413 (if (eq (process-status (epg-context-process context)) 'run)
1414 (delete-process (epg-context-process context))))
1417 (defun epg-start-decrypt (context cipher)
1418 "Initiate a decrypt operation on CIPHER.
1419 CIPHER is a data object.
1421 If you use this function, you will need to wait for the completion of
1422 `epg-gpg-program' by using `epg-wait-for-completion' and call
1423 `epg-reset' to clear a temporaly output file.
1424 If you are unsure, use synchronous version of this function
1425 `epg-decrypt-file' or `epg-decrypt-string' instead."
1426 (unless (epg-data-file cipher)
1427 (error "Not a file"))
1428 (epg-context-set-result context nil)
1429 (epg-start context (list "--decrypt" (epg-data-file cipher)))
1430 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
1431 (unless (eq (epg-context-protocol context) 'CMS)
1432 (epg-wait-for-status context '("BEGIN_DECRYPTION"))))
1435 (defun epg-decrypt-file (context cipher plain)
1436 "Decrypt a file CIPHER and store the result to a file PLAIN.
1437 If PLAIN is nil, it returns the result as a string."
1441 (epg-context-set-output-file context plain)
1442 (epg-context-set-output-file context
1443 (epg-make-temp-file "epg-output")))
1444 (epg-start-decrypt context (epg-make-data-from-file cipher))
1445 (epg-wait-for-completion context)
1446 (if (epg-context-result-for context 'error)
1447 (error "Decrypt failed: %S"
1448 (epg-context-result-for context 'error)))
1450 (epg-read-output context)))
1452 (epg-delete-output-file context))
1453 (epg-reset context)))
1456 (defun epg-decrypt-string (context cipher)
1457 "Decrypt a string CIPHER and return the plain text."
1458 (let ((input-file (epg-make-temp-file "epg-input"))
1459 (coding-system-for-write 'binary))
1462 (write-region cipher nil input-file nil 'quiet)
1463 (epg-context-set-output-file context
1464 (epg-make-temp-file "epg-output"))
1465 (epg-start-decrypt context (epg-make-data-from-file input-file))
1466 (epg-wait-for-completion context)
1467 (if (epg-context-result-for context 'error)
1468 (error "Decrypt failed: %S"
1469 (epg-context-result-for context 'error)))
1470 (epg-read-output context))
1471 (epg-delete-output-file context)
1472 (if (file-exists-p input-file)
1473 (delete-file input-file))
1474 (epg-reset context))))
1477 (defun epg-start-verify (context signature &optional signed-text)
1478 "Initiate a verify operation on SIGNATURE.
1479 SIGNATURE and SIGNED-TEXT are a data object if they are specified.
1481 For a detached signature, both SIGNATURE and SIGNED-TEXT should be set.
1482 For a normal or a clear text signature, SIGNED-TEXT should be nil.
1484 If you use this function, you will need to wait for the completion of
1485 `epg-gpg-program' by using `epg-wait-for-completion' and call
1486 `epg-reset' to clear a temporaly output file.
1487 If you are unsure, use synchronous version of this function
1488 `epg-verify-file' or `epg-verify-string' instead."
1489 (epg-context-set-result context nil)
1491 ;; Detached signature.
1492 (if (epg-data-file signed-text)
1493 (epg-start context (list "--verify" (epg-data-file signature)
1494 (epg-data-file signed-text)))
1495 (epg-start context (list "--verify" (epg-data-file signature) "-"))
1496 (if (eq (process-status (epg-context-process context)) 'run)
1497 (process-send-string (epg-context-process context)
1498 (epg-data-string signed-text)))
1499 (if (eq (process-status (epg-context-process context)) 'run)
1500 (process-send-eof (epg-context-process context))))
1501 ;; Normal (or cleartext) signature.
1502 (if (epg-data-file signature)
1503 (epg-start context (list "--verify" (epg-data-file signature)))
1504 (epg-start context (list "--verify"))
1505 (if (eq (process-status (epg-context-process context)) 'run)
1506 (process-send-string (epg-context-process context)
1507 (epg-data-string signature)))
1508 (if (eq (process-status (epg-context-process context)) 'run)
1509 (process-send-eof (epg-context-process context))))))
1512 (defun epg-verify-file (context signature &optional signed-text plain)
1513 "Verify a file SIGNATURE.
1514 SIGNED-TEXT and PLAIN are also a file if they are specified.
1516 For a detached signature, both SIGNATURE and SIGNED-TEXT should be string.
1517 For a normal or a clear text signature, SIGNED-TEXT should be nil."
1521 (epg-context-set-output-file context plain)
1522 (epg-context-set-output-file context
1523 (epg-make-temp-file "epg-output")))
1525 (epg-start-verify context
1526 (epg-make-data-from-file signature)
1527 (epg-make-data-from-file signed-text))
1528 (epg-start-verify context
1529 (epg-make-data-from-file signature)))
1530 (epg-wait-for-completion context)
1531 ; (if (epg-context-result-for context 'error)
1532 ; (error "Verify failed: %S"
1533 ; (epg-context-result-for context 'error)))
1535 (epg-read-output context)))
1537 (epg-delete-output-file context))
1538 (epg-reset context)))
1541 (defun epg-verify-string (context signature &optional signed-text)
1542 "Verify a string SIGNATURE.
1543 SIGNED-TEXT is a string if it is specified.
1545 For a detached signature, both SIGNATURE and SIGNED-TEXT should be string.
1546 For a normal or a clear text signature, SIGNED-TEXT should be nil."
1547 (let ((coding-system-for-write 'binary)
1551 (epg-context-set-output-file context
1552 (epg-make-temp-file "epg-output"))
1555 (setq input-file (epg-make-temp-file "epg-signature"))
1556 (write-region signature nil input-file nil 'quiet)
1557 (epg-start-verify context
1558 (epg-make-data-from-file input-file)
1559 (epg-make-data-from-string signed-text)))
1560 (epg-start-verify context (epg-make-data-from-string signature)))
1561 (epg-wait-for-completion context)
1562 ; (if (epg-context-result-for context 'error)
1563 ; (error "Verify failed: %S"
1564 ; (epg-context-result-for context 'error)))
1565 (epg-read-output context))
1566 (epg-delete-output-file context)
1568 (file-exists-p input-file))
1569 (delete-file input-file))
1570 (epg-reset context))))
1573 (defun epg-start-sign (context plain &optional mode)
1574 "Initiate a sign operation on PLAIN.
1575 PLAIN is a data object.
1577 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
1578 If it is nil or 'normal, it makes a normal signature.
1579 Otherwise, it makes a clear text signature.
1581 If you use this function, you will need to wait for the completion of
1582 `epg-gpg-program' by using `epg-wait-for-completion' and call
1583 `epg-reset' to clear a temporaly output file.
1584 If you are unsure, use synchronous version of this function
1585 `epg-sign-file' or `epg-sign-string' instead."
1586 (epg-context-set-result context nil)
1588 (append (list (if (memq mode '(t detached))
1590 (if (memq mode '(nil normal))
1598 (car (epg-key-sub-key-list signer)))))
1599 (epg-context-signers context)))
1600 (if (epg-data-file plain)
1601 (list (epg-data-file plain)))))
1602 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
1603 (unless (eq (epg-context-protocol context) 'CMS)
1604 (epg-wait-for-status context '("BEGIN_SIGNING")))
1605 (when (epg-data-string plain)
1606 (if (eq (process-status (epg-context-process context)) 'run)
1607 (process-send-string (epg-context-process context)
1608 (epg-data-string plain)))
1609 (if (eq (process-status (epg-context-process context)) 'run)
1610 (process-send-eof (epg-context-process context)))))
1613 (defun epg-sign-file (context plain signature &optional mode)
1614 "Sign a file PLAIN and store the result to a file SIGNATURE.
1615 If SIGNATURE is nil, it returns the result as a string.
1616 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
1617 If it is nil or 'normal, it makes a normal signature.
1618 Otherwise, it makes a clear text signature."
1622 (epg-context-set-output-file context signature)
1623 (epg-context-set-output-file context
1624 (epg-make-temp-file "epg-output")))
1625 (epg-start-sign context (epg-make-data-from-file plain) mode)
1626 (epg-wait-for-completion context)
1627 (unless (epg-context-result-for context 'sign)
1628 (if (epg-context-result-for context 'error)
1629 (error "Sign failed: %S"
1630 (epg-context-result-for context 'error))
1631 (error "Sign failed")))
1633 (epg-read-output context)))
1635 (epg-delete-output-file context))
1636 (epg-reset context)))
1639 (defun epg-sign-string (context plain &optional mode)
1640 "Sign a string PLAIN and return the output as string.
1641 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
1642 If it is nil or 'normal, it makes a normal signature.
1643 Otherwise, it makes a clear text signature."
1646 (epg-context-set-output-file context
1647 (epg-make-temp-file "epg-output"))
1648 (epg-start-sign context (epg-make-data-from-string plain) mode)
1649 (epg-wait-for-completion context)
1650 (unless (epg-context-result-for context 'sign)
1651 (if (epg-context-result-for context 'error)
1652 (error "Sign failed: %S"
1653 (epg-context-result-for context 'error))
1654 (error "Sign failed")))
1655 (epg-read-output context))
1656 (epg-delete-output-file context)
1657 (epg-reset context)))
1660 (defun epg-start-encrypt (context plain recipients
1661 &optional sign always-trust)
1662 "Initiate an encrypt operation on PLAIN.
1663 PLAIN is a data object.
1664 If RECIPIENTS is nil, it performs symmetric encryption.
1666 If you use this function, you will need to wait for the completion of
1667 `epg-gpg-program' by using `epg-wait-for-completion' and call
1668 `epg-reset' to clear a temporaly output file.
1669 If you are unsure, use synchronous version of this function
1670 `epg-encrypt-file' or `epg-encrypt-string' instead."
1671 (epg-context-set-result context nil)
1673 (append (if always-trust '("--always-trust"))
1674 (if recipients '("--encrypt") '("--symmetric"))
1678 (mapcar (lambda (signer)
1680 (epg-context-signers context)))))
1686 (car (epg-key-sub-key-list recipient)))))
1688 (if (epg-data-file plain)
1689 (list (epg-data-file plain)))))
1690 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
1691 (unless (eq (epg-context-protocol context) 'CMS)
1693 (epg-wait-for-status context '("BEGIN_SIGNING"))
1694 (epg-wait-for-status context '("BEGIN_ENCRYPTION"))))
1695 (when (epg-data-string plain)
1696 (if (eq (process-status (epg-context-process context)) 'run)
1697 (process-send-string (epg-context-process context)
1698 (epg-data-string plain)))
1699 (if (eq (process-status (epg-context-process context)) 'run)
1700 (process-send-eof (epg-context-process context)))))
1703 (defun epg-encrypt-file (context plain recipients
1704 cipher &optional sign always-trust)
1705 "Encrypt a file PLAIN and store the result to a file CIPHER.
1706 If CIPHER is nil, it returns the result as a string.
1707 If RECIPIENTS is nil, it performs symmetric encryption."
1711 (epg-context-set-output-file context cipher)
1712 (epg-context-set-output-file context
1713 (epg-make-temp-file "epg-output")))
1714 (epg-start-encrypt context (epg-make-data-from-file plain)
1715 recipients sign always-trust)
1716 (epg-wait-for-completion context)
1718 (not (epg-context-result-for context 'sign)))
1719 (if (epg-context-result-for context 'error)
1720 (error "Sign failed: %S"
1721 (epg-context-result-for context 'error))
1722 (error "Sign failed")))
1723 (if (epg-context-result-for context 'error)
1724 (error "Encrypt failed: %S"
1725 (epg-context-result-for context 'error)))
1727 (epg-read-output context)))
1729 (epg-delete-output-file context))
1730 (epg-reset context)))
1733 (defun epg-encrypt-string (context plain recipients
1734 &optional sign always-trust)
1735 "Encrypt a string PLAIN.
1736 If RECIPIENTS is nil, it performs symmetric encryption."
1739 (epg-context-set-output-file context
1740 (epg-make-temp-file "epg-output"))
1741 (epg-start-encrypt context (epg-make-data-from-string plain)
1742 recipients sign always-trust)
1743 (epg-wait-for-completion context)
1745 (not (epg-context-result-for context 'sign)))
1746 (if (epg-context-result-for context 'error)
1747 (error "Sign failed: %S"
1748 (epg-context-result-for context 'error))
1749 (error "Sign failed")))
1750 (if (epg-context-result-for context 'error)
1751 (error "Encrypt failed: %S"
1752 (epg-context-result-for context 'error)))
1753 (epg-read-output context))
1754 (epg-delete-output-file context)
1755 (epg-reset context)))
1758 (defun epg-start-export-keys (context keys)
1759 "Initiate an export keys operation.
1761 If you use this function, you will need to wait for the completion of
1762 `epg-gpg-program' by using `epg-wait-for-completion' and call
1763 `epg-reset' to clear a temporaly output file.
1764 If you are unsure, use synchronous version of this function
1765 `epg-export-keys-to-file' or `epg-export-keys-to-string' instead."
1766 (epg-context-set-result context nil)
1767 (epg-start context (cons "--export"
1771 (car (epg-key-sub-key-list key))))
1775 (defun epg-export-keys-to-file (context keys file)
1776 "Extract public KEYS."
1780 (epg-context-set-output-file context file)
1781 (epg-context-set-output-file context
1782 (epg-make-temp-file "epg-output")))
1783 (epg-start-export-keys context keys)
1784 (epg-wait-for-completion context)
1785 (if (epg-context-result-for context 'error)
1786 (error "Export keys failed: %S"
1787 (epg-context-result-for context 'error)))
1789 (epg-read-output context)))
1791 (epg-delete-output-file context))
1792 (epg-reset context)))
1795 (defun epg-export-keys-to-string (context keys)
1796 "Extract public KEYS and return them as a string."
1797 (epg-export-keys-to-file context keys nil))
1800 (defun epg-start-import-keys (context keys)
1801 "Initiate an import keys operation.
1802 KEYS is a data object.
1804 If you use this function, you will need to wait for the completion of
1805 `epg-gpg-program' by using `epg-wait-for-completion' and call
1806 `epg-reset' to clear a temporaly output file.
1807 If you are unsure, use synchronous version of this function
1808 `epg-import-keys-from-file' or `epg-import-keys-from-string' instead."
1809 (epg-context-set-result context nil)
1810 (epg-start context (list "--import" (epg-data-file keys)))
1811 (when (epg-data-string keys)
1812 (if (eq (process-status (epg-context-process context)) 'run)
1813 (process-send-string (epg-context-process context)
1814 (epg-data-string keys)))
1815 (if (eq (process-status (epg-context-process context)) 'run)
1816 (process-send-eof (epg-context-process context)))))
1818 (defun epg-import-keys-1 (context keys)
1821 (epg-start-import-keys context keys)
1822 (epg-wait-for-completion context)
1823 (if (epg-context-result-for context 'error)
1824 (error "Import keys failed: %S"
1825 (epg-context-result-for context 'error))))
1826 (epg-reset context)))
1829 (defun epg-import-keys-from-file (context keys)
1830 "Add keys from a file KEYS."
1831 (epg-import-keys-1 context (epg-make-data-from-file keys)))
1834 (defun epg-import-keys-from-string (context keys)
1835 "Add keys from a string KEYS."
1836 (epg-import-keys-1 context (epg-make-data-from-string keys)))
1839 (defun epg-start-receive-keys (context key-id-list)
1840 "Initiate a receive key operation.
1841 KEY-ID-LIST is a list of key IDs.
1843 If you use this function, you will need to wait for the completion of
1844 `epg-gpg-program' by using `epg-wait-for-completion' and call
1845 `epg-reset' to clear a temporaly output file.
1846 If you are unsure, use synchronous version of this function
1847 `epg-generate-key-from-file' or `epg-generate-key-from-string' instead."
1848 (epg-context-set-result context nil)
1849 (epg-start context (cons "--recv-keys" key-id-list)))
1852 (defun epg-receive-keys (context keys)
1853 "Add keys from server.
1854 KEYS is a list of key IDs"
1857 (epg-start-receive-keys context keys)
1858 (epg-wait-for-completion context)
1859 (if (epg-context-result-for context 'error)
1860 (error "Import keys failed: %S"
1861 (epg-context-result-for context 'error))))
1862 (epg-reset context)))
1865 (defalias 'epg-import-keys-from-server 'epg-receive-keys)
1868 (defun epg-start-delete-keys (context keys &optional allow-secret)
1869 "Initiate an delete keys operation.
1871 If you use this function, you will need to wait for the completion of
1872 `epg-gpg-program' by using `epg-wait-for-completion' and call
1873 `epg-reset' to clear a temporaly output file.
1874 If you are unsure, use synchronous version of this function
1875 `epg-delete-keys' instead."
1876 (epg-context-set-result context nil)
1877 (epg-start context (cons (if allow-secret
1878 "--delete-secret-key"
1883 (car (epg-key-sub-key-list key))))
1887 (defun epg-delete-keys (context keys &optional allow-secret)
1888 "Delete KEYS from the key ring."
1891 (epg-start-delete-keys context keys allow-secret)
1892 (epg-wait-for-completion context)
1893 (if (epg-context-result-for context 'error)
1894 (error "Delete keys failed: %S"
1895 (epg-context-result-for context 'error))))
1896 (epg-reset context)))
1899 (defun epg-start-sign-keys (context keys &optional local)
1900 "Initiate an sign keys operation.
1902 If you use this function, you will need to wait for the completion of
1903 `epg-gpg-program' by using `epg-wait-for-completion' and call
1904 `epg-reset' to clear a temporaly output file.
1905 If you are unsure, use synchronous version of this function
1906 `epg-sign-keys' instead."
1907 (epg-context-set-result context nil)
1908 (epg-start context (cons (if local
1914 (car (epg-key-sub-key-list key))))
1918 (defun epg-sign-keys (context keys &optional local)
1919 "Sign KEYS from the key ring."
1922 (epg-start-sign-keys context keys local)
1923 (epg-wait-for-completion context)
1924 (if (epg-context-result-for context 'error)
1925 (error "Sign keys failed: %S"
1926 (epg-context-result-for context 'error))))
1927 (epg-reset context)))
1930 (defun epg-start-generate-key (context parameters)
1931 "Initiate a key generation.
1932 PARAMETERS specifies parameters for the key.
1934 If you use this function, you will need to wait for the completion of
1935 `epg-gpg-program' by using `epg-wait-for-completion' and call
1936 `epg-reset' to clear a temporaly output file.
1937 If you are unsure, use synchronous version of this function
1938 `epg-generate-key-from-file' or `epg-generate-key-from-string' instead."
1939 (epg-context-set-result context nil)
1940 (if (epg-data-file parameters)
1941 (epg-start context (list "--batch" "--genkey"
1942 (epg-data-file parameters)))
1943 (epg-start context '("--batch" "--genkey"))
1944 (if (eq (process-status (epg-context-process context)) 'run)
1945 (process-send-string (epg-context-process context)
1946 (epg-data-string parameters)))
1947 (if (eq (process-status (epg-context-process context)) 'run)
1948 (process-send-eof (epg-context-process context)))))
1951 (defun epg-generate-key-from-file (context parameters)
1952 "Generate a new key pair.
1953 PARAMETERS is a file which tells how to create the key."
1956 (epg-start-generate-key context (epg-make-data-from-file parameters))
1957 (epg-wait-for-completion context)
1958 (if (epg-context-result-for context 'error)
1959 (error "Generate key failed: %S"
1960 (epg-context-result-for context 'error))))
1961 (epg-reset context)))
1964 (defun epg-generate-key-from-string (context parameters)
1965 "Generate a new key pair.
1966 PARAMETERS is a string which tells how to create the key."
1969 (epg-start-generate-key context (epg-make-data-from-string parameters))
1970 (epg-wait-for-completion context)
1971 (if (epg-context-result-for context 'error)
1972 (error "Generate key failed: %S"
1973 (epg-context-result-for context 'error))))
1974 (epg-reset context)))
1976 (defun epg-decode-hexstring (string)
1978 (while (eq index (string-match "[0-9A-Fa-f][0-9A-Fa-f]" string index))
1979 (setq string (replace-match "\\x\\&" t nil string)
1981 (car (read-from-string (concat "\"" string "\"")))))
1983 (defun epg-decode-quotedstring (string)
1985 (while (string-match "\\\\\\(\\([,=+<>#;\\\"]\\)\\|\
1986 \\([0-9A-Fa-f][0-9A-Fa-f]\\)\\|\\(.\\)\\)"
1988 (if (match-beginning 2)
1989 (setq string (replace-match "\\2" t nil string)
1991 (if (match-beginning 3)
1992 (setq string (replace-match "\\x\\3" t nil string)
1994 (setq string (replace-match "\\\\\\\\\\4" t nil string)
1995 index (+ index 3)))))
1996 (car (read-from-string (concat "\"" string "\"")))))
1998 (defun epg-dn-from-string (string)
1999 "Parse STRING as LADPv3 Distinguished Names (RFC2253).
2000 The return value is an alist mapping from types to values."
2002 (length (length string))
2003 alist type value group)
2004 (while (< index length)
2005 (if (eq index (string-match "[ \t\n\r]*" string index))
2006 (setq index (match-end 0)))
2007 (if (eq index (string-match
2008 "\\([0-9]+\\(\\.[0-9]+\\)*\\)\[ \t\n\r]*=[ \t\n\r]*"
2010 (setq type (match-string 1 string)
2011 index (match-end 0))
2012 (if (eq index (string-match "\\([0-9A-Za-z]+\\)[ \t\n\r]*=[ \t\n\r]*"
2014 (setq type (match-string 1 string)
2015 index (match-end 0))))
2017 (error "Invalid type"))
2018 (if (eq index (string-match
2019 "\\([^,=+<>#;\\\"]\\|\\\\.\\)+"
2021 (setq index (match-end 0)
2022 value (epg-decode-quotedstring (match-string 0 string)))
2023 (if (eq index (string-match "#\\([0-9A-Fa-f]+\\)" string index))
2024 (setq index (match-end 0)
2025 value (epg-decode-hexstring (match-string 1 string)))
2026 (if (eq index (string-match "\"\\([^\\\"]\\|\\\\.\\)*\""
2028 (setq index (match-end 0)
2029 value (epg-decode-quotedstring (match-string 0 string))))))
2031 (if (stringp (car (car alist)))
2032 (setcar alist (list (cons type value) (car alist)))
2033 (setcar alist (cons (cons type value) (car alist))))
2034 (if (consp (car (car alist)))
2035 (setcar alist (nreverse (car alist))))
2036 (setq alist (cons (cons type value) alist)
2039 (if (eq index (string-match "[ \t\n\r]*\\([,;+]\\)" string index))
2040 (setq index (match-end 0)
2041 group (eq (aref string (match-beginning 1)) ?+))))
2044 (defun epg-decode-dn (alist)
2045 "Convert ALIST returned by `epg-dn-from-string' to a human readable form.
2046 Type names are resolved using `epg-dn-type-alist'."
2049 (if (stringp (car rdn))
2050 (let ((entry (assoc (car rdn) epg-dn-type-alist)))
2052 (format "%s=%s" (cdr entry) (cdr rdn))
2053 (format "%s=%s" (car rdn) (cdr rdn))))
2054 (concat "(" (epg-decode-dn rdn) ")")))
2060 ;;; epg.el ends here