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.
30 (defvar epg-user-id nil
31 "GnuPG ID of your default identity.")
33 (defvar epg-user-id-alist nil
34 "An alist mapping from key ID to user ID.")
36 (defvar epg-last-status nil)
37 (defvar epg-read-point nil)
38 (defvar epg-process-filter-running nil)
39 (defvar epg-pending-status-list nil)
40 (defvar epg-key-id nil)
41 (defvar epg-context nil)
42 (defvar epg-debug-buffer nil)
44 ;; from gnupg/include/cipher.h
45 (defconst epg-cipher-algorithm-alist
57 ;; from gnupg/include/cipher.h
58 (defconst epg-pubkey-algorithm-alist
66 ;; from gnupg/include/cipher.h
67 (defconst epg-digest-algorithm-alist
75 ;; from gnupg/include/cipher.h
76 (defconst epg-compress-algorithm-alist
82 (defconst epg-invalid-recipients-reason-alist
83 '((0 . "No specific reason given")
85 (2 . "Ambigious specification")
86 (3 . "Wrong key usage")
91 (8 . "Policy mismatch")
92 (9 . "Not a secret key")
93 (10 . "Key not trusted")))
95 (defconst epg-delete-problem-reason-alist
97 (2 . "Must delete secret key first")
98 (3 . "Ambigious specification")))
100 (defconst epg-import-ok-reason-alist
101 '((0 . "Not actually changed")
102 (1 . "Entirely new key")
104 (4 . "New signatures")
106 (16 . "Contains private key")))
108 (defconst epg-import-problem-reason-alist
109 '((0 . "No specific reason given")
110 (1 . "Invalid Certificate")
111 (2 . "Issuer Certificate missing")
112 (3 . "Certificate Chain too long")
113 (4 . "Error storing certificate")))
115 (defconst epg-no-data-reason-alist
116 '((1 . "No armored data")
117 (2 . "Expected a packet but did not found one")
118 (3 . "Invalid packet found, this may indicate a non OpenPGP message")
119 (4 . "Signature expected but not found")))
121 (defconst epg-unexpected-reason-alist nil)
123 (defvar epg-key-validity-alist
136 (defvar epg-key-capablity-alist
140 (?a . authentication)))
142 (defvar epg-new-signature-type-alist
147 (defvar epg-dn-type-alist
148 '(("1.2.840.113549.1.9.1" . "EMail")
152 ("0.2.262.1.10.7.20" . "NameDistinguisher")
153 ("2.5.4.16" . "ADDR")
156 ("2.5.4.17" . "PostalCode")
157 ("2.5.4.65" . "Pseudo")
158 ("2.5.4.5" . "SerialNumber")))
160 (defvar epg-prompt-alist nil)
162 (put 'epg-error 'error-conditions '(epg-error error))
164 (defun epg-make-data-from-file (file)
165 "Make a data object from FILE."
166 (cons 'epg-data (vector file nil)))
168 (defun epg-make-data-from-string (string)
169 "Make a data object from STRING."
170 (cons 'epg-data (vector nil string)))
172 (defun epg-data-file (data)
173 "Return the file of DATA."
174 (unless (eq (car-safe data) 'epg-data)
175 (signal 'wrong-type-argument (list 'epg-data-p data)))
178 (defun epg-data-string (data)
179 "Return the string of DATA."
180 (unless (eq (car-safe data) 'epg-data)
181 (signal 'wrong-type-argument (list 'epg-data-p data)))
184 (defun epg-make-context (&optional protocol armor textmode include-certs
185 cipher-algorithm digest-algorithm
187 "Return a context object."
189 (vector (or protocol 'OpenPGP) armor textmode include-certs
190 cipher-algorithm digest-algorithm compress-algorithm
191 #'epg-passphrase-callback-function
193 nil nil nil nil nil nil)))
195 (defun epg-context-protocol (context)
196 "Return the protocol used within CONTEXT."
197 (unless (eq (car-safe context) 'epg-context)
198 (signal 'wrong-type-argument (list 'epg-context-p context)))
199 (aref (cdr context) 0))
201 (defun epg-context-armor (context)
202 "Return t if the output shouled be ASCII armored in CONTEXT."
203 (unless (eq (car-safe context) 'epg-context)
204 (signal 'wrong-type-argument (list 'epg-context-p context)))
205 (aref (cdr context) 1))
207 (defun epg-context-textmode (context)
208 "Return t if canonical text mode should be used in CONTEXT."
209 (unless (eq (car-safe context) 'epg-context)
210 (signal 'wrong-type-argument (list 'epg-context-p context)))
211 (aref (cdr context) 2))
213 (defun epg-context-include-certs (context)
214 "Return how many certificates should be included in an S/MIME signed
216 (unless (eq (car-safe context) 'epg-context)
217 (signal 'wrong-type-argument (list 'epg-context-p context)))
218 (aref (cdr context) 3))
220 (defun epg-context-cipher-algorithm (context)
221 "Return the cipher algorithm in CONTEXT."
222 (unless (eq (car-safe context) 'epg-context)
223 (signal 'wrong-type-argument (list 'epg-context-p context)))
224 (aref (cdr context) 4))
226 (defun epg-context-digest-algorithm (context)
227 "Return the digest algorithm in CONTEXT."
228 (unless (eq (car-safe context) 'epg-context)
229 (signal 'wrong-type-argument (list 'epg-context-p context)))
230 (aref (cdr context) 5))
232 (defun epg-context-compress-algorithm (context)
233 "Return the compress algorithm in CONTEXT."
234 (unless (eq (car-safe context) 'epg-context)
235 (signal 'wrong-type-argument (list 'epg-context-p context)))
236 (aref (cdr context) 6))
238 (defun epg-context-passphrase-callback (context)
239 "Return the function used to query passphrase."
240 (unless (eq (car-safe context) 'epg-context)
241 (signal 'wrong-type-argument (list 'epg-context-p context)))
242 (aref (cdr context) 7))
244 (defun epg-context-progress-callback (context)
245 "Return the function which handles progress update."
246 (unless (eq (car-safe context) 'epg-context)
247 (signal 'wrong-type-argument (list 'epg-context-p context)))
248 (aref (cdr context) 8))
250 (defun epg-context-signers (context)
251 "Return the list of key-id for singning."
252 (unless (eq (car-safe context) 'epg-context)
253 (signal 'wrong-type-argument (list 'epg-context-p context)))
254 (aref (cdr context) 9))
256 (defun epg-context-sig-notations (context)
257 "Return the list of notations for singning."
258 (unless (eq (car-safe context) 'epg-context)
259 (signal 'wrong-type-argument (list 'epg-context-p context)))
260 (aref (cdr context) 10))
262 (defun epg-context-process (context)
263 "Return the process object of `epg-gpg-program'.
264 This function is for internal use only."
265 (unless (eq (car-safe context) 'epg-context)
266 (signal 'wrong-type-argument (list 'epg-context-p context)))
267 (aref (cdr context) 11))
269 (defun epg-context-output-file (context)
270 "Return the output file of `epg-gpg-program'.
271 This function is for internal use only."
272 (unless (eq (car-safe context) 'epg-context)
273 (signal 'wrong-type-argument (list 'epg-context-p context)))
274 (aref (cdr context) 12))
276 (defun epg-context-result (context)
277 "Return the result of the previous cryptographic operation."
278 (unless (eq (car-safe context) 'epg-context)
279 (signal 'wrong-type-argument (list 'epg-context-p context)))
280 (aref (cdr context) 13))
282 (defun epg-context-operation (context)
283 "Return the name of the current cryptographic operation."
284 (unless (eq (car-safe context) 'epg-context)
285 (signal 'wrong-type-argument (list 'epg-context-p context)))
286 (aref (cdr context) 14))
288 (defun epg-context-set-protocol (context protocol)
289 "Set the protocol used within CONTEXT."
290 (unless (eq (car-safe context) 'epg-context)
291 (signal 'wrong-type-argument (list 'epg-context-p context)))
292 (aset (cdr context) 0 protocol))
294 (defun epg-context-set-armor (context armor)
295 "Specify if the output shouled be ASCII armored in CONTEXT."
296 (unless (eq (car-safe context) 'epg-context)
297 (signal 'wrong-type-argument (list 'epg-context-p context)))
298 (aset (cdr context) 1 armor))
300 (defun epg-context-set-textmode (context textmode)
301 "Specify if canonical text mode should be used in CONTEXT."
302 (unless (eq (car-safe context) 'epg-context)
303 (signal 'wrong-type-argument (list 'epg-context-p context)))
304 (aset (cdr context) 2 textmode))
306 (defun epg-context-set-include-certs (context include-certs)
307 "Set how many certificates should be included in an S/MIME signed message."
308 (unless (eq (car-safe context) 'epg-context)
309 (signal 'wrong-type-argument (list 'epg-context-p context)))
310 (aset (cdr context) 3 include-certs))
312 (defun epg-context-set-cipher-algorithm (context cipher-algorithm)
313 "Set the cipher algorithm in CONTEXT."
314 (unless (eq (car-safe context) 'epg-context)
315 (signal 'wrong-type-argument (list 'epg-context-p context)))
316 (aset (cdr context) 4 cipher-algorithm))
318 (defun epg-context-set-digest-algorithm (context digest-algorithm)
319 "Set the digest algorithm in CONTEXT."
320 (unless (eq (car-safe context) 'epg-context)
321 (signal 'wrong-type-argument (list 'epg-context-p context)))
322 (aset (cdr context) 5 digest-algorithm))
324 (defun epg-context-set-compress-algorithm (context compress-algorithm)
325 "Set the compress algorithm in CONTEXT."
326 (unless (eq (car-safe context) 'epg-context)
327 (signal 'wrong-type-argument (list 'epg-context-p context)))
328 (aset (cdr context) 6 compress-algorithm))
330 (defun epg-context-set-passphrase-callback (context passphrase-callback
332 "Set the function used to query passphrase.
333 If optional argument HANDBACK is specified, it is passed to CALLBACK."
334 (unless (eq (car-safe context) 'epg-context)
335 (signal 'wrong-type-argument (list 'epg-context-p context)))
336 (aset (cdr context) 7 (if handback
337 (cons passphrase-callback handback)
338 passphrase-callback)))
340 (defun epg-context-set-progress-callback (context progress-callback
342 "Set the function which handles progress update.
343 If optional argument HANDBACK is specified, it is passed to CALLBACK."
344 (unless (eq (car-safe context) 'epg-context)
345 (signal 'wrong-type-argument (list 'epg-context-p context)))
346 (aset (cdr context) 8 (if handback
347 (cons progress-callback handback)
350 (defun epg-context-set-signers (context signers)
351 "Set the list of key-id for singning."
352 (unless (eq (car-safe context) 'epg-context)
353 (signal 'wrong-type-argument (list 'epg-context-p context)))
354 (aset (cdr context) 9 signers))
356 (defun epg-context-set-sig-notations (context notations)
357 "Set the list of notations for singning."
358 (unless (eq (car-safe context) 'epg-context)
359 (signal 'wrong-type-argument (list 'epg-context-p context)))
360 (aset (cdr context) 10 notations))
362 (defun epg-context-set-process (context process)
363 "Set the process object of `epg-gpg-program'.
364 This function is for internal use only."
365 (unless (eq (car-safe context) 'epg-context)
366 (signal 'wrong-type-argument (list 'epg-context-p context)))
367 (aset (cdr context) 11 process))
369 (defun epg-context-set-output-file (context output-file)
370 "Set the output file of `epg-gpg-program'.
371 This function is for internal use only."
372 (unless (eq (car-safe context) 'epg-context)
373 (signal 'wrong-type-argument (list 'epg-context-p context)))
374 (aset (cdr context) 12 output-file))
376 (defun epg-context-set-result (context result)
377 "Set the result of the previous cryptographic operation."
378 (unless (eq (car-safe context) 'epg-context)
379 (signal 'wrong-type-argument (list 'epg-context-p context)))
380 (aset (cdr context) 13 result))
382 (defun epg-context-set-operation (context operation)
383 "Set the name of the current cryptographic operation."
384 (unless (eq (car-safe context) 'epg-context)
385 (signal 'wrong-type-argument (list 'epg-context-p context)))
386 (aset (cdr context) 14 operation))
388 (defun epg-make-signature (status &optional key-id)
389 "Return a signature object."
390 (cons 'epg-signature (vector status key-id nil nil nil nil nil nil nil nil
393 (defun epg-signature-status (signature)
394 "Return the status code of SIGNATURE."
395 (unless (eq (car-safe signature) 'epg-signature)
396 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
397 (aref (cdr signature) 0))
399 (defun epg-signature-key-id (signature)
400 "Return the key-id of SIGNATURE."
401 (unless (eq (car-safe signature) 'epg-signature)
402 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
403 (aref (cdr signature) 1))
405 (defun epg-signature-validity (signature)
406 "Return the validity of SIGNATURE."
407 (unless (eq (car-safe signature) 'epg-signature)
408 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
409 (aref (cdr signature) 2))
411 (defun epg-signature-fingerprint (signature)
412 "Return the fingerprint of SIGNATURE."
413 (unless (eq (car-safe signature) 'epg-signature)
414 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
415 (aref (cdr signature) 3))
417 (defun epg-signature-creation-time (signature)
418 "Return the creation time of SIGNATURE."
419 (unless (eq (car-safe signature) 'epg-signature)
420 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
421 (aref (cdr signature) 4))
423 (defun epg-signature-expiration-time (signature)
424 "Return the expiration time of SIGNATURE."
425 (unless (eq (car-safe signature) 'epg-signature)
426 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
427 (aref (cdr signature) 5))
429 (defun epg-signature-pubkey-algorithm (signature)
430 "Return the public key algorithm of SIGNATURE."
431 (unless (eq (car-safe signature) 'epg-signature)
432 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
433 (aref (cdr signature) 6))
435 (defun epg-signature-digest-algorithm (signature)
436 "Return the digest algorithm of SIGNATURE."
437 (unless (eq (car-safe signature) 'epg-signature)
438 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
439 (aref (cdr signature) 7))
441 (defun epg-signature-class (signature)
442 "Return the class of SIGNATURE."
443 (unless (eq (car-safe signature) 'epg-signature)
444 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
445 (aref (cdr signature) 8))
447 (defun epg-signature-version (signature)
448 "Return the version of SIGNATURE."
449 (unless (eq (car-safe signature) 'epg-signature)
450 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
451 (aref (cdr signature) 9))
453 (defun epg-sig-notations (signature)
454 "Return the list of notations of SIGNATURE."
455 (unless (eq (car-safe signature) 'epg-signature)
456 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
457 (aref (cdr signature) 10))
459 (defun epg-signature-set-status (signature status)
460 "Set the status code of SIGNATURE."
461 (unless (eq (car-safe signature) 'epg-signature)
462 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
463 (aset (cdr signature) 0 status))
465 (defun epg-signature-set-key-id (signature key-id)
466 "Set the key-id of SIGNATURE."
467 (unless (eq (car-safe signature) 'epg-signature)
468 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
469 (aset (cdr signature) 1 key-id))
471 (defun epg-signature-set-validity (signature validity)
472 "Set the validity of SIGNATURE."
473 (unless (eq (car-safe signature) 'epg-signature)
474 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
475 (aset (cdr signature) 2 validity))
477 (defun epg-signature-set-fingerprint (signature fingerprint)
478 "Set the fingerprint of SIGNATURE."
479 (unless (eq (car-safe signature) 'epg-signature)
480 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
481 (aset (cdr signature) 3 fingerprint))
483 (defun epg-signature-set-creation-time (signature creation-time)
484 "Set the creation time of SIGNATURE."
485 (unless (eq (car-safe signature) 'epg-signature)
486 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
487 (aset (cdr signature) 4 creation-time))
489 (defun epg-signature-set-expiration-time (signature expiration-time)
490 "Set the expiration time of SIGNATURE."
491 (unless (eq (car-safe signature) 'epg-signature)
492 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
493 (aset (cdr signature) 5 expiration-time))
495 (defun epg-signature-set-pubkey-algorithm (signature pubkey-algorithm)
496 "Set the public key algorithm of SIGNATURE."
497 (unless (eq (car-safe signature) 'epg-signature)
498 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
499 (aset (cdr signature) 6 pubkey-algorithm))
501 (defun epg-signature-set-digest-algorithm (signature digest-algorithm)
502 "Set the digest algorithm of SIGNATURE."
503 (unless (eq (car-safe signature) 'epg-signature)
504 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
505 (aset (cdr signature) 7 digest-algorithm))
507 (defun epg-signature-set-class (signature class)
508 "Set the class of SIGNATURE."
509 (unless (eq (car-safe signature) 'epg-signature)
510 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
511 (aset (cdr signature) 8 class))
513 (defun epg-signature-set-version (signature version)
514 "Set the version of SIGNATURE."
515 (unless (eq (car-safe signature) 'epg-signature)
516 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
517 (aset (cdr signature) 9 version))
519 (defun epg-signature-set-notations (signature notations)
520 "Set the list of notations of SIGNATURE."
521 (unless (eq (car-safe signature) 'epg-signature)
522 (signal 'wrong-type-argument (list 'epg-signature-p signature)))
523 (aset (cdr signature) 10 notations))
525 (defun epg-make-new-signature (type pubkey-algorithm digest-algorithm
526 class creation-time fingerprint)
527 "Return a new signature object."
528 (cons 'epg-new-signature (vector type pubkey-algorithm digest-algorithm
529 class creation-time fingerprint)))
531 (defun epg-new-signature-type (new-signature)
532 "Return the type of NEW-SIGNATURE."
533 (unless (eq (car-safe new-signature) 'epg-new-signature)
534 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
535 (aref (cdr new-signature) 0))
537 (defun epg-new-signature-pubkey-algorithm (new-signature)
538 "Return the public key algorithm of NEW-SIGNATURE."
539 (unless (eq (car-safe new-signature) 'epg-new-signature)
540 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
541 (aref (cdr new-signature) 1))
543 (defun epg-new-signature-digest-algorithm (new-signature)
544 "Return the digest algorithm of NEW-SIGNATURE."
545 (unless (eq (car-safe new-signature) 'epg-new-signature)
546 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
547 (aref (cdr new-signature) 2))
549 (defun epg-new-signature-class (new-signature)
550 "Return the class of NEW-SIGNATURE."
551 (unless (eq (car-safe new-signature) 'epg-new-signature)
552 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
553 (aref (cdr new-signature) 3))
555 (defun epg-new-signature-creation-time (new-signature)
556 "Return the creation time of NEW-SIGNATURE."
557 (unless (eq (car-safe new-signature) 'epg-new-signature)
558 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
559 (aref (cdr new-signature) 4))
561 (defun epg-new-signature-fingerprint (new-signature)
562 "Return the fingerprint of NEW-SIGNATURE."
563 (unless (eq (car-safe new-signature) 'epg-new-signature)
564 (signal 'wrong-type-argument (list 'epg-new-signature-p new-signature)))
565 (aref (cdr new-signature) 5))
567 (defun epg-make-key (owner-trust)
568 "Return a key object."
569 (cons 'epg-key (vector owner-trust nil nil)))
571 (defun epg-key-owner-trust (key)
572 "Return the owner trust of KEY."
573 (unless (eq (car-safe key) 'epg-key)
574 (signal 'wrong-type-argument (list 'epg-key-p key)))
577 (defun epg-key-sub-key-list (key)
578 "Return the sub key list of KEY."
579 (unless (eq (car-safe key) 'epg-key)
580 (signal 'wrong-type-argument (list 'epg-key-p key)))
583 (defun epg-key-user-id-list (key)
584 "Return the user ID list of KEY."
585 (unless (eq (car-safe key) 'epg-key)
586 (signal 'wrong-type-argument (list 'epg-key-p key)))
589 (defun epg-key-set-sub-key-list (key sub-key-list)
590 "Set the sub key list of KEY."
591 (unless (eq (car-safe key) 'epg-key)
592 (signal 'wrong-type-argument (list 'epg-key-p key)))
593 (aset (cdr key) 1 sub-key-list))
595 (defun epg-key-set-user-id-list (key user-id-list)
596 "Set the user ID list of KEY."
597 (unless (eq (car-safe key) 'epg-key)
598 (signal 'wrong-type-argument (list 'epg-key-p key)))
599 (aset (cdr key) 2 user-id-list))
601 (defun epg-make-sub-key (validity capability secret-p algorithm length id
602 creation-time expiration-time)
603 "Return a sub key object."
605 (vector validity capability secret-p algorithm length id creation-time
606 expiration-time nil)))
608 (defun epg-sub-key-validity (sub-key)
609 "Return the validity of SUB-KEY."
610 (unless (eq (car-safe sub-key) 'epg-sub-key)
611 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
612 (aref (cdr sub-key) 0))
614 (defun epg-sub-key-capability (sub-key)
615 "Return the capability of SUB-KEY."
616 (unless (eq (car-safe sub-key) 'epg-sub-key)
617 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
618 (aref (cdr sub-key) 1))
620 (defun epg-sub-key-secret-p (sub-key)
621 "Return non-nil if SUB-KEY is a secret key."
622 (unless (eq (car-safe sub-key) 'epg-sub-key)
623 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
624 (aref (cdr sub-key) 2))
626 (defun epg-sub-key-algorithm (sub-key)
627 "Return the algorithm of SUB-KEY."
628 (unless (eq (car-safe sub-key) 'epg-sub-key)
629 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
630 (aref (cdr sub-key) 3))
632 (defun epg-sub-key-length (sub-key)
633 "Return the length of SUB-KEY."
634 (unless (eq (car-safe sub-key) 'epg-sub-key)
635 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
636 (aref (cdr sub-key) 4))
638 (defun epg-sub-key-id (sub-key)
639 "Return the ID of SUB-KEY."
640 (unless (eq (car-safe sub-key) 'epg-sub-key)
641 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
642 (aref (cdr sub-key) 5))
644 (defun epg-sub-key-creation-time (sub-key)
645 "Return the creation time of SUB-KEY."
646 (unless (eq (car-safe sub-key) 'epg-sub-key)
647 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
648 (aref (cdr sub-key) 6))
650 (defun epg-sub-key-expiration-time (sub-key)
651 "Return the expiration time of SUB-KEY."
652 (unless (eq (car-safe sub-key) 'epg-sub-key)
653 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
654 (aref (cdr sub-key) 7))
656 (defun epg-sub-key-fingerprint (sub-key)
657 "Return the fingerprint of SUB-KEY."
658 (unless (eq (car-safe sub-key) 'epg-sub-key)
659 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
660 (aref (cdr sub-key) 8))
662 (defun epg-sub-key-set-fingerprint (sub-key fingerprint)
663 "Set the fingerprint of SUB-KEY.
664 This function is for internal use only."
665 (unless (eq (car-safe sub-key) 'epg-sub-key)
666 (signal 'wrong-type-argument (list 'epg-sub-key-p sub-key)))
667 (aset (cdr sub-key) 8 fingerprint))
669 (defun epg-make-user-id (validity string)
670 "Return a user ID object."
671 (cons 'epg-user-id (vector validity string nil)))
673 (defun epg-user-id-validity (user-id)
674 "Return the validity of USER-ID."
675 (unless (eq (car-safe user-id) 'epg-user-id)
676 (signal 'wrong-type-argument (list 'epg-user-id-p user-id)))
677 (aref (cdr user-id) 0))
679 (defun epg-user-id-string (user-id)
680 "Return the name of USER-ID."
681 (unless (eq (car-safe user-id) 'epg-user-id)
682 (signal 'wrong-type-argument (list 'epg-user-id-p user-id)))
683 (aref (cdr user-id) 1))
685 (defun epg-user-id-signature-list (user-id)
686 "Return the signature list of USER-ID."
687 (unless (eq (car-safe user-id) 'epg-user-id)
688 (signal 'wrong-type-argument (list 'epg-user-id-p user-id)))
689 (aref (cdr user-id) 2))
691 (defun epg-user-id-set-signature-list (user-id signature-list)
692 "Set the signature list of USER-ID."
693 (unless (eq (car-safe user-id) 'epg-user-id)
694 (signal 'wrong-type-argument (list 'epg-user-id-p user-id)))
695 (aset (cdr user-id) 2 signature-list))
697 (defun epg-make-key-signature (validity pubkey-algorithm key-id creation-time
698 expiration-time user-id class
700 "Return a key signature object."
701 (cons 'epg-key-signature
702 (vector validity pubkey-algorithm key-id creation-time expiration-time
703 user-id class exportable-p)))
705 (defun epg-key-signature-validity (key-signature)
706 "Return the validity of KEY-SIGNATURE."
707 (unless (eq (car-safe key-signature) 'epg-key-signature)
708 (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature)))
709 (aref (cdr key-signature) 0))
711 (defun epg-key-signature-pubkey-algorithm (key-signature)
712 "Return the public key algorithm of KEY-SIGNATURE."
713 (unless (eq (car-safe key-signature) 'epg-key-signature)
714 (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature)))
715 (aref (cdr key-signature) 1))
717 (defun epg-key-signature-key-id (key-signature)
718 "Return the key-id of KEY-SIGNATURE."
719 (unless (eq (car-safe key-signature) 'epg-key-signature)
720 (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature)))
721 (aref (cdr key-signature) 2))
723 (defun epg-key-signature-creation-time (key-signature)
724 "Return the creation time of KEY-SIGNATURE."
725 (unless (eq (car-safe key-signature) 'epg-key-signature)
726 (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature)))
727 (aref (cdr key-signature) 3))
729 (defun epg-key-signature-expiration-time (key-signature)
730 "Return the expiration time of KEY-SIGNATURE."
731 (unless (eq (car-safe key-signature) 'epg-key-signature)
732 (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature)))
733 (aref (cdr key-signature) 4))
735 (defun epg-key-signature-user-id (key-signature)
736 "Return the user-id of KEY-SIGNATURE."
737 (unless (eq (car-safe key-signature) 'epg-key-signature)
738 (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature)))
739 (aref (cdr key-signature) 5))
741 (defun epg-key-signature-class (key-signature)
742 "Return the class of KEY-SIGNATURE."
743 (unless (eq (car-safe key-signature) 'epg-key-signature)
744 (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature)))
745 (aref (cdr key-signature) 6))
747 (defun epg-key-signature-exportable-p (key-signature)
748 "Return t if KEY-SIGNATURE is exportable."
749 (unless (eq (car-safe key-signature) 'epg-key-signature)
750 (signal 'wrong-type-argument (list 'epg-key-signature-p key-signature)))
751 (aref (cdr key-signature) 7))
753 (defun epg-make-sig-notation (name value &optional human-readable
755 "Return a notation object."
756 (cons 'epg-sig-notation (vector name value human-readable critical)))
758 (defun epg-sig-notation-name (sig-notation)
759 "Return the name of SIG-NOTATION."
760 (unless (eq (car-safe sig-notation) 'epg-sig-notation)
761 (signal 'wrong-type-argument (list 'epg-sig-notation-p
763 (aref (cdr sig-notation) 0))
765 (defun epg-sig-notation-value (sig-notation)
766 "Return the value of SIG-NOTATION."
767 (unless (eq (car-safe sig-notation) 'epg-sig-notation)
768 (signal 'wrong-type-argument (list 'epg-sig-notation-p
770 (aref (cdr sig-notation) 1))
772 (defun epg-sig-notation-human-readable (sig-notation)
773 "Return the human-readable of SIG-NOTATION."
774 (unless (eq (car-safe sig-notation) 'epg-sig-notation)
775 (signal 'wrong-type-argument (list 'epg-sig-notation-p
777 (aref (cdr sig-notation) 2))
779 (defun epg-sig-notation-critical (sig-notation)
780 "Return the critical of SIG-NOTATION."
781 (unless (eq (car-safe sig-notation) 'epg-sig-notation)
782 (signal 'wrong-type-argument (list 'epg-sig-notation-p
784 (aref (cdr sig-notation) 3))
786 (defun epg-sig-notation-set-value (sig-notation value)
787 "Set the value of SIG-NOTATION."
788 (unless (eq (car-safe sig-notation) 'epg-sig-notation)
789 (signal 'wrong-type-argument (list 'epg-sig-notation-p
791 (aset (cdr sig-notation) 1 value))
793 (defun epg-make-import-status (fingerprint &optional reason new user-id
794 signature sub-key secret)
795 "Return a import status object."
796 (cons 'epg-import-status (vector fingerprint reason new user-id signature
799 (defun epg-import-status-fingerprint (import-status)
800 "Return the fingerprint of the key that was considered."
801 (unless (eq (car-safe import-status) 'epg-import-status)
802 (signal 'wrong-type-argument (list 'epg-import-status-p import-status)))
803 (aref (cdr import-status) 0))
805 (defun epg-import-status-reason (import-status)
806 "Return the reason code for import failure."
807 (unless (eq (car-safe import-status) 'epg-import-status)
808 (signal 'wrong-type-argument (list 'epg-import-status-p import-status)))
809 (aref (cdr import-status) 1))
811 (defun epg-import-status-new (import-status)
812 "Return t if the imported key was new."
813 (unless (eq (car-safe import-status) 'epg-import-status)
814 (signal 'wrong-type-argument (list 'epg-import-status-p import-status)))
815 (aref (cdr import-status) 2))
817 (defun epg-import-status-user-id (import-status)
818 "Return t if the imported key contained new user IDs."
819 (unless (eq (car-safe import-status) 'epg-import-status)
820 (signal 'wrong-type-argument (list 'epg-import-status-p import-status)))
821 (aref (cdr import-status) 3))
823 (defun epg-import-status-signature (import-status)
824 "Return t if the imported key contained new signatures."
825 (unless (eq (car-safe import-status) 'epg-import-status)
826 (signal 'wrong-type-argument (list 'epg-import-status-p import-status)))
827 (aref (cdr import-status) 4))
829 (defun epg-import-status-sub-key (import-status)
830 "Return t if the imported key contained new sub keys."
831 (unless (eq (car-safe import-status) 'epg-import-status)
832 (signal 'wrong-type-argument (list 'epg-import-status-p import-status)))
833 (aref (cdr import-status) 5))
835 (defun epg-import-status-secret (import-status)
836 "Return t if the imported key contained a secret key."
837 (unless (eq (car-safe import-status) 'epg-import-status)
838 (signal 'wrong-type-argument (list 'epg-import-status-p import-status)))
839 (aref (cdr import-status) 6))
841 (defun epg-make-import-result (considered no-user-id imported imported-rsa
842 unchanged new-user-ids new-sub-keys
843 new-signatures new-revocations
844 secret-read secret-imported
845 secret-unchanged not-imported
847 "Return a import result object."
848 (cons 'epg-import-result (vector considered no-user-id imported imported-rsa
849 unchanged new-user-ids new-sub-keys
850 new-signatures new-revocations secret-read
851 secret-imported secret-unchanged
852 not-imported imports)))
854 (defun epg-import-result-considered (import-result)
855 "Return the total number of considered keys."
856 (unless (eq (car-safe import-result) 'epg-import-result)
857 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
858 (aref (cdr import-result) 0))
860 (defun epg-import-result-no-user-id (import-result)
861 "Return the number of keys without user ID."
862 (unless (eq (car-safe import-result) 'epg-import-result)
863 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
864 (aref (cdr import-result) 1))
866 (defun epg-import-result-imported (import-result)
867 "Return the number of imported keys."
868 (unless (eq (car-safe import-result) 'epg-import-result)
869 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
870 (aref (cdr import-result) 2))
872 (defun epg-import-result-imported-rsa (import-result)
873 "Return the number of imported RSA keys."
874 (unless (eq (car-safe import-result) 'epg-import-result)
875 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
876 (aref (cdr import-result) 3))
878 (defun epg-import-result-unchanged (import-result)
879 "Return the number of unchanged keys."
880 (unless (eq (car-safe import-result) 'epg-import-result)
881 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
882 (aref (cdr import-result) 4))
884 (defun epg-import-result-new-user-ids (import-result)
885 "Return the number of new user IDs."
886 (unless (eq (car-safe import-result) 'epg-import-result)
887 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
888 (aref (cdr import-result) 5))
890 (defun epg-import-result-new-sub-keys (import-result)
891 "Return the number of new sub keys."
892 (unless (eq (car-safe import-result) 'epg-import-result)
893 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
894 (aref (cdr import-result) 6))
896 (defun epg-import-result-new-signatures (import-result)
897 "Return the number of new signatures."
898 (unless (eq (car-safe import-result) 'epg-import-result)
899 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
900 (aref (cdr import-result) 7))
902 (defun epg-import-result-new-revocations (import-result)
903 "Return the number of new revocations."
904 (unless (eq (car-safe import-result) 'epg-import-result)
905 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
906 (aref (cdr import-result) 8))
908 (defun epg-import-result-secret-read (import-result)
909 "Return the total number of secret keys read."
910 (unless (eq (car-safe import-result) 'epg-import-result)
911 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
912 (aref (cdr import-result) 9))
914 (defun epg-import-result-secret-imported (import-result)
915 "Return the number of imported secret keys."
916 (unless (eq (car-safe import-result) 'epg-import-result)
917 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
918 (aref (cdr import-result) 10))
920 (defun epg-import-result-secret-unchanged (import-result)
921 "Return the number of unchanged secret keys."
922 (unless (eq (car-safe import-result) 'epg-import-result)
923 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
924 (aref (cdr import-result) 11))
926 (defun epg-import-result-not-imported (import-result)
927 "Return the number of keys not imported."
928 (unless (eq (car-safe import-result) 'epg-import-result)
929 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
930 (aref (cdr import-result) 12))
932 (defun epg-import-result-imports (import-result)
933 "Return the list of `epg-import-status' objects."
934 (unless (eq (car-safe import-result) 'epg-import-result)
935 (signal 'wrong-type-argument (list 'epg-import-result-p import-result)))
936 (aref (cdr import-result) 13))
938 (defun epg-context-result-for (context name)
939 "Return the result of CONTEXT associated with NAME."
940 (cdr (assq name (epg-context-result context))))
942 (defun epg-context-set-result-for (context name value)
943 "Set the result of CONTEXT associated with NAME to VALUE."
944 (let* ((result (epg-context-result context))
945 (entry (assq name result)))
948 (epg-context-set-result context (cons (cons name value) result)))))
950 (defun epg-signature-to-string (signature)
951 "Convert SIGNATURE to a human readable string."
952 (let* ((user-id (cdr (assoc (epg-signature-key-id signature)
954 (pubkey-algorithm (epg-signature-pubkey-algorithm signature)))
956 (cond ((eq (epg-signature-status signature) 'good)
957 "Good signature from ")
958 ((eq (epg-signature-status signature) 'bad)
959 "Bad signature from ")
960 ((eq (epg-signature-status signature) 'expired)
961 "Expired signature from ")
962 ((eq (epg-signature-status signature) 'expired-key)
963 "Signature made by expired key ")
964 ((eq (epg-signature-status signature) 'revoked-key)
965 "Signature made by revoked key ")
966 ((eq (epg-signature-status signature) 'no-pubkey)
967 "No public key for "))
968 (epg-signature-key-id signature)
971 (if (stringp user-id)
973 (epg-decode-dn user-id)))
975 (if (epg-signature-validity signature)
976 (format " (trust %s)" (epg-signature-validity signature))
978 (if (epg-signature-creation-time signature)
979 (format-time-string " created at %Y-%m-%dT%T%z"
980 (epg-signature-creation-time signature))
984 (or (cdr (assq pubkey-algorithm epg-pubkey-algorithm-alist))
985 (format "(unknown algorithm %d)" pubkey-algorithm)))
988 (defun epg-verify-result-to-string (verify-result)
989 "Convert VERIFY-RESULT to a human readable string."
990 (mapconcat #'epg-signature-to-string verify-result "\n"))
992 (defun epg-new-signature-to-string (new-signature)
993 "Convert NEW-SIGNATURE to a human readable string."
995 (cond ((eq (epg-new-signature-type new-signature) 'detached)
996 "Detached signature ")
997 ((eq (epg-new-signature-type new-signature) 'clear)
998 "Cleartext signature ")
1001 (cdr (assq (epg-new-signature-pubkey-algorithm new-signature)
1002 epg-pubkey-algorithm-alist))
1004 (cdr (assq (epg-new-signature-digest-algorithm new-signature)
1005 epg-digest-algorithm-alist))
1007 (format "%02X " (epg-new-signature-class new-signature))
1008 (epg-new-signature-fingerprint new-signature)))
1010 (defun epg-import-result-to-string (import-result)
1011 "Convert IMPORT-RESULT to a human readable string."
1012 (concat (format "Total number processed: %d\n"
1013 (epg-import-result-considered import-result))
1014 (if (> (epg-import-result-not-imported import-result) 0)
1015 (format " skipped new keys: %d\n"
1016 (epg-import-result-not-imported import-result)))
1017 (if (> (epg-import-result-no-user-id import-result) 0)
1018 (format " w/o user IDs: %d\n"
1019 (epg-import-result-no-user-id import-result)))
1020 (if (> (epg-import-result-imported import-result) 0)
1021 (concat (format " imported: %d"
1022 (epg-import-result-imported import-result))
1023 (if (> (epg-import-result-imported-rsa import-result) 0)
1024 (format " (RSA: %d)"
1025 (epg-import-result-imported-rsa
1028 (if (> (epg-import-result-unchanged import-result) 0)
1029 (format " unchanged: %d\n"
1030 (epg-import-result-unchanged import-result)))
1031 (if (> (epg-import-result-new-user-ids import-result) 0)
1032 (format " new user IDs: %d\n"
1033 (epg-import-result-new-user-ids import-result)))
1034 (if (> (epg-import-result-new-sub-keys import-result) 0)
1035 (format " new subkeys: %d\n"
1036 (epg-import-result-new-sub-keys import-result)))
1037 (if (> (epg-import-result-new-signatures import-result) 0)
1038 (format " new signatures: %d\n"
1039 (epg-import-result-new-signatures import-result)))
1040 (if (> (epg-import-result-new-revocations import-result) 0)
1041 (format " new key revocations: %d\n"
1042 (epg-import-result-new-revocations import-result)))
1043 (if (> (epg-import-result-secret-read import-result) 0)
1044 (format " secret keys read: %d\n"
1045 (epg-import-result-secret-read import-result)))
1046 (if (> (epg-import-result-secret-imported import-result) 0)
1047 (format " secret keys imported: %d\n"
1048 (epg-import-result-secret-imported import-result)))
1049 (if (> (epg-import-result-secret-unchanged import-result) 0)
1050 (format " secret keys unchanged: %d\n"
1051 (epg-import-result-secret-unchanged import-result)))))
1053 (defun epg--start (context args)
1054 "Start `epg-gpg-program' in a subprocess with given ARGS."
1055 (if (and (epg-context-process context)
1056 (eq (process-status (epg-context-process context)) 'run))
1057 (error "%s is already running in this context"
1058 (if (eq (epg-context-protocol context) 'CMS)
1061 (let* ((args (append (list "--no-tty"
1064 (if (and (not (eq (epg-context-protocol context) 'CMS))
1065 (string-match ":" (or (getenv "GPG_AGENT_INFO")
1068 (if (and (not (eq (epg-context-protocol context) 'CMS))
1069 (epg-context-progress-callback context))
1070 '("--enable-progress-filter"))
1071 (if epg-gpg-home-directory
1072 (list "--homedir" epg-gpg-home-directory))
1073 (unless (eq (epg-context-protocol context) 'CMS)
1074 '("--command-fd" "0"))
1075 (if (epg-context-armor context) '("--armor"))
1076 (if (epg-context-textmode context) '("--textmode"))
1077 (if (epg-context-output-file context)
1078 (list "--output" (epg-context-output-file context)))
1080 (coding-system-for-write 'binary)
1081 process-connection-type
1082 (orig-mode (default-file-modes))
1083 (buffer (generate-new-buffer " *epg*"))
1087 (unless epg-debug-buffer
1088 (setq epg-debug-buffer (generate-new-buffer " *epg-debug*")))
1089 (set-buffer epg-debug-buffer)
1090 (goto-char (point-max))
1091 (insert (format "%s %s\n"
1092 (if (eq (epg-context-protocol context) 'CMS)
1095 (mapconcat #'identity args " ")))))
1096 (with-current-buffer buffer
1097 (make-local-variable 'epg-last-status)
1098 (setq epg-last-status nil)
1099 (make-local-variable 'epg-read-point)
1100 (setq epg-read-point (point-min))
1101 (make-local-variable 'epg-process-filter-running)
1102 (setq epg-process-filter-running nil)
1103 (make-local-variable 'epg-pending-status-list)
1104 (setq epg-pending-status-list nil)
1105 (make-local-variable 'epg-key-id)
1106 (setq epg-key-id nil)
1107 (make-local-variable 'epg-context)
1108 (setq epg-context context))
1111 (set-default-file-modes 448)
1113 (apply #'start-process "epg" buffer
1114 (if (eq (epg-context-protocol context) 'CMS)
1118 (set-default-file-modes orig-mode))
1119 (set-process-filter process #'epg--process-filter)
1120 (epg-context-set-process context process)))
1122 (defun epg--process-filter (process input)
1125 (unless epg-debug-buffer
1126 (setq epg-debug-buffer (generate-new-buffer " *epg-debug*")))
1127 (set-buffer epg-debug-buffer)
1128 (goto-char (point-max))
1130 (if (buffer-live-p (process-buffer process))
1132 (set-buffer (process-buffer process))
1133 (goto-char (point-max))
1135 (unless epg-process-filter-running
1138 (setq epg-process-filter-running t)
1139 (goto-char epg-read-point)
1141 (while (looking-at ".*\n") ;the input line finished
1142 (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\) ?\\(.*\\)")
1143 (let* ((status (match-string 1))
1144 (string (match-string 2))
1145 (symbol (intern-soft (concat "epg--status-"
1147 (if (member status epg-pending-status-list)
1148 (setq epg-pending-status-list nil))
1151 (funcall symbol epg-context string))
1152 (setq epg-last-status (cons status string))))
1154 (setq epg-read-point (point))))
1155 (setq epg-process-filter-running nil))))))
1157 (defun epg-read-output (context)
1158 "Read the output file CONTEXT and return the content as a string."
1160 (if (fboundp 'set-buffer-multibyte)
1161 (set-buffer-multibyte nil))
1162 (if (file-exists-p (epg-context-output-file context))
1163 (let ((coding-system-for-read 'binary))
1164 (insert-file-contents (epg-context-output-file context))
1167 (defun epg-wait-for-status (context status-list)
1168 "Wait until one of elements in STATUS-LIST arrives."
1169 (with-current-buffer (process-buffer (epg-context-process context))
1170 (setq epg-pending-status-list status-list)
1171 (while (and (eq (process-status (epg-context-process context)) 'run)
1172 epg-pending-status-list)
1173 (accept-process-output (epg-context-process context) 1))))
1175 (defun epg-wait-for-completion (context)
1176 "Wait until the `epg-gpg-program' process completes."
1177 (while (eq (process-status (epg-context-process context)) 'run)
1178 (accept-process-output (epg-context-process context) 1)))
1180 (defun epg-reset (context)
1181 "Reset the CONTEXT."
1182 (if (and (epg-context-process context)
1183 (buffer-live-p (process-buffer (epg-context-process context))))
1184 (kill-buffer (process-buffer (epg-context-process context))))
1185 (epg-context-set-process context nil))
1187 (defun epg-delete-output-file (context)
1188 "Delete the output file of CONTEXT."
1189 (if (and (epg-context-output-file context)
1190 (file-exists-p (epg-context-output-file context)))
1191 (delete-file (epg-context-output-file context))))
1193 (defun epg--status-USERID_HINT (context string)
1194 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
1195 (let* ((key-id (match-string 1 string))
1196 (user-id (match-string 2 string))
1197 (entry (assoc key-id epg-user-id-alist)))
1199 (setcdr entry user-id)
1200 (setq epg-user-id-alist (cons (cons key-id user-id)
1201 epg-user-id-alist))))))
1203 (defun epg--status-NEED_PASSPHRASE (context string)
1204 (if (string-match "\\`\\([^ ]+\\)" string)
1205 (setq epg-key-id (match-string 1 string))))
1207 (defun epg--status-NEED_PASSPHRASE_SYM (context string)
1208 (setq epg-key-id 'SYM))
1210 (defun epg--status-NEED_PASSPHRASE_PIN (context string)
1211 (setq epg-key-id 'PIN))
1213 (defun epg--status-GET_HIDDEN (context string)
1214 (when (and epg-key-id
1215 (string-match "\\`passphrase\\." string))
1216 (unless (epg-context-passphrase-callback context)
1217 (error "passphrase-callback not set"))
1220 passphrase-with-new-line
1221 encoded-passphrase-with-new-line)
1227 (if (consp (epg-context-passphrase-callback context))
1228 (car (epg-context-passphrase-callback context))
1229 (epg-context-passphrase-callback context))
1232 (if (consp (epg-context-passphrase-callback context))
1233 (cdr (epg-context-passphrase-callback context)))))
1235 (setq passphrase-with-new-line (concat passphrase "\n"))
1236 (epg--clear-string passphrase)
1237 (setq passphrase nil)
1238 (if epg-passphrase-coding-system
1240 (setq encoded-passphrase-with-new-line
1241 (epg--encode-coding-string
1242 passphrase-with-new-line
1243 (coding-system-change-eol-conversion
1244 epg-passphrase-coding-system 'unix)))
1245 (epg--clear-string passphrase-with-new-line)
1246 (setq passphrase-with-new-line nil))
1247 (setq encoded-passphrase-with-new-line
1248 passphrase-with-new-line
1249 passphrase-with-new-line nil))
1250 (process-send-string (epg-context-process context)
1251 encoded-passphrase-with-new-line)))
1253 (epg-context-set-result-for
1256 (epg-context-result-for context 'error)))
1257 (delete-process (epg-context-process context))))
1259 (epg--clear-string passphrase))
1260 (if passphrase-with-new-line
1261 (epg--clear-string passphrase-with-new-line))
1262 (if encoded-passphrase-with-new-line
1263 (epg--clear-string encoded-passphrase-with-new-line))))))
1265 (defun epg--prompt-GET_BOOL (context string)
1266 (let ((entry (assoc string epg-prompt-alist)))
1267 (y-or-n-p (if entry (cdr entry) (concat string "? ")))))
1269 (defun epg--prompt-GET_BOOL-untrusted_key.override (context string)
1270 (y-or-n-p (if (equal (car epg-last-status) "USERID_HINT")
1271 (format "Untrusted key %s. Use anyway? "
1272 (cdr epg-last-status))
1273 "Use untrusted key anyway? ")))
1275 (defun epg--status-GET_BOOL (context string)
1278 (if (funcall (or (intern-soft (concat "epg--prompt-GET_BOOL-" string))
1279 #'epg--prompt-GET_BOOL)
1281 (process-send-string (epg-context-process context) "y\n")
1282 (process-send-string (epg-context-process context) "n\n"))
1284 (epg-context-set-result-for
1287 (epg-context-result-for context 'error)))
1288 (delete-process (epg-context-process context))))))
1290 (defun epg--status-GET_LINE (context string)
1291 (let ((entry (assoc string epg-prompt-alist))
1294 (process-send-string (epg-context-process context)
1295 (concat (read-string
1298 (concat string ": ")))
1301 (epg-context-set-result-for
1304 (epg-context-result-for context 'error)))
1305 (delete-process (epg-context-process context))))))
1307 (defun epg--status-*SIG (context status string)
1308 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
1309 (let* ((key-id (match-string 1 string))
1310 (user-id (match-string 2 string))
1311 (entry (assoc key-id epg-user-id-alist)))
1312 (epg-context-set-result-for
1315 (cons (epg-make-signature status key-id)
1316 (epg-context-result-for context 'verify)))
1317 (if (eq (epg-context-protocol context) 'CMS)
1319 (setq user-id (epg-dn-from-string user-id))
1322 (setcdr entry user-id)
1323 (setq epg-user-id-alist
1324 (cons (cons key-id user-id) epg-user-id-alist))))
1325 (epg-context-set-result-for
1328 (cons (epg-make-signature status)
1329 (epg-context-result-for context 'verify)))))
1331 (defun epg--status-GOODSIG (context string)
1332 (epg--status-*SIG context 'good string))
1334 (defun epg--status-EXPSIG (context string)
1335 (epg--status-*SIG context 'expired string))
1337 (defun epg--status-EXPKEYSIG (context string)
1338 (epg--status-*SIG context 'expired-key string))
1340 (defun epg--status-REVKEYSIG (context string)
1341 (epg--status-*SIG context 'revoked-key string))
1343 (defun epg--status-BADSIG (context string)
1344 (epg--status-*SIG context 'bad string))
1346 (defun epg--status-NO_PUBKEY (context string)
1347 (let ((signature (car (epg-context-result-for context 'verify))))
1349 (eq (epg-signature-status signature) 'error)
1350 (equal (epg-signature-key-id signature) string))
1351 (epg-signature-set-status signature 'no-pubkey))))
1353 (defun epg--time-from-seconds (seconds)
1354 (let ((number-seconds (string-to-number (concat seconds ".0"))))
1355 (cons (floor (/ number-seconds 65536))
1356 (floor (mod number-seconds 65536)))))
1358 (defun epg--status-ERRSIG (context string)
1359 (if (string-match "\\`\\([^ ]+\\) \\([0-9]+\\) \\([0-9]+\\) \
1360 \\([0-9A-Fa-f][0-9A-Fa-f]\\) \\([^ ]+\\) \\([0-9]+\\)"
1362 (let ((signature (epg-make-signature 'error)))
1363 (epg-context-set-result-for
1367 (epg-context-result-for context 'verify)))
1368 (epg-signature-set-key-id
1370 (match-string 1 string))
1371 (epg-signature-set-pubkey-algorithm
1373 (string-to-number (match-string 2 string)))
1374 (epg-signature-set-digest-algorithm
1376 (string-to-number (match-string 3 string)))
1377 (epg-signature-set-class
1379 (string-to-number (match-string 4 string) 16))
1380 (epg-signature-set-creation-time
1382 (epg--time-from-seconds (match-string 5 string))))))
1384 (defun epg--status-VALIDSIG (context string)
1385 (let ((signature (car (epg-context-result-for context 'verify))))
1386 (when (and signature
1387 (eq (epg-signature-status signature) 'good)
1388 (string-match "\\`\\([^ ]+\\) [^ ]+ \\([^ ]+\\) \\([^ ]+\\) \
1389 \\([0-9]+\\) [^ ]+ \\([0-9]+\\) \\([0-9]+\\) \\([0-9A-Fa-f][0-9A-Fa-f]\\) \
1392 (epg-signature-set-fingerprint
1394 (match-string 1 string))
1395 (epg-signature-set-creation-time
1397 (epg--time-from-seconds (match-string 2 string)))
1398 (unless (equal (match-string 3 string) "0")
1399 (epg-signature-set-expiration-time
1401 (epg--time-from-seconds (match-string 3 string))))
1402 (epg-signature-set-version
1404 (string-to-number (match-string 4 string)))
1405 (epg-signature-set-pubkey-algorithm
1407 (string-to-number (match-string 5 string)))
1408 (epg-signature-set-digest-algorithm
1410 (string-to-number (match-string 6 string)))
1411 (epg-signature-set-class
1413 (string-to-number (match-string 7 string) 16)))))
1415 (defun epg--status-TRUST_UNDEFINED (context string)
1416 (let ((signature (car (epg-context-result-for context 'verify))))
1418 (eq (epg-signature-status signature) 'good))
1419 (epg-signature-set-validity signature 'undefined))))
1421 (defun epg--status-TRUST_NEVER (context string)
1422 (let ((signature (car (epg-context-result-for context 'verify))))
1424 (eq (epg-signature-status signature) 'good))
1425 (epg-signature-set-validity signature 'never))))
1427 (defun epg--status-TRUST_MARGINAL (context string)
1428 (let ((signature (car (epg-context-result-for context 'verify))))
1430 (eq (epg-signature-status signature) 'marginal))
1431 (epg-signature-set-validity signature 'marginal))))
1433 (defun epg--status-TRUST_FULLY (context string)
1434 (let ((signature (car (epg-context-result-for context 'verify))))
1436 (eq (epg-signature-status signature) 'good))
1437 (epg-signature-set-validity signature 'full))))
1439 (defun epg--status-TRUST_ULTIMATE (context string)
1440 (let ((signature (car (epg-context-result-for context 'verify))))
1442 (eq (epg-signature-status signature) 'good))
1443 (epg-signature-set-validity signature 'ultimate))))
1445 (defun epg--status-NOTATION_NAME (context string)
1446 (let ((signature (car (epg-context-result-for context 'verify))))
1448 (epg-signature-set-notations
1450 (cons (epg-make-sig-notation string nil t nil)
1451 (epg-sig-notations signature))))))
1453 (defun epg--status-NOTATION_DATA (context string)
1454 (let ((signature (car (epg-context-result-for context 'verify)))
1457 (setq notation (car (epg-sig-notations signature))))
1458 (epg-sig-notation-set-value notation string))))
1460 (defun epg--status-POLICY_URL (context string)
1461 (let ((signature (car (epg-context-result-for context 'verify))))
1463 (epg-signature-set-notations
1465 (cons (epg-make-sig-notation nil string t nil)
1466 (epg-sig-notations signature))))))
1468 (defun epg--status-PROGRESS (context string)
1469 (if (and (epg-context-progress-callback context)
1470 (string-match "\\`\\([^ ]+\\) \\([^ ]\\) \\([0-9]+\\) \\([0-9]+\\)"
1472 (funcall (if (consp (epg-context-progress-callback context))
1473 (car (epg-context-progress-callback context))
1474 (epg-context-progress-callback context))
1476 (match-string 1 string)
1477 (match-string 2 string)
1478 (string-to-number (match-string 3 string))
1479 (string-to-number (match-string 4 string))
1480 (if (consp (epg-context-progress-callback context))
1481 (cdr (epg-context-progress-callback context))))))
1483 (defun epg--status-DECRYPTION_FAILED (context string)
1484 (epg-context-set-result-for context 'decryption-failed t))
1486 (defun epg--status-DECRYPTION_OKAY (context string)
1487 (epg-context-set-result-for context 'decryption-okay t))
1489 (defun epg--status-NODATA (context string)
1490 (epg-context-set-result-for
1492 (cons (cons 'no-data (string-to-number string))
1493 (epg-context-result-for context 'error))))
1495 (defun epg--status-UNEXPECTED (context string)
1496 (epg-context-set-result-for
1498 (cons (cons 'unexpected (string-to-number string))
1499 (epg-context-result-for context 'error))))
1501 (defun epg--status-KEYEXPIRED (context string)
1502 (epg-context-set-result-for
1504 (cons (list 'key-expired (cons 'expiration-time
1505 (epg--time-from-seconds string)))
1506 (epg-context-result-for context 'error))))
1508 (defun epg--status-KEYREVOKED (context string)
1509 (epg-context-set-result-for
1511 (cons '(key-revoked)
1512 (epg-context-result-for context 'error))))
1514 (defun epg--status-BADARMOR (context string)
1515 (epg-context-set-result-for
1518 (epg-context-result-for context 'error))))
1520 (defun epg--status-INV_RECP (context string)
1521 (if (string-match "\\`\\([0-9]+\\) \\(.*\\)" string)
1522 (epg-context-set-result-for
1524 (cons (list 'invalid-recipient
1526 (string-to-number (match-string 1 string)))
1527 (cons 'requested-recipient
1528 (match-string 2 string)))
1529 (epg-context-result-for context 'error)))))
1531 (defun epg--status-NO_RECP (context string)
1532 (epg-context-set-result-for
1534 (cons '(no-recipients)
1535 (epg-context-result-for context 'error))))
1537 (defun epg--status-DELETE_PROBLEM (context string)
1538 (if (string-match "\\`\\([0-9]+\\)" string)
1539 (epg-context-set-result-for
1541 (cons (cons 'delete-problem
1542 (string-to-number (match-string 1 string)))
1543 (epg-context-result-for context 'error)))))
1545 (defun epg--status-SIG_CREATED (context string)
1546 (if (string-match "\\`\\([DCS]\\) \\([0-9]+\\) \\([0-9]+\\) \
1547 \\([0-9A-Fa-F][0-9A-Fa-F]\\) \\(.*\\) " string)
1548 (epg-context-set-result-for
1550 (cons (epg-make-new-signature
1551 (cdr (assq (aref (match-string 1 string) 0)
1552 epg-new-signature-type-alist))
1553 (string-to-number (match-string 2 string))
1554 (string-to-number (match-string 3 string))
1555 (string-to-number (match-string 4 string) 16)
1556 (epg--time-from-seconds (match-string 5 string))
1557 (substring string (match-end 0)))
1558 (epg-context-result-for context 'sign)))))
1560 (defun epg--status-KEY_CREATED (context string)
1561 (if (string-match "\\`\\([BPS]\\) \\([^ ]+\\)" string)
1562 (epg-context-set-result-for
1563 context 'generate-key
1564 (cons (list (cons 'type (string-to-char (match-string 1 string)))
1565 (cons 'fingerprint (match-string 2 string)))
1566 (epg-context-result-for context 'generate-key)))))
1568 (defun epg--status-KEY_NOT_CREATED (context string)
1569 (epg-context-set-result-for
1571 (cons '(key-not-created)
1572 (epg-context-result-for context 'error))))
1574 (defun epg--status-IMPORTED (context string)
1575 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
1576 (let* ((key-id (match-string 1 string))
1577 (user-id (match-string 2 string))
1578 (entry (assoc key-id epg-user-id-alist)))
1580 (setcdr entry user-id)
1581 (setq epg-user-id-alist (cons (cons key-id user-id)
1582 epg-user-id-alist))))))
1584 (defun epg--status-IMPORT_OK (context string)
1585 (if (string-match "\\`\\([0-9]+\\)\\( \\(.+\\)\\)?" string)
1586 (let ((reason (string-to-number (match-string 1 string))))
1587 (epg-context-set-result-for
1588 context 'import-status
1589 (cons (epg-make-import-status (if (match-beginning 2)
1590 (match-string 3 string))
1592 (/= (logand reason 1) 0)
1593 (/= (logand reason 2) 0)
1594 (/= (logand reason 4) 0)
1595 (/= (logand reason 8) 0)
1596 (/= (logand reason 16) 0))
1597 (epg-context-result-for context 'import-status))))))
1599 (defun epg--status-IMPORT_PROBLEM (context string)
1600 (if (string-match "\\`\\([0-9]+\\)\\( \\(.+\\)\\)?" string)
1601 (epg-context-set-result-for
1602 context 'import-status
1603 (cons (epg-make-import-status
1604 (if (match-beginning 2)
1605 (match-string 3 string))
1606 (string-to-number (match-string 1 string)))
1607 (epg-context-result-for context 'import-status)))))
1609 (defun epg--status-IMPORT_RES (context string)
1610 (when (string-match "\\`\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \
1611 \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \
1612 \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" string)
1613 (epg-context-set-result-for
1615 (epg-make-import-result (string-to-number (match-string 1 string))
1616 (string-to-number (match-string 2 string))
1617 (string-to-number (match-string 3 string))
1618 (string-to-number (match-string 4 string))
1619 (string-to-number (match-string 5 string))
1620 (string-to-number (match-string 6 string))
1621 (string-to-number (match-string 7 string))
1622 (string-to-number (match-string 8 string))
1623 (string-to-number (match-string 9 string))
1624 (string-to-number (match-string 10 string))
1625 (string-to-number (match-string 11 string))
1626 (string-to-number (match-string 12 string))
1627 (string-to-number (match-string 13 string))
1628 (epg-context-result-for context 'import-status)))
1629 (epg-context-set-result-for context 'import-status nil)))
1631 (defun epg-passphrase-callback-function (context key-id handback)
1632 (if (eq key-id 'SYM)
1633 (read-passwd "Passphrase for symmetric encryption: "
1634 (eq (epg-context-operation context) 'encrypt))
1636 (if (eq key-id 'PIN)
1637 "Passphrase for PIN: "
1638 (let ((entry (assoc key-id epg-user-id-alist)))
1640 (format "Passphrase for %s %s: " key-id (cdr entry))
1641 (format "Passphrase for %s: " key-id)))))))
1643 (make-obsolete 'epg-passphrase-callback-function
1644 'epa-passphrase-callback-function)
1646 (defun epg--list-keys-1 (context name mode)
1647 (let ((args (append (if epg-gpg-home-directory
1648 (list "--homedir" epg-gpg-home-directory))
1649 (list "--with-colons" "--no-greeting" "--batch"
1650 "--with-fingerprint"
1651 "--with-fingerprint"
1652 (if (memq mode '(t secret))
1653 "--list-secret-keys"
1654 (if (memq mode '(nil public))
1657 (unless (eq (epg-context-protocol context) 'CMS)
1658 '("--fixed-list-mode"))
1659 (if name (list name))))
1660 keys string field index)
1662 (apply #'call-process
1663 (if (eq (epg-context-protocol context) 'CMS)
1666 nil (list t nil) nil args)
1667 (goto-char (point-min))
1668 (while (re-search-forward "^[a-z][a-z][a-z]:.*" nil t)
1669 (setq keys (cons (make-vector 15 nil) keys)
1670 string (match-string 0)
1674 (string-match "\\([^:]+\\)?:" string index))
1675 (setq index (match-end 0))
1676 (aset (car keys) field (match-string 1 string))
1677 (setq field (1+ field))))
1680 (defun epg--make-sub-key-1 (line)
1683 (cdr (assq (string-to-char (aref line 1)) epg-key-validity-alist)))
1685 (mapcar (lambda (char) (cdr (assq char epg-key-capablity-alist)))
1687 (member (aref line 0) '("sec" "ssb"))
1688 (string-to-number (aref line 3))
1689 (string-to-number (aref line 2))
1691 (epg--time-from-seconds (aref line 5))
1693 (epg--time-from-seconds (aref line 6)))))
1696 (defun epg-list-keys (context &optional name mode)
1697 "Return a list of epg-key objects matched with NAME.
1698 If MODE is nil or 'public, only public keyring should be searched.
1699 If MODE is t or 'secret, only secret keyring should be searched.
1700 Otherwise, only public keyring should be searched and the key
1701 signatures should be included."
1702 (let ((lines (epg--list-keys-1 context name mode))
1703 keys cert pointer pointer-1)
1706 ((member (aref (car lines) 0) '("pub" "sec" "crt" "crs"))
1707 (setq cert (member (aref (car lines) 0) '("crt" "crs"))
1708 keys (cons (epg-make-key
1709 (if (aref (car lines) 8)
1710 (cdr (assq (string-to-char (aref (car lines) 8))
1711 epg-key-validity-alist))))
1713 (epg-key-set-sub-key-list
1715 (cons (epg--make-sub-key-1 (car lines))
1716 (epg-key-sub-key-list (car keys)))))
1717 ((member (aref (car lines) 0) '("sub" "ssb"))
1718 (epg-key-set-sub-key-list
1720 (cons (epg--make-sub-key-1 (car lines))
1721 (epg-key-sub-key-list (car keys)))))
1722 ((equal (aref (car lines) 0) "uid")
1723 (epg-key-set-user-id-list
1725 (cons (epg-make-user-id
1726 (if (aref (car lines) 1)
1727 (cdr (assq (string-to-char (aref (car lines) 1))
1728 epg-key-validity-alist)))
1731 (epg-dn-from-string (aref (car lines) 9))
1732 (error (aref (car lines) 9)))
1733 (aref (car lines) 9)))
1734 (epg-key-user-id-list (car keys)))))
1735 ((equal (aref (car lines) 0) "fpr")
1736 (epg-sub-key-set-fingerprint (car (epg-key-sub-key-list (car keys)))
1737 (aref (car lines) 9)))
1738 ((equal (aref (car lines) 0) "sig")
1739 (epg-user-id-set-signature-list
1740 (car (epg-key-user-id-list (car keys)))
1742 (epg-make-key-signature
1743 (if (aref (car lines) 1)
1744 (cdr (assq (string-to-char (aref (car lines) 1))
1745 epg-key-validity-alist)))
1746 (string-to-number (aref (car lines) 3))
1747 (aref (car lines) 4)
1748 (epg--time-from-seconds (aref (car lines) 5))
1749 (epg--time-from-seconds (aref (car lines) 6))
1750 (aref (car lines) 9)
1751 (string-to-number (aref (car lines) 10) 16)
1752 (eq (aref (aref (car lines) 10) 2) ?x))
1753 (epg-user-id-signature-list
1754 (car (epg-key-user-id-list (car keys))))))))
1755 (setq lines (cdr lines)))
1756 (setq keys (nreverse keys)
1759 (epg-key-set-sub-key-list
1761 (nreverse (epg-key-sub-key-list (car pointer))))
1762 (setq pointer-1 (epg-key-set-user-id-list
1764 (nreverse (epg-key-user-id-list (car pointer)))))
1766 (epg-user-id-set-signature-list
1768 (nreverse (epg-user-id-signature-list (car pointer-1))))
1769 (setq pointer-1 (cdr pointer-1)))
1770 (setq pointer (cdr pointer)))
1773 (if (fboundp 'make-temp-file)
1774 (defalias 'epg--make-temp-file 'make-temp-file)
1775 (defvar temporary-file-directory)
1776 ;; stolen from poe.el.
1777 (defun epg--make-temp-file (prefix)
1778 "Create a temporary file.
1779 The returned file name (created by appending some random characters at the end
1780 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1781 is guaranteed to point to a newly created empty file.
1782 You can then use `write-region' to write new data into the file."
1783 (let (tempdir tempfile)
1784 (setq prefix (expand-file-name prefix
1785 (if (featurep 'xemacs)
1787 temporary-file-directory)))
1790 ;; First, create a temporary directory.
1791 (while (condition-case ()
1793 (setq tempdir (make-temp-name
1795 (file-name-directory prefix)
1797 ;; return nil or signal an error.
1798 (make-directory tempdir))
1800 (file-already-exists t)))
1801 (set-file-modes tempdir 448)
1802 ;; Second, create a temporary file in the tempdir.
1803 ;; There *is* a race condition between `make-temp-name'
1804 ;; and `write-region', but we don't care it since we are
1805 ;; in a private directory now.
1806 (setq tempfile (make-temp-name (concat tempdir "/EMU")))
1807 (write-region "" nil tempfile nil 'silent)
1808 (set-file-modes tempfile 384)
1809 ;; Finally, make a hard-link from the tempfile.
1810 (while (condition-case ()
1812 (setq file (make-temp-name prefix))
1813 ;; return nil or signal an error.
1814 (add-name-to-file tempfile file))
1816 (file-already-exists t)))
1818 ;; Cleanup the tempfile.
1820 (file-exists-p tempfile)
1821 (delete-file tempfile))
1822 ;; Cleanup the tempdir.
1824 (file-directory-p tempdir)
1825 (delete-directory tempdir))))))
1827 (if (fboundp 'clear-string)
1828 (defalias 'epg--clear-string 'clear-string)
1829 (defun epg--clear-string (string)
1830 (fillarray string 0)))
1832 (if (fboundp 'encode-coding-string)
1833 (defalias 'epg--encode-coding-string 'encode-coding-string)
1834 (defalias 'epg--encode-coding-string 'identity))
1836 (defun epg--args-from-sig-notations (notations)
1840 (if (and (epg-sig-notation-name notation)
1841 (not (epg-sig-notation-human-readable notation)))
1842 (error "Unreadable"))
1843 (if (epg-sig-notation-name notation)
1844 (list "--sig-notation"
1845 (if (epg-sig-notation-critical notation)
1846 (concat "!" (epg-sig-notation-name notation)
1847 "=" (epg-sig-notation-value notation))
1848 (concat (epg-sig-notation-name notation)
1849 "=" (epg-sig-notation-value notation))))
1850 (list "--sig-policy-url"
1851 (if (epg-sig-notation-critical notation)
1852 (concat "!" (epg-sig-notation-value notation))
1853 (epg-sig-notation-value notation)))))
1857 (defun epg-cancel (context)
1858 (if (buffer-live-p (process-buffer (epg-context-process context)))
1860 (set-buffer (process-buffer (epg-context-process context)))
1861 (epg-context-set-result-for
1864 (epg-context-result-for epg-context 'error)))))
1865 (if (eq (process-status (epg-context-process context)) 'run)
1866 (delete-process (epg-context-process context))))
1869 (defun epg-start-decrypt (context cipher)
1870 "Initiate a decrypt operation on CIPHER.
1871 CIPHER must be a file data object.
1873 If you use this function, you will need to wait for the completion of
1874 `epg-gpg-program' by using `epg-wait-for-completion' and call
1875 `epg-reset' to clear a temporaly output file.
1876 If you are unsure, use synchronous version of this function
1877 `epg-decrypt-file' or `epg-decrypt-string' instead."
1878 (unless (epg-data-file cipher)
1879 (error "Not a file"))
1880 (epg-context-set-operation context 'decrypt)
1881 (epg-context-set-result context nil)
1882 (epg--start context (list "--decrypt" "--" (epg-data-file cipher)))
1883 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
1884 (unless (eq (epg-context-protocol context) 'CMS)
1885 (epg-wait-for-status context '("BEGIN_DECRYPTION"))))
1887 (defun epg--check-error-for-decrypt (context)
1888 (if (epg-context-result-for context 'decryption-failed)
1889 (signal 'epg-error (list "Decryption failed")))
1890 (if (epg-context-result-for context 'no-secret-key)
1892 (list "No secret key"
1893 (epg-context-result-for context 'no-secret-key))))
1894 (unless (epg-context-result-for context 'decryption-okay)
1895 (let* ((error (epg-context-result-for context 'error)))
1896 (if (assq 'no-data error)
1897 (signal 'epg-error (list "No data")))
1898 (signal 'epg-error (list "Can't decrypt" error)))))
1901 (defun epg-decrypt-file (context cipher plain)
1902 "Decrypt a file CIPHER and store the result to a file PLAIN.
1903 If PLAIN is nil, it returns the result as a string."
1907 (epg-context-set-output-file context plain)
1908 (epg-context-set-output-file context
1909 (epg--make-temp-file "epg-output")))
1910 (epg-start-decrypt context (epg-make-data-from-file cipher))
1911 (epg-wait-for-completion context)
1912 (epg--check-error-for-decrypt context)
1914 (epg-read-output context)))
1916 (epg-delete-output-file context))
1917 (epg-reset context)))
1920 (defun epg-decrypt-string (context cipher)
1921 "Decrypt a string CIPHER and return the plain text."
1922 (let ((input-file (epg--make-temp-file "epg-input"))
1923 (coding-system-for-write 'binary))
1926 (write-region cipher nil input-file nil 'quiet)
1927 (epg-context-set-output-file context
1928 (epg--make-temp-file "epg-output"))
1929 (epg-start-decrypt context (epg-make-data-from-file input-file))
1930 (epg-wait-for-completion context)
1931 (epg--check-error-for-decrypt context)
1932 (epg-read-output context))
1933 (epg-delete-output-file context)
1934 (if (file-exists-p input-file)
1935 (delete-file input-file))
1936 (epg-reset context))))
1939 (defun epg-start-verify (context signature &optional signed-text)
1940 "Initiate a verify operation on SIGNATURE.
1941 SIGNATURE and SIGNED-TEXT are a data object if they are specified.
1943 For a detached signature, both SIGNATURE and SIGNED-TEXT should be set.
1944 For a normal or a cleartext signature, SIGNED-TEXT should be nil.
1946 If you use this function, you will need to wait for the completion of
1947 `epg-gpg-program' by using `epg-wait-for-completion' and call
1948 `epg-reset' to clear a temporaly output file.
1949 If you are unsure, use synchronous version of this function
1950 `epg-verify-file' or `epg-verify-string' instead."
1951 (epg-context-set-operation context 'verify)
1952 (epg-context-set-result context nil)
1954 ;; Detached signature.
1955 (if (epg-data-file signed-text)
1956 (epg--start context (list "--verify" "--" (epg-data-file signature)
1957 (epg-data-file signed-text)))
1958 (epg--start context (list "--verify" "--" (epg-data-file signature)
1960 (if (eq (process-status (epg-context-process context)) 'run)
1961 (process-send-string (epg-context-process context)
1962 (epg-data-string signed-text)))
1963 (if (eq (process-status (epg-context-process context)) 'run)
1964 (process-send-eof (epg-context-process context))))
1965 ;; Normal (or cleartext) signature.
1966 (if (epg-data-file signature)
1967 (epg--start context (list "--" (epg-data-file signature)))
1968 (epg--start context '("-"))
1969 (if (eq (process-status (epg-context-process context)) 'run)
1970 (process-send-string (epg-context-process context)
1971 (epg-data-string signature)))
1972 (if (eq (process-status (epg-context-process context)) 'run)
1973 (process-send-eof (epg-context-process context))))))
1976 (defun epg-verify-file (context signature &optional signed-text plain)
1977 "Verify a file SIGNATURE.
1978 SIGNED-TEXT and PLAIN are also a file if they are specified.
1980 For a detached signature, both SIGNATURE and SIGNED-TEXT should be
1981 string. For a normal or a cleartext signature, SIGNED-TEXT should be
1982 nil. In the latter case, if PLAIN is specified, the plaintext is
1983 stored into the file after successful verification."
1987 (epg-context-set-output-file context plain)
1988 (epg-context-set-output-file context
1989 (epg--make-temp-file "epg-output")))
1991 (epg-start-verify context
1992 (epg-make-data-from-file signature)
1993 (epg-make-data-from-file signed-text))
1994 (epg-start-verify context
1995 (epg-make-data-from-file signature)))
1996 (epg-wait-for-completion context)
1998 (epg-read-output context)))
2000 (epg-delete-output-file context))
2001 (epg-reset context)))
2004 (defun epg-verify-string (context signature &optional signed-text)
2005 "Verify a string SIGNATURE.
2006 SIGNED-TEXT is a string if it is specified.
2008 For a detached signature, both SIGNATURE and SIGNED-TEXT should be
2009 string. For a normal or a cleartext signature, SIGNED-TEXT should be
2010 nil. In the latter case, this function returns the plaintext after
2011 successful verification."
2012 (let ((coding-system-for-write 'binary)
2016 (epg-context-set-output-file context
2017 (epg--make-temp-file "epg-output"))
2020 (setq input-file (epg--make-temp-file "epg-signature"))
2021 (write-region signature nil input-file nil 'quiet)
2022 (epg-start-verify context
2023 (epg-make-data-from-file input-file)
2024 (epg-make-data-from-string signed-text)))
2025 (epg-start-verify context (epg-make-data-from-string signature)))
2026 (epg-wait-for-completion context)
2027 (epg-read-output context))
2028 (epg-delete-output-file context)
2030 (file-exists-p input-file))
2031 (delete-file input-file))
2032 (epg-reset context))))
2035 (defun epg-start-sign (context plain &optional mode)
2036 "Initiate a sign operation on PLAIN.
2037 PLAIN is a data object.
2039 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
2040 If it is nil or 'normal, it makes a normal signature.
2041 Otherwise, it makes a cleartext signature.
2043 If you use this function, you will need to wait for the completion of
2044 `epg-gpg-program' by using `epg-wait-for-completion' and call
2045 `epg-reset' to clear a temporaly output file.
2046 If you are unsure, use synchronous version of this function
2047 `epg-sign-file' or `epg-sign-string' instead."
2048 (epg-context-set-operation context 'sign)
2049 (epg-context-set-result context nil)
2050 (unless (memq mode '(t detached nil normal)) ;i.e. cleartext
2051 (epg-context-set-armor context nil)
2052 (epg-context-set-textmode context nil))
2054 (append (list (if (memq mode '(t detached))
2056 (if (memq mode '(nil normal))
2064 (car (epg-key-sub-key-list signer)))))
2065 (epg-context-signers context)))
2066 (epg--args-from-sig-notations
2067 (epg-context-sig-notations context))
2068 (if (epg-data-file plain)
2069 (list "--" (epg-data-file plain)))))
2070 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
2071 (unless (eq (epg-context-protocol context) 'CMS)
2072 (epg-wait-for-status context '("BEGIN_SIGNING")))
2073 (when (epg-data-string plain)
2074 (if (eq (process-status (epg-context-process context)) 'run)
2075 (process-send-string (epg-context-process context)
2076 (epg-data-string plain)))
2077 (if (eq (process-status (epg-context-process context)) 'run)
2078 (process-send-eof (epg-context-process context)))))
2081 (defun epg-sign-file (context plain signature &optional mode)
2082 "Sign a file PLAIN and store the result to a file SIGNATURE.
2083 If SIGNATURE is nil, it returns the result as a string.
2084 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
2085 If it is nil or 'normal, it makes a normal signature.
2086 Otherwise, it makes a cleartext signature."
2090 (epg-context-set-output-file context signature)
2091 (epg-context-set-output-file context
2092 (epg--make-temp-file "epg-output")))
2093 (epg-start-sign context (epg-make-data-from-file plain) mode)
2094 (epg-wait-for-completion context)
2095 (unless (epg-context-result-for context 'sign)
2096 (if (epg-context-result-for context 'error)
2097 (error "Sign failed: %S"
2098 (epg-context-result-for context 'error))
2099 (error "Sign failed")))
2101 (epg-read-output context)))
2103 (epg-delete-output-file context))
2104 (epg-reset context)))
2107 (defun epg-sign-string (context plain &optional mode)
2108 "Sign a string PLAIN and return the output as string.
2109 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
2110 If it is nil or 'normal, it makes a normal signature.
2111 Otherwise, it makes a cleartext signature."
2113 (unless (or (eq (epg-context-protocol context) 'CMS)
2116 (epg-check-configuration (epg-configuration))
2119 (epg--make-temp-file "epg-input")))
2120 (coding-system-for-write 'binary))
2123 (epg-context-set-output-file context
2124 (epg--make-temp-file "epg-output"))
2126 (write-region plain nil input-file nil 'quiet))
2127 (epg-start-sign context
2129 (epg-make-data-from-file input-file)
2130 (epg-make-data-from-string plain))
2132 (epg-wait-for-completion context)
2133 (unless (epg-context-result-for context 'sign)
2134 (if (epg-context-result-for context 'error)
2135 (error "Sign failed: %S"
2136 (epg-context-result-for context 'error))
2137 (error "Sign failed")))
2138 (epg-read-output context))
2139 (epg-delete-output-file context)
2141 (delete-file input-file))
2142 (epg-reset context))))
2145 (defun epg-start-encrypt (context plain recipients
2146 &optional sign always-trust)
2147 "Initiate an encrypt operation on PLAIN.
2148 PLAIN is a data object.
2149 If RECIPIENTS is nil, it performs symmetric encryption.
2151 If you use this function, you will need to wait for the completion of
2152 `epg-gpg-program' by using `epg-wait-for-completion' and call
2153 `epg-reset' to clear a temporaly output file.
2154 If you are unsure, use synchronous version of this function
2155 `epg-encrypt-file' or `epg-encrypt-string' instead."
2156 (epg-context-set-operation context 'encrypt)
2157 (epg-context-set-result context nil)
2159 (append (if always-trust '("--always-trust"))
2160 (if recipients '("--encrypt") '("--symmetric"))
2161 (if sign '("--sign"))
2168 (car (epg-key-sub-key-list
2170 (epg-context-signers context))))
2172 (epg--args-from-sig-notations
2173 (epg-context-sig-notations context)))
2179 (car (epg-key-sub-key-list recipient)))))
2181 (if (epg-data-file plain)
2182 (list "--" (epg-data-file plain)))))
2183 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
2184 (unless (eq (epg-context-protocol context) 'CMS)
2186 (epg-wait-for-status context '("BEGIN_SIGNING"))
2187 (epg-wait-for-status context '("BEGIN_ENCRYPTION"))))
2188 (when (epg-data-string plain)
2189 (if (eq (process-status (epg-context-process context)) 'run)
2190 (process-send-string (epg-context-process context)
2191 (epg-data-string plain)))
2192 (if (eq (process-status (epg-context-process context)) 'run)
2193 (process-send-eof (epg-context-process context)))))
2196 (defun epg-encrypt-file (context plain recipients
2197 cipher &optional sign always-trust)
2198 "Encrypt a file PLAIN and store the result to a file CIPHER.
2199 If CIPHER is nil, it returns the result as a string.
2200 If RECIPIENTS is nil, it performs symmetric encryption."
2204 (epg-context-set-output-file context cipher)
2205 (epg-context-set-output-file context
2206 (epg--make-temp-file "epg-output")))
2207 (epg-start-encrypt context (epg-make-data-from-file plain)
2208 recipients sign always-trust)
2209 (epg-wait-for-completion context)
2211 (not (epg-context-result-for context 'sign)))
2212 (if (epg-context-result-for context 'error)
2213 (error "Sign failed: %S"
2214 (epg-context-result-for context 'error))
2215 (error "Sign failed")))
2216 (if (epg-context-result-for context 'error)
2217 (error "Encrypt failed: %S"
2218 (epg-context-result-for context 'error)))
2220 (epg-read-output context)))
2222 (epg-delete-output-file context))
2223 (epg-reset context)))
2226 (defun epg-encrypt-string (context plain recipients
2227 &optional sign always-trust)
2228 "Encrypt a string PLAIN.
2229 If RECIPIENTS is nil, it performs symmetric encryption."
2231 (unless (or (not sign)
2232 (eq (epg-context-protocol context) 'CMS)
2235 (epg-check-configuration (epg-configuration))
2238 (epg--make-temp-file "epg-input")))
2239 (coding-system-for-write 'binary))
2242 (epg-context-set-output-file context
2243 (epg--make-temp-file "epg-output"))
2245 (write-region plain nil input-file nil 'quiet))
2246 (epg-start-encrypt context
2248 (epg-make-data-from-file input-file)
2249 (epg-make-data-from-string plain))
2250 recipients sign always-trust)
2251 (epg-wait-for-completion context)
2253 (not (epg-context-result-for context 'sign)))
2254 (if (epg-context-result-for context 'error)
2255 (error "Sign failed: %S"
2256 (epg-context-result-for context 'error))
2257 (error "Sign failed")))
2258 (if (epg-context-result-for context 'error)
2259 (error "Encrypt failed: %S"
2260 (epg-context-result-for context 'error)))
2261 (epg-read-output context))
2262 (epg-delete-output-file context)
2264 (delete-file input-file))
2265 (epg-reset context))))
2268 (defun epg-start-export-keys (context keys)
2269 "Initiate an export keys operation.
2271 If you use this function, you will need to wait for the completion of
2272 `epg-gpg-program' by using `epg-wait-for-completion' and call
2273 `epg-reset' to clear a temporaly output file.
2274 If you are unsure, use synchronous version of this function
2275 `epg-export-keys-to-file' or `epg-export-keys-to-string' instead."
2276 (epg-context-set-operation context 'export-keys)
2277 (epg-context-set-result context nil)
2278 (epg--start context (cons "--export"
2282 (car (epg-key-sub-key-list key))))
2286 (defun epg-export-keys-to-file (context keys file)
2287 "Extract public KEYS."
2291 (epg-context-set-output-file context file)
2292 (epg-context-set-output-file context
2293 (epg--make-temp-file "epg-output")))
2294 (epg-start-export-keys context keys)
2295 (epg-wait-for-completion context)
2296 (if (epg-context-result-for context 'error)
2297 (error "Export keys failed: %S"
2298 (epg-context-result-for context 'error)))
2300 (epg-read-output context)))
2302 (epg-delete-output-file context))
2303 (epg-reset context)))
2306 (defun epg-export-keys-to-string (context keys)
2307 "Extract public KEYS and return them as a string."
2308 (epg-export-keys-to-file context keys nil))
2311 (defun epg-start-import-keys (context keys)
2312 "Initiate an import keys operation.
2313 KEYS is a data object.
2315 If you use this function, you will need to wait for the completion of
2316 `epg-gpg-program' by using `epg-wait-for-completion' and call
2317 `epg-reset' to clear a temporaly output file.
2318 If you are unsure, use synchronous version of this function
2319 `epg-import-keys-from-file' or `epg-import-keys-from-string' instead."
2320 (epg-context-set-operation context 'import-keys)
2321 (epg-context-set-result context nil)
2322 (epg--start context (if (epg-data-file keys)
2323 (list "--import" "--" (epg-data-file keys))
2325 (when (epg-data-string keys)
2326 (if (eq (process-status (epg-context-process context)) 'run)
2327 (process-send-string (epg-context-process context)
2328 (epg-data-string keys)))
2329 (if (eq (process-status (epg-context-process context)) 'run)
2330 (process-send-eof (epg-context-process context)))))
2332 (defun epg--import-keys-1 (context keys)
2335 (epg-start-import-keys context keys)
2336 (epg-wait-for-completion context)
2337 (if (epg-context-result-for context 'error)
2338 (error "Import keys failed: %S"
2339 (epg-context-result-for context 'error))))
2340 (epg-reset context)))
2343 (defun epg-import-keys-from-file (context keys)
2344 "Add keys from a file KEYS."
2345 (epg--import-keys-1 context (epg-make-data-from-file keys)))
2348 (defun epg-import-keys-from-string (context keys)
2349 "Add keys from a string KEYS."
2350 (epg--import-keys-1 context (epg-make-data-from-string keys)))
2353 (defun epg-start-receive-keys (context key-id-list)
2354 "Initiate a receive key operation.
2355 KEY-ID-LIST is a list of key IDs.
2357 If you use this function, you will need to wait for the completion of
2358 `epg-gpg-program' by using `epg-wait-for-completion' and call
2359 `epg-reset' to clear a temporaly output file.
2360 If you are unsure, use synchronous version of this function
2361 `epg-generate-key-from-file' or `epg-generate-key-from-string' instead."
2362 (epg-context-set-operation context 'receive-keys)
2363 (epg-context-set-result context nil)
2364 (epg--start context (cons "--recv-keys" key-id-list)))
2367 (defun epg-receive-keys (context keys)
2368 "Add keys from server.
2369 KEYS is a list of key IDs"
2372 (epg-start-receive-keys context keys)
2373 (epg-wait-for-completion context)
2374 (if (epg-context-result-for context 'error)
2375 (error "Receive keys failed: %S"
2376 (epg-context-result-for context 'error))))
2377 (epg-reset context)))
2380 (defalias 'epg-import-keys-from-server 'epg-receive-keys)
2383 (defun epg-start-delete-keys (context keys &optional allow-secret)
2384 "Initiate an delete keys operation.
2386 If you use this function, you will need to wait for the completion of
2387 `epg-gpg-program' by using `epg-wait-for-completion' and call
2388 `epg-reset' to clear a temporaly output file.
2389 If you are unsure, use synchronous version of this function
2390 `epg-delete-keys' instead."
2391 (epg-context-set-operation context 'delete-keys)
2392 (epg-context-set-result context nil)
2393 (epg--start context (cons (if allow-secret
2394 "--delete-secret-key"
2399 (car (epg-key-sub-key-list key))))
2403 (defun epg-delete-keys (context keys &optional allow-secret)
2404 "Delete KEYS from the key ring."
2407 (epg-start-delete-keys context keys allow-secret)
2408 (epg-wait-for-completion context)
2409 (let ((entry (assq 'delete-problem
2410 (epg-context-result-for context 'error))))
2412 (if (setq entry (assq (cdr entry)
2413 epg-delete-problem-reason-alist))
2414 (error "Delete keys failed: %s" (cdr entry))
2415 (error "Delete keys failed")))))
2416 (epg-reset context)))
2419 (defun epg-start-sign-keys (context keys &optional local)
2420 "Initiate an sign keys operation.
2422 If you use this function, you will need to wait for the completion of
2423 `epg-gpg-program' by using `epg-wait-for-completion' and call
2424 `epg-reset' to clear a temporaly output file.
2425 If you are unsure, use synchronous version of this function
2426 `epg-sign-keys' instead."
2427 (epg-context-set-operation context 'sign-keys)
2428 (epg-context-set-result context nil)
2429 (epg--start context (cons (if local
2435 (car (epg-key-sub-key-list key))))
2437 (make-obsolete 'epg-start-sign-keys "Do not use.")
2440 (defun epg-sign-keys (context keys &optional local)
2441 "Sign KEYS from the key ring."
2444 (epg-start-sign-keys context keys local)
2445 (epg-wait-for-completion context)
2446 (if (epg-context-result-for context 'error)
2447 (error "Sign keys failed: %S"
2448 (epg-context-result-for context 'error))))
2449 (epg-reset context)))
2450 (make-obsolete 'epg-sign-keys "Do not use.")
2453 (defun epg-start-generate-key (context parameters)
2454 "Initiate a key generation.
2455 PARAMETERS specifies parameters for the key.
2457 If you use this function, you will need to wait for the completion of
2458 `epg-gpg-program' by using `epg-wait-for-completion' and call
2459 `epg-reset' to clear a temporaly output file.
2460 If you are unsure, use synchronous version of this function
2461 `epg-generate-key-from-file' or `epg-generate-key-from-string' instead."
2462 (epg-context-set-operation context 'generate-key)
2463 (epg-context-set-result context nil)
2464 (if (epg-data-file parameters)
2465 (epg--start context (list "--batch" "--genkey" "--"
2466 (epg-data-file parameters)))
2467 (epg--start context '("--batch" "--genkey"))
2468 (if (eq (process-status (epg-context-process context)) 'run)
2469 (process-send-string (epg-context-process context)
2470 (epg-data-string parameters)))
2471 (if (eq (process-status (epg-context-process context)) 'run)
2472 (process-send-eof (epg-context-process context)))))
2475 (defun epg-generate-key-from-file (context parameters)
2476 "Generate a new key pair.
2477 PARAMETERS is a file which tells how to create the key."
2480 (epg-start-generate-key context (epg-make-data-from-file parameters))
2481 (epg-wait-for-completion context)
2482 (if (epg-context-result-for context 'error)
2483 (error "Generate key failed: %S"
2484 (epg-context-result-for context 'error))))
2485 (epg-reset context)))
2488 (defun epg-generate-key-from-string (context parameters)
2489 "Generate a new key pair.
2490 PARAMETERS is a string which tells how to create the key."
2493 (epg-start-generate-key context (epg-make-data-from-string parameters))
2494 (epg-wait-for-completion context)
2495 (if (epg-context-result-for context 'error)
2496 (error "Generate key failed: %S"
2497 (epg-context-result-for context 'error))))
2498 (epg-reset context)))
2500 (defun epg--decode-hexstring (string)
2502 (while (eq index (string-match "[0-9A-Fa-f][0-9A-Fa-f]" string index))
2503 (setq string (replace-match "\\\\x\\&" t nil string)
2505 (car (read-from-string (concat "\"" string "\"")))))
2507 (defun epg--decode-quotedstring (string)
2509 (while (string-match "\\\\\\(\\([,=+<>#;\\\"]\\)\\|\
2510 \\([0-9A-Fa-f][0-9A-Fa-f]\\)\\|\\(.\\)\\)"
2512 (if (match-beginning 2)
2513 (setq string (replace-match "\\2" t nil string)
2515 (if (match-beginning 3)
2516 (setq string (replace-match "\\\\x\\3" t nil string)
2518 (setq string (replace-match "\\\\\\\\\\4" t nil string)
2519 index (+ index 3)))))
2520 (car (read-from-string (concat "\"" string "\"")))))
2522 (defun epg-dn-from-string (string)
2523 "Parse STRING as LADPv3 Distinguished Names (RFC2253).
2524 The return value is an alist mapping from types to values."
2526 (length (length string))
2527 alist type value group)
2528 (while (< index length)
2529 (if (eq index (string-match "[ \t\n\r]*" string index))
2530 (setq index (match-end 0)))
2531 (if (eq index (string-match
2532 "\\([0-9]+\\(\\.[0-9]+\\)*\\)\[ \t\n\r]*=[ \t\n\r]*"
2534 (setq type (match-string 1 string)
2535 index (match-end 0))
2536 (if (eq index (string-match "\\([0-9A-Za-z]+\\)[ \t\n\r]*=[ \t\n\r]*"
2538 (setq type (match-string 1 string)
2539 index (match-end 0))))
2541 (error "Invalid type"))
2542 (if (eq index (string-match
2543 "\\([^,=+<>#;\\\"]\\|\\\\.\\)+"
2545 (setq index (match-end 0)
2546 value (epg--decode-quotedstring (match-string 0 string)))
2547 (if (eq index (string-match "#\\([0-9A-Fa-f]+\\)" string index))
2548 (setq index (match-end 0)
2549 value (epg--decode-hexstring (match-string 1 string)))
2550 (if (eq index (string-match "\"\\([^\\\"]\\|\\\\.\\)*\""
2552 (setq index (match-end 0)
2553 value (epg--decode-quotedstring
2554 (match-string 0 string))))))
2556 (if (stringp (car (car alist)))
2557 (setcar alist (list (cons type value) (car alist)))
2558 (setcar alist (cons (cons type value) (car alist))))
2559 (if (consp (car (car alist)))
2560 (setcar alist (nreverse (car alist))))
2561 (setq alist (cons (cons type value) alist)
2564 (if (eq index (string-match "[ \t\n\r]*\\([,;+]\\)" string index))
2565 (setq index (match-end 0)
2566 group (eq (aref string (match-beginning 1)) ?+))))
2569 (defun epg-decode-dn (alist)
2570 "Convert ALIST returned by `epg-dn-from-string' to a human readable form.
2571 Type names are resolved using `epg-dn-type-alist'."
2574 (if (stringp (car rdn))
2575 (let ((entry (assoc (car rdn) epg-dn-type-alist)))
2577 (format "%s=%s" (cdr entry) (cdr rdn))
2578 (format "%s=%s" (car rdn) (cdr rdn))))
2579 (concat "(" (epg-decode-dn rdn) ")")))
2585 ;;; epg.el ends here