1 ;;; epg.el --- the EasyPG Library
2 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
3 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: PGP, GnuPG
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 (defvar epg-user-id nil
28 "GnuPG ID of your default identity.")
30 (defvar epg-user-id-alist nil
31 "An alist mapping from key ID to user ID.")
33 (defvar epg-last-status nil
)
34 (defvar epg-read-point nil
)
35 (defvar epg-process-filter-running nil
)
36 (defvar epg-pending-status-list nil
)
37 (defvar epg-key-id nil
)
38 (defvar epg-context nil
)
39 (defvar epg-debug-buffer nil
)
41 ;; from gnupg/include/cipher.h
42 (defconst epg-cipher-algorithm-alist
56 ;; from gnupg/include/cipher.h
57 (defconst epg-pubkey-algorithm-alist
65 ;; from gnupg/include/cipher.h
66 (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
)))
185 (defun epg-make-context (&optional protocol armor textmode include-certs
186 cipher-algorithm digest-algorithm
188 "Return a context object."
190 (vector (or protocol
'OpenPGP
) armor textmode include-certs
191 cipher-algorithm digest-algorithm compress-algorithm
192 (list #'epg-passphrase-callback-function
)
194 nil nil nil nil nil nil
)))
196 (defun epg-context-protocol (context)
197 "Return the protocol used within CONTEXT."
198 (unless (eq (car-safe context
) 'epg-context
)
199 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
200 (aref (cdr context
) 0))
202 (defun epg-context-armor (context)
203 "Return t if the output should be ASCII armored in CONTEXT."
204 (unless (eq (car-safe context
) 'epg-context
)
205 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
206 (aref (cdr context
) 1))
208 (defun epg-context-textmode (context)
209 "Return t if canonical text mode should be used in CONTEXT."
210 (unless (eq (car-safe context
) 'epg-context
)
211 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
212 (aref (cdr context
) 2))
214 (defun epg-context-include-certs (context)
215 "Return how many certificates should be included in an S/MIME signed message."
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 signing."
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 signing."
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 should 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
332 "Set the function used to query passphrase.
334 PASSPHRASE-CALLBACK is either a function, or a cons-cell whose
335 car is a function and cdr is a callback data.
337 The function gets three arguments: the context, the key-id in
338 question, and the callback data (if any)."
339 (unless (eq (car-safe context
) 'epg-context
)
340 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
341 (aset (cdr context
) 7 (if (consp passphrase-callback
)
343 (list passphrase-callback
))))
345 (defun epg-context-set-progress-callback (context
347 "Set the function which handles progress update.
349 PROGRESS-CALLBACK is either a function, or a cons-cell whose
350 car is a function and cdr is a callback data.
352 The function gets five arguments: the context, the operation
353 description, the character to display a progress unit, the
354 current amount done, the total amount to be done, and the
355 callback data (if any)."
356 (unless (eq (car-safe context
) 'epg-context
)
357 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
358 (aset (cdr context
) 8 (if (consp progress-callback
)
360 (list progress-callback
))))
362 (defun epg-context-set-signers (context signers
)
363 "Set the list of key-id for signing."
364 (unless (eq (car-safe context
) 'epg-context
)
365 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
366 (aset (cdr context
) 9 signers
))
368 (defun epg-context-set-sig-notations (context notations
)
369 "Set the list of notations for signing."
370 (unless (eq (car-safe context
) 'epg-context
)
371 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
372 (aset (cdr context
) 10 notations
))
374 (defun epg-context-set-process (context process
)
375 "Set the process object of `epg-gpg-program'.
376 This function is for internal use only."
377 (unless (eq (car-safe context
) 'epg-context
)
378 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
379 (aset (cdr context
) 11 process
))
381 (defun epg-context-set-output-file (context output-file
)
382 "Set the output file of `epg-gpg-program'.
383 This function is for internal use only."
384 (unless (eq (car-safe context
) 'epg-context
)
385 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
386 (aset (cdr context
) 12 output-file
))
388 (defun epg-context-set-result (context result
)
389 "Set the result of the previous cryptographic operation."
390 (unless (eq (car-safe context
) 'epg-context
)
391 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
392 (aset (cdr context
) 13 result
))
394 (defun epg-context-set-operation (context operation
)
395 "Set the name of the current cryptographic operation."
396 (unless (eq (car-safe context
) 'epg-context
)
397 (signal 'wrong-type-argument
(list 'epg-context-p context
)))
398 (aset (cdr context
) 14 operation
))
400 (defun epg-make-signature (status &optional key-id
)
401 "Return a signature object."
402 (cons 'epg-signature
(vector status key-id nil nil nil nil nil nil nil nil
405 (defun epg-signature-status (signature)
406 "Return the status code of SIGNATURE."
407 (unless (eq (car-safe signature
) 'epg-signature
)
408 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
409 (aref (cdr signature
) 0))
411 (defun epg-signature-key-id (signature)
412 "Return the key-id of SIGNATURE."
413 (unless (eq (car-safe signature
) 'epg-signature
)
414 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
415 (aref (cdr signature
) 1))
417 (defun epg-signature-validity (signature)
418 "Return the validity of SIGNATURE."
419 (unless (eq (car-safe signature
) 'epg-signature
)
420 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
421 (aref (cdr signature
) 2))
423 (defun epg-signature-fingerprint (signature)
424 "Return the fingerprint of SIGNATURE."
425 (unless (eq (car-safe signature
) 'epg-signature
)
426 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
427 (aref (cdr signature
) 3))
429 (defun epg-signature-creation-time (signature)
430 "Return the creation time of SIGNATURE."
431 (unless (eq (car-safe signature
) 'epg-signature
)
432 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
433 (aref (cdr signature
) 4))
435 (defun epg-signature-expiration-time (signature)
436 "Return the expiration time of SIGNATURE."
437 (unless (eq (car-safe signature
) 'epg-signature
)
438 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
439 (aref (cdr signature
) 5))
441 (defun epg-signature-pubkey-algorithm (signature)
442 "Return the public key algorithm of SIGNATURE."
443 (unless (eq (car-safe signature
) 'epg-signature
)
444 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
445 (aref (cdr signature
) 6))
447 (defun epg-signature-digest-algorithm (signature)
448 "Return the digest algorithm of SIGNATURE."
449 (unless (eq (car-safe signature
) 'epg-signature
)
450 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
451 (aref (cdr signature
) 7))
453 (defun epg-signature-class (signature)
454 "Return the class of SIGNATURE."
455 (unless (eq (car-safe signature
) 'epg-signature
)
456 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
457 (aref (cdr signature
) 8))
459 (defun epg-signature-version (signature)
460 "Return the version of SIGNATURE."
461 (unless (eq (car-safe signature
) 'epg-signature
)
462 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
463 (aref (cdr signature
) 9))
465 (defun epg-sig-notations (signature)
466 "Return the list of notations of SIGNATURE."
467 (unless (eq (car-safe signature
) 'epg-signature
)
468 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
469 (aref (cdr signature
) 10))
471 (defun epg-signature-set-status (signature status
)
472 "Set the status code of SIGNATURE."
473 (unless (eq (car-safe signature
) 'epg-signature
)
474 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
475 (aset (cdr signature
) 0 status
))
477 (defun epg-signature-set-key-id (signature key-id
)
478 "Set the key-id of SIGNATURE."
479 (unless (eq (car-safe signature
) 'epg-signature
)
480 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
481 (aset (cdr signature
) 1 key-id
))
483 (defun epg-signature-set-validity (signature validity
)
484 "Set the validity of SIGNATURE."
485 (unless (eq (car-safe signature
) 'epg-signature
)
486 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
487 (aset (cdr signature
) 2 validity
))
489 (defun epg-signature-set-fingerprint (signature fingerprint
)
490 "Set the fingerprint of SIGNATURE."
491 (unless (eq (car-safe signature
) 'epg-signature
)
492 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
493 (aset (cdr signature
) 3 fingerprint
))
495 (defun epg-signature-set-creation-time (signature creation-time
)
496 "Set the creation time of SIGNATURE."
497 (unless (eq (car-safe signature
) 'epg-signature
)
498 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
499 (aset (cdr signature
) 4 creation-time
))
501 (defun epg-signature-set-expiration-time (signature expiration-time
)
502 "Set the expiration time of SIGNATURE."
503 (unless (eq (car-safe signature
) 'epg-signature
)
504 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
505 (aset (cdr signature
) 5 expiration-time
))
507 (defun epg-signature-set-pubkey-algorithm (signature pubkey-algorithm
)
508 "Set the public key algorithm of SIGNATURE."
509 (unless (eq (car-safe signature
) 'epg-signature
)
510 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
511 (aset (cdr signature
) 6 pubkey-algorithm
))
513 (defun epg-signature-set-digest-algorithm (signature digest-algorithm
)
514 "Set the digest algorithm of SIGNATURE."
515 (unless (eq (car-safe signature
) 'epg-signature
)
516 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
517 (aset (cdr signature
) 7 digest-algorithm
))
519 (defun epg-signature-set-class (signature class
)
520 "Set the class of SIGNATURE."
521 (unless (eq (car-safe signature
) 'epg-signature
)
522 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
523 (aset (cdr signature
) 8 class
))
525 (defun epg-signature-set-version (signature version
)
526 "Set the version of SIGNATURE."
527 (unless (eq (car-safe signature
) 'epg-signature
)
528 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
529 (aset (cdr signature
) 9 version
))
531 (defun epg-signature-set-notations (signature notations
)
532 "Set the list of notations of SIGNATURE."
533 (unless (eq (car-safe signature
) 'epg-signature
)
534 (signal 'wrong-type-argument
(list 'epg-signature-p signature
)))
535 (aset (cdr signature
) 10 notations
))
537 (defun epg-make-new-signature (type pubkey-algorithm digest-algorithm
538 class creation-time fingerprint
)
539 "Return a new signature object."
540 (cons 'epg-new-signature
(vector type pubkey-algorithm digest-algorithm
541 class creation-time fingerprint
)))
543 (defun epg-new-signature-type (new-signature)
544 "Return the type 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
) 0))
549 (defun epg-new-signature-pubkey-algorithm (new-signature)
550 "Return the public key algorithm 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
) 1))
555 (defun epg-new-signature-digest-algorithm (new-signature)
556 "Return the digest algorithm 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
) 2))
561 (defun epg-new-signature-class (new-signature)
562 "Return the class 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
) 3))
567 (defun epg-new-signature-creation-time (new-signature)
568 "Return the creation time of NEW-SIGNATURE."
569 (unless (eq (car-safe new-signature
) 'epg-new-signature
)
570 (signal 'wrong-type-argument
(list 'epg-new-signature-p new-signature
)))
571 (aref (cdr new-signature
) 4))
573 (defun epg-new-signature-fingerprint (new-signature)
574 "Return the fingerprint of NEW-SIGNATURE."
575 (unless (eq (car-safe new-signature
) 'epg-new-signature
)
576 (signal 'wrong-type-argument
(list 'epg-new-signature-p new-signature
)))
577 (aref (cdr new-signature
) 5))
579 (defun epg-make-key (owner-trust)
580 "Return a key object."
581 (cons 'epg-key
(vector owner-trust nil nil
)))
583 (defun epg-key-owner-trust (key)
584 "Return the owner trust of KEY."
585 (unless (eq (car-safe key
) 'epg-key
)
586 (signal 'wrong-type-argument
(list 'epg-key-p key
)))
589 (defun epg-key-sub-key-list (key)
590 "Return the sub key list of KEY."
591 (unless (eq (car-safe key
) 'epg-key
)
592 (signal 'wrong-type-argument
(list 'epg-key-p key
)))
595 (defun epg-key-user-id-list (key)
596 "Return the user ID list of KEY."
597 (unless (eq (car-safe key
) 'epg-key
)
598 (signal 'wrong-type-argument
(list 'epg-key-p key
)))
601 (defun epg-key-set-sub-key-list (key sub-key-list
)
602 "Set the sub key list of KEY."
603 (unless (eq (car-safe key
) 'epg-key
)
604 (signal 'wrong-type-argument
(list 'epg-key-p key
)))
605 (aset (cdr key
) 1 sub-key-list
))
607 (defun epg-key-set-user-id-list (key user-id-list
)
608 "Set the user ID list of KEY."
609 (unless (eq (car-safe key
) 'epg-key
)
610 (signal 'wrong-type-argument
(list 'epg-key-p key
)))
611 (aset (cdr key
) 2 user-id-list
))
613 (defun epg-make-sub-key (validity capability secret-p algorithm length id
614 creation-time expiration-time
)
615 "Return a sub key object."
617 (vector validity capability secret-p algorithm length id creation-time
618 expiration-time nil
)))
620 (defun epg-sub-key-validity (sub-key)
621 "Return the validity of SUB-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
) 0))
626 (defun epg-sub-key-capability (sub-key)
627 "Return the capability 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
) 1))
632 (defun epg-sub-key-secret-p (sub-key)
633 "Return non-nil if SUB-KEY is a secret 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
) 2))
638 (defun epg-sub-key-algorithm (sub-key)
639 "Return the algorithm 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
) 3))
644 (defun epg-sub-key-length (sub-key)
645 "Return the length 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
) 4))
650 (defun epg-sub-key-id (sub-key)
651 "Return the ID 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
) 5))
656 (defun epg-sub-key-creation-time (sub-key)
657 "Return the creation time 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
) 6))
662 (defun epg-sub-key-expiration-time (sub-key)
663 "Return the expiration time of SUB-KEY."
664 (unless (eq (car-safe sub-key
) 'epg-sub-key
)
665 (signal 'wrong-type-argument
(list 'epg-sub-key-p sub-key
)))
666 (aref (cdr sub-key
) 7))
668 (defun epg-sub-key-fingerprint (sub-key)
669 "Return the fingerprint of SUB-KEY."
670 (unless (eq (car-safe sub-key
) 'epg-sub-key
)
671 (signal 'wrong-type-argument
(list 'epg-sub-key-p sub-key
)))
672 (aref (cdr sub-key
) 8))
674 (defun epg-sub-key-set-fingerprint (sub-key fingerprint
)
675 "Set the fingerprint of SUB-KEY.
676 This function is for internal use only."
677 (unless (eq (car-safe sub-key
) 'epg-sub-key
)
678 (signal 'wrong-type-argument
(list 'epg-sub-key-p sub-key
)))
679 (aset (cdr sub-key
) 8 fingerprint
))
681 (defun epg-make-user-id (validity string
)
682 "Return a user ID object."
683 (cons 'epg-user-id
(vector validity string nil
)))
685 (defun epg-user-id-validity (user-id)
686 "Return the validity 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
) 0))
691 (defun epg-user-id-string (user-id)
692 "Return the name 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 (aref (cdr user-id
) 1))
697 (defun epg-user-id-signature-list (user-id)
698 "Return the signature list of USER-ID."
699 (unless (eq (car-safe user-id
) 'epg-user-id
)
700 (signal 'wrong-type-argument
(list 'epg-user-id-p user-id
)))
701 (aref (cdr user-id
) 2))
703 (defun epg-user-id-set-signature-list (user-id signature-list
)
704 "Set the signature list of USER-ID."
705 (unless (eq (car-safe user-id
) 'epg-user-id
)
706 (signal 'wrong-type-argument
(list 'epg-user-id-p user-id
)))
707 (aset (cdr user-id
) 2 signature-list
))
709 (defun epg-make-key-signature (validity pubkey-algorithm key-id creation-time
710 expiration-time user-id class
712 "Return a key signature object."
713 (cons 'epg-key-signature
714 (vector validity pubkey-algorithm key-id creation-time expiration-time
715 user-id class exportable-p
)))
717 (defun epg-key-signature-validity (key-signature)
718 "Return the validity 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
) 0))
723 (defun epg-key-signature-pubkey-algorithm (key-signature)
724 "Return the public key algorithm 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
) 1))
729 (defun epg-key-signature-key-id (key-signature)
730 "Return the key-id 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
) 2))
735 (defun epg-key-signature-creation-time (key-signature)
736 "Return the creation time 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
) 3))
741 (defun epg-key-signature-expiration-time (key-signature)
742 "Return the expiration time 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
) 4))
747 (defun epg-key-signature-user-id (key-signature)
748 "Return the user-id of KEY-SIGNATURE."
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
) 5))
753 (defun epg-key-signature-class (key-signature)
754 "Return the class of KEY-SIGNATURE."
755 (unless (eq (car-safe key-signature
) 'epg-key-signature
)
756 (signal 'wrong-type-argument
(list 'epg-key-signature-p key-signature
)))
757 (aref (cdr key-signature
) 6))
759 (defun epg-key-signature-exportable-p (key-signature)
760 "Return t if KEY-SIGNATURE is exportable."
761 (unless (eq (car-safe key-signature
) 'epg-key-signature
)
762 (signal 'wrong-type-argument
(list 'epg-key-signature-p key-signature
)))
763 (aref (cdr key-signature
) 7))
765 (defun epg-make-sig-notation (name value
&optional human-readable
767 "Return a notation object."
768 (cons 'epg-sig-notation
(vector name value human-readable critical
)))
770 (defun epg-sig-notation-name (sig-notation)
771 "Return the name of SIG-NOTATION."
772 (unless (eq (car-safe sig-notation
) 'epg-sig-notation
)
773 (signal 'wrong-type-argument
(list 'epg-sig-notation-p
775 (aref (cdr sig-notation
) 0))
777 (defun epg-sig-notation-value (sig-notation)
778 "Return the value of SIG-NOTATION."
779 (unless (eq (car-safe sig-notation
) 'epg-sig-notation
)
780 (signal 'wrong-type-argument
(list 'epg-sig-notation-p
782 (aref (cdr sig-notation
) 1))
784 (defun epg-sig-notation-human-readable (sig-notation)
785 "Return the human-readable of SIG-NOTATION."
786 (unless (eq (car-safe sig-notation
) 'epg-sig-notation
)
787 (signal 'wrong-type-argument
(list 'epg-sig-notation-p
789 (aref (cdr sig-notation
) 2))
791 (defun epg-sig-notation-critical (sig-notation)
792 "Return the critical of SIG-NOTATION."
793 (unless (eq (car-safe sig-notation
) 'epg-sig-notation
)
794 (signal 'wrong-type-argument
(list 'epg-sig-notation-p
796 (aref (cdr sig-notation
) 3))
798 (defun epg-sig-notation-set-value (sig-notation value
)
799 "Set the value of SIG-NOTATION."
800 (unless (eq (car-safe sig-notation
) 'epg-sig-notation
)
801 (signal 'wrong-type-argument
(list 'epg-sig-notation-p
803 (aset (cdr sig-notation
) 1 value
))
805 (defun epg-make-import-status (fingerprint &optional reason new user-id
806 signature sub-key secret
)
807 "Return an import status object."
808 (cons 'epg-import-status
(vector fingerprint reason new user-id signature
811 (defun epg-import-status-fingerprint (import-status)
812 "Return the fingerprint of the key that was considered."
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
) 0))
817 (defun epg-import-status-reason (import-status)
818 "Return the reason code for import failure."
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
) 1))
823 (defun epg-import-status-new (import-status)
824 "Return t if the imported key was new."
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
) 2))
829 (defun epg-import-status-user-id (import-status)
830 "Return t if the imported key contained new user IDs."
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
) 3))
835 (defun epg-import-status-signature (import-status)
836 "Return t if the imported key contained new signatures."
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
) 4))
841 (defun epg-import-status-sub-key (import-status)
842 "Return t if the imported key contained new sub keys."
843 (unless (eq (car-safe import-status
) 'epg-import-status
)
844 (signal 'wrong-type-argument
(list 'epg-import-status-p import-status
)))
845 (aref (cdr import-status
) 5))
847 (defun epg-import-status-secret (import-status)
848 "Return t if the imported key contained a secret key."
849 (unless (eq (car-safe import-status
) 'epg-import-status
)
850 (signal 'wrong-type-argument
(list 'epg-import-status-p import-status
)))
851 (aref (cdr import-status
) 6))
853 (defun epg-make-import-result (considered no-user-id imported imported-rsa
854 unchanged new-user-ids new-sub-keys
855 new-signatures new-revocations
856 secret-read secret-imported
857 secret-unchanged not-imported
859 "Return an import result object."
860 (cons 'epg-import-result
(vector considered no-user-id imported imported-rsa
861 unchanged new-user-ids new-sub-keys
862 new-signatures new-revocations secret-read
863 secret-imported secret-unchanged
864 not-imported imports
)))
866 (defun epg-import-result-considered (import-result)
867 "Return the total number of considered 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
) 0))
872 (defun epg-import-result-no-user-id (import-result)
873 "Return the number of keys without user ID."
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
) 1))
878 (defun epg-import-result-imported (import-result)
879 "Return the number of imported 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
) 2))
884 (defun epg-import-result-imported-rsa (import-result)
885 "Return the number of imported RSA keys."
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
) 3))
890 (defun epg-import-result-unchanged (import-result)
891 "Return the number of unchanged 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
) 4))
896 (defun epg-import-result-new-user-ids (import-result)
897 "Return the number of new user IDs."
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
) 5))
902 (defun epg-import-result-new-sub-keys (import-result)
903 "Return the number of new sub keys."
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
) 6))
908 (defun epg-import-result-new-signatures (import-result)
909 "Return the number of new signatures."
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
) 7))
914 (defun epg-import-result-new-revocations (import-result)
915 "Return the number of new revocations."
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
) 8))
920 (defun epg-import-result-secret-read (import-result)
921 "Return the total number of secret keys read."
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
) 9))
926 (defun epg-import-result-secret-imported (import-result)
927 "Return the number of imported secret keys."
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
) 10))
932 (defun epg-import-result-secret-unchanged (import-result)
933 "Return the number of unchanged secret keys."
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
) 11))
938 (defun epg-import-result-not-imported (import-result)
939 "Return the number of keys not imported."
940 (unless (eq (car-safe import-result
) 'epg-import-result
)
941 (signal 'wrong-type-argument
(list 'epg-import-result-p import-result
)))
942 (aref (cdr import-result
) 12))
944 (defun epg-import-result-imports (import-result)
945 "Return the list of `epg-import-status' objects."
946 (unless (eq (car-safe import-result
) 'epg-import-result
)
947 (signal 'wrong-type-argument
(list 'epg-import-result-p import-result
)))
948 (aref (cdr import-result
) 13))
950 (defun epg-context-result-for (context name
)
951 "Return the result of CONTEXT associated with NAME."
952 (cdr (assq name
(epg-context-result context
))))
954 (defun epg-context-set-result-for (context name value
)
955 "Set the result of CONTEXT associated with NAME to VALUE."
956 (let* ((result (epg-context-result context
))
957 (entry (assq name result
)))
960 (epg-context-set-result context
(cons (cons name value
) result
)))))
962 (defun epg-signature-to-string (signature)
963 "Convert SIGNATURE to a human readable string."
964 (let* ((user-id (cdr (assoc (epg-signature-key-id signature
)
966 (pubkey-algorithm (epg-signature-pubkey-algorithm signature
)))
968 (cond ((eq (epg-signature-status signature
) 'good
)
969 "Good signature from ")
970 ((eq (epg-signature-status signature
) 'bad
)
971 "Bad signature from ")
972 ((eq (epg-signature-status signature
) 'expired
)
973 "Expired signature from ")
974 ((eq (epg-signature-status signature
) 'expired-key
)
975 "Signature made by expired key ")
976 ((eq (epg-signature-status signature
) 'revoked-key
)
977 "Signature made by revoked key ")
978 ((eq (epg-signature-status signature
) 'no-pubkey
)
979 "No public key for "))
980 (epg-signature-key-id signature
)
983 (if (stringp user-id
)
985 (epg-decode-dn user-id
)))
987 (if (epg-signature-validity signature
)
988 (format " (trust %s)" (epg-signature-validity signature
))
990 (if (epg-signature-creation-time signature
)
991 (format-time-string " created at %Y-%m-%dT%T%z"
992 (epg-signature-creation-time signature
))
996 (or (cdr (assq pubkey-algorithm epg-pubkey-algorithm-alist
))
997 (format "(unknown algorithm %d)" pubkey-algorithm
)))
1000 (defun epg-verify-result-to-string (verify-result)
1001 "Convert VERIFY-RESULT to a human readable string."
1002 (mapconcat #'epg-signature-to-string verify-result
"\n"))
1004 (defun epg-new-signature-to-string (new-signature)
1005 "Convert NEW-SIGNATURE to a human readable string."
1007 (cond ((eq (epg-new-signature-type new-signature
) 'detached
)
1008 "Detached signature ")
1009 ((eq (epg-new-signature-type new-signature
) 'clear
)
1010 "Cleartext signature ")
1013 (cdr (assq (epg-new-signature-pubkey-algorithm new-signature
)
1014 epg-pubkey-algorithm-alist
))
1016 (cdr (assq (epg-new-signature-digest-algorithm new-signature
)
1017 epg-digest-algorithm-alist
))
1019 (format "%02X " (epg-new-signature-class new-signature
))
1020 (epg-new-signature-fingerprint new-signature
)))
1022 (defun epg-import-result-to-string (import-result)
1023 "Convert IMPORT-RESULT to a human readable string."
1024 (concat (format "Total number processed: %d\n"
1025 (epg-import-result-considered import-result
))
1026 (if (> (epg-import-result-not-imported import-result
) 0)
1027 (format " skipped new keys: %d\n"
1028 (epg-import-result-not-imported import-result
)))
1029 (if (> (epg-import-result-no-user-id import-result
) 0)
1030 (format " w/o user IDs: %d\n"
1031 (epg-import-result-no-user-id import-result
)))
1032 (if (> (epg-import-result-imported import-result
) 0)
1033 (concat (format " imported: %d"
1034 (epg-import-result-imported import-result
))
1035 (if (> (epg-import-result-imported-rsa import-result
) 0)
1036 (format " (RSA: %d)"
1037 (epg-import-result-imported-rsa
1040 (if (> (epg-import-result-unchanged import-result
) 0)
1041 (format " unchanged: %d\n"
1042 (epg-import-result-unchanged import-result
)))
1043 (if (> (epg-import-result-new-user-ids import-result
) 0)
1044 (format " new user IDs: %d\n"
1045 (epg-import-result-new-user-ids import-result
)))
1046 (if (> (epg-import-result-new-sub-keys import-result
) 0)
1047 (format " new subkeys: %d\n"
1048 (epg-import-result-new-sub-keys import-result
)))
1049 (if (> (epg-import-result-new-signatures import-result
) 0)
1050 (format " new signatures: %d\n"
1051 (epg-import-result-new-signatures import-result
)))
1052 (if (> (epg-import-result-new-revocations import-result
) 0)
1053 (format " new key revocations: %d\n"
1054 (epg-import-result-new-revocations import-result
)))
1055 (if (> (epg-import-result-secret-read import-result
) 0)
1056 (format " secret keys read: %d\n"
1057 (epg-import-result-secret-read import-result
)))
1058 (if (> (epg-import-result-secret-imported import-result
) 0)
1059 (format " secret keys imported: %d\n"
1060 (epg-import-result-secret-imported import-result
)))
1061 (if (> (epg-import-result-secret-unchanged import-result
) 0)
1062 (format " secret keys unchanged: %d\n"
1063 (epg-import-result-secret-unchanged import-result
)))))
1065 (defun epg--start (context args
)
1066 "Start `epg-gpg-program' in a subprocess with given ARGS."
1067 (if (and (epg-context-process context
)
1068 (eq (process-status (epg-context-process context
)) 'run
))
1069 (error "%s is already running in this context"
1070 (if (eq (epg-context-protocol context
) 'CMS
)
1073 (let* ((args (append (list "--no-tty"
1076 (if (and (not (eq (epg-context-protocol context
) 'CMS
))
1077 (string-match ":" (or (getenv "GPG_AGENT_INFO")
1080 (if (and (not (eq (epg-context-protocol context
) 'CMS
))
1081 (epg-context-progress-callback context
))
1082 '("--enable-progress-filter"))
1083 (if epg-gpg-home-directory
1084 (list "--homedir" epg-gpg-home-directory
))
1085 (unless (eq (epg-context-protocol context
) 'CMS
)
1086 '("--command-fd" "0"))
1087 (if (epg-context-armor context
) '("--armor"))
1088 (if (epg-context-textmode context
) '("--textmode"))
1089 (if (epg-context-output-file context
)
1090 (list "--output" (epg-context-output-file context
)))
1092 (coding-system-for-write 'binary
)
1093 (coding-system-for-read 'binary
)
1094 process-connection-type
1095 (orig-mode (default-file-modes))
1096 (buffer (generate-new-buffer " *epg*"))
1100 (unless epg-debug-buffer
1101 (setq epg-debug-buffer
(generate-new-buffer " *epg-debug*")))
1102 (set-buffer epg-debug-buffer
)
1103 (goto-char (point-max))
1104 (insert (format "%s %s\n"
1105 (if (eq (epg-context-protocol context
) 'CMS
)
1108 (mapconcat #'identity args
" ")))))
1109 (with-current-buffer buffer
1110 (if (fboundp 'set-buffer-multibyte
)
1111 (set-buffer-multibyte nil
))
1112 (make-local-variable 'epg-last-status
)
1113 (setq epg-last-status nil
)
1114 (make-local-variable 'epg-read-point
)
1115 (setq epg-read-point
(point-min))
1116 (make-local-variable 'epg-process-filter-running
)
1117 (setq epg-process-filter-running nil
)
1118 (make-local-variable 'epg-pending-status-list
)
1119 (setq epg-pending-status-list nil
)
1120 (make-local-variable 'epg-key-id
)
1121 (setq epg-key-id nil
)
1122 (make-local-variable 'epg-context
)
1123 (setq epg-context context
))
1126 (set-default-file-modes 448)
1128 (apply #'start-process
"epg" buffer
1129 (if (eq (epg-context-protocol context
) 'CMS
)
1133 (set-default-file-modes orig-mode
))
1134 (set-process-filter process
#'epg--process-filter
)
1135 (epg-context-set-process context process
)))
1137 (defun epg--process-filter (process input
)
1140 (unless epg-debug-buffer
1141 (setq epg-debug-buffer
(generate-new-buffer " *epg-debug*")))
1142 (set-buffer epg-debug-buffer
)
1143 (goto-char (point-max))
1145 (if (buffer-live-p (process-buffer process
))
1147 (set-buffer (process-buffer process
))
1148 (goto-char (point-max))
1150 (unless epg-process-filter-running
1153 (setq epg-process-filter-running t
)
1154 (goto-char epg-read-point
)
1156 (while (looking-at ".*\n") ;the input line finished
1157 (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\) ?\\(.*\\)")
1158 (let* ((status (match-string 1))
1159 (string (match-string 2))
1160 (symbol (intern-soft (concat "epg--status-"
1162 (if (member status epg-pending-status-list
)
1163 (setq epg-pending-status-list nil
))
1166 (funcall symbol epg-context string
))
1167 (setq epg-last-status
(cons status string
))))
1169 (setq epg-read-point
(point))))
1170 (setq epg-process-filter-running nil
))))))
1172 (defun epg-read-output (context)
1173 "Read the output file CONTEXT and return the content as a string."
1175 (if (fboundp 'set-buffer-multibyte
)
1176 (set-buffer-multibyte nil
))
1177 (if (file-exists-p (epg-context-output-file context
))
1178 (let ((coding-system-for-read 'binary
))
1179 (insert-file-contents (epg-context-output-file context
))
1182 (defun epg-wait-for-status (context status-list
)
1183 "Wait until one of elements in STATUS-LIST arrives."
1184 (with-current-buffer (process-buffer (epg-context-process context
))
1185 (setq epg-pending-status-list status-list
)
1186 (while (and (eq (process-status (epg-context-process context
)) 'run
)
1187 epg-pending-status-list
)
1188 (accept-process-output (epg-context-process context
) 1))
1189 (if epg-pending-status-list
1190 (epg-context-set-result-for context
'error
'exit
))))
1192 (defun epg-wait-for-completion (context)
1193 "Wait until the `epg-gpg-program' process completes."
1194 (while (eq (process-status (epg-context-process context
)) 'run
)
1195 (accept-process-output (epg-context-process context
) 1))
1196 ;; This line is needed to run the process-filter right now.
1199 (defun epg-reset (context)
1200 "Reset the CONTEXT."
1201 (if (and (epg-context-process context
)
1202 (buffer-live-p (process-buffer (epg-context-process context
))))
1203 (kill-buffer (process-buffer (epg-context-process context
))))
1204 (epg-context-set-process context nil
))
1206 (defun epg-delete-output-file (context)
1207 "Delete the output file of CONTEXT."
1208 (if (and (epg-context-output-file context
)
1209 (file-exists-p (epg-context-output-file context
)))
1210 (delete-file (epg-context-output-file context
))))
1213 (if (fboundp 'decode-coding-string
)
1214 (defalias 'epg--decode-coding-string
'decode-coding-string
)
1215 (defalias 'epg--decode-coding-string
'identity
)))
1217 (defun epg--status-USERID_HINT (context string
)
1218 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string
)
1219 (let* ((key-id (match-string 1 string
))
1220 (user-id (match-string 2 string
))
1221 (entry (assoc key-id epg-user-id-alist
)))
1223 (setq user-id
(epg--decode-coding-string
1224 (epg--decode-percent-escape user-id
)
1228 (setcdr entry user-id
)
1229 (setq epg-user-id-alist
(cons (cons key-id user-id
)
1230 epg-user-id-alist
))))))
1232 (defun epg--status-NEED_PASSPHRASE (context string
)
1233 (if (string-match "\\`\\([^ ]+\\)" string
)
1234 (setq epg-key-id
(match-string 1 string
))))
1236 (defun epg--status-NEED_PASSPHRASE_SYM (context string
)
1237 (setq epg-key-id
'SYM
))
1239 (defun epg--status-NEED_PASSPHRASE_PIN (context string
)
1240 (setq epg-key-id
'PIN
))
1243 (if (fboundp 'clear-string
)
1244 (defalias 'epg--clear-string
'clear-string
)
1245 (defun epg--clear-string (string)
1246 (fillarray string
0))))
1249 (if (fboundp 'encode-coding-string
)
1250 (defalias 'epg--encode-coding-string
'encode-coding-string
)
1251 (defalias 'epg--encode-coding-string
'identity
)))
1253 (defun epg--status-GET_HIDDEN (context string
)
1254 (when (and epg-key-id
1255 (string-match "\\`passphrase\\." string
))
1256 (unless (epg-context-passphrase-callback context
)
1257 (error "passphrase-callback not set"))
1260 passphrase-with-new-line
1261 encoded-passphrase-with-new-line
)
1267 (car (epg-context-passphrase-callback context
))
1270 (cdr (epg-context-passphrase-callback context
))))
1272 (setq passphrase-with-new-line
(concat passphrase
"\n"))
1273 (epg--clear-string passphrase
)
1274 (setq passphrase nil
)
1275 (if epg-passphrase-coding-system
1277 (setq encoded-passphrase-with-new-line
1278 (epg--encode-coding-string
1279 passphrase-with-new-line
1280 (coding-system-change-eol-conversion
1281 epg-passphrase-coding-system
'unix
)))
1282 (epg--clear-string passphrase-with-new-line
)
1283 (setq passphrase-with-new-line nil
))
1284 (setq encoded-passphrase-with-new-line
1285 passphrase-with-new-line
1286 passphrase-with-new-line nil
))
1287 (process-send-string (epg-context-process context
)
1288 encoded-passphrase-with-new-line
)))
1290 (epg-context-set-result-for
1293 (epg-context-result-for context
'error
)))
1294 (delete-process (epg-context-process context
))))
1296 (epg--clear-string passphrase
))
1297 (if passphrase-with-new-line
1298 (epg--clear-string passphrase-with-new-line
))
1299 (if encoded-passphrase-with-new-line
1300 (epg--clear-string encoded-passphrase-with-new-line
))))))
1302 (defun epg--prompt-GET_BOOL (context string
)
1303 (let ((entry (assoc string epg-prompt-alist
)))
1304 (y-or-n-p (if entry
(cdr entry
) (concat string
"? ")))))
1306 (defun epg--prompt-GET_BOOL-untrusted_key.override
(context string
)
1307 (y-or-n-p (if (and (equal (car epg-last-status
) "USERID_HINT")
1308 (string-match "\\`\\([^ ]+\\) \\(.*\\)"
1309 (cdr epg-last-status
)))
1310 (let* ((key-id (match-string 1 (cdr epg-last-status
)))
1311 (user-id (match-string 2 (cdr epg-last-status
)))
1312 (entry (assoc key-id epg-user-id-alist
)))
1314 (setq user-id
(cdr entry
)))
1315 (format "Untrusted key %s %s. Use anyway? " key-id user-id
))
1316 "Use untrusted key anyway? ")))
1318 (defun epg--status-GET_BOOL (context string
)
1321 (if (funcall (or (intern-soft (concat "epg--prompt-GET_BOOL-" string
))
1322 #'epg--prompt-GET_BOOL
)
1324 (process-send-string (epg-context-process context
) "y\n")
1325 (process-send-string (epg-context-process context
) "n\n"))
1327 (epg-context-set-result-for
1330 (epg-context-result-for context
'error
)))
1331 (delete-process (epg-context-process context
))))))
1333 (defun epg--status-GET_LINE (context string
)
1334 (let ((entry (assoc string epg-prompt-alist
))
1337 (process-send-string (epg-context-process context
)
1338 (concat (read-string
1341 (concat string
": ")))
1344 (epg-context-set-result-for
1347 (epg-context-result-for context
'error
)))
1348 (delete-process (epg-context-process context
))))))
1350 (defun epg--status-*SIG
(context status string
)
1351 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string
)
1352 (let* ((key-id (match-string 1 string
))
1353 (user-id (match-string 2 string
))
1354 (entry (assoc key-id epg-user-id-alist
)))
1355 (epg-context-set-result-for
1358 (cons (epg-make-signature status key-id
)
1359 (epg-context-result-for context
'verify
)))
1361 (if (eq (epg-context-protocol context
) 'CMS
)
1362 (setq user-id
(epg-dn-from-string user-id
))
1363 (setq user-id
(epg--decode-coding-string
1364 (epg--decode-percent-escape user-id
)
1368 (setcdr entry user-id
)
1369 (setq epg-user-id-alist
1370 (cons (cons key-id user-id
) epg-user-id-alist
))))
1371 (epg-context-set-result-for
1374 (cons (epg-make-signature status
)
1375 (epg-context-result-for context
'verify
)))))
1377 (defun epg--status-GOODSIG (context string
)
1378 (epg--status-*SIG context
'good string
))
1380 (defun epg--status-EXPSIG (context string
)
1381 (epg--status-*SIG context
'expired string
))
1383 (defun epg--status-EXPKEYSIG (context string
)
1384 (epg--status-*SIG context
'expired-key string
))
1386 (defun epg--status-REVKEYSIG (context string
)
1387 (epg--status-*SIG context
'revoked-key string
))
1389 (defun epg--status-BADSIG (context string
)
1390 (epg--status-*SIG context
'bad string
))
1392 (defun epg--status-NO_PUBKEY (context string
)
1393 (let ((signature (car (epg-context-result-for context
'verify
))))
1395 (eq (epg-signature-status signature
) 'error
)
1396 (equal (epg-signature-key-id signature
) string
))
1397 (epg-signature-set-status signature
'no-pubkey
))))
1399 (defun epg--time-from-seconds (seconds)
1400 (let ((number-seconds (string-to-number (concat seconds
".0"))))
1401 (cons (floor (/ number-seconds
65536))
1402 (floor (mod number-seconds
65536)))))
1404 (defun epg--status-ERRSIG (context string
)
1405 (if (string-match "\\`\\([^ ]+\\) \\([0-9]+\\) \\([0-9]+\\) \
1406 \\([0-9A-Fa-f][0-9A-Fa-f]\\) \\([^ ]+\\) \\([0-9]+\\)"
1408 (let ((signature (epg-make-signature 'error
)))
1409 (epg-context-set-result-for
1413 (epg-context-result-for context
'verify
)))
1414 (epg-signature-set-key-id
1416 (match-string 1 string
))
1417 (epg-signature-set-pubkey-algorithm
1419 (string-to-number (match-string 2 string
)))
1420 (epg-signature-set-digest-algorithm
1422 (string-to-number (match-string 3 string
)))
1423 (epg-signature-set-class
1425 (string-to-number (match-string 4 string
) 16))
1426 (epg-signature-set-creation-time
1428 (epg--time-from-seconds (match-string 5 string
))))))
1430 (defun epg--status-VALIDSIG (context string
)
1431 (let ((signature (car (epg-context-result-for context
'verify
))))
1432 (when (and signature
1433 (eq (epg-signature-status signature
) 'good
)
1434 (string-match "\\`\\([^ ]+\\) [^ ]+ \\([^ ]+\\) \\([^ ]+\\) \
1435 \\([0-9]+\\) [^ ]+ \\([0-9]+\\) \\([0-9]+\\) \\([0-9A-Fa-f][0-9A-Fa-f]\\) \
1438 (epg-signature-set-fingerprint
1440 (match-string 1 string
))
1441 (epg-signature-set-creation-time
1443 (epg--time-from-seconds (match-string 2 string
)))
1444 (unless (equal (match-string 3 string
) "0")
1445 (epg-signature-set-expiration-time
1447 (epg--time-from-seconds (match-string 3 string
))))
1448 (epg-signature-set-version
1450 (string-to-number (match-string 4 string
)))
1451 (epg-signature-set-pubkey-algorithm
1453 (string-to-number (match-string 5 string
)))
1454 (epg-signature-set-digest-algorithm
1456 (string-to-number (match-string 6 string
)))
1457 (epg-signature-set-class
1459 (string-to-number (match-string 7 string
) 16)))))
1461 (defun epg--status-TRUST_UNDEFINED (context string
)
1462 (let ((signature (car (epg-context-result-for context
'verify
))))
1464 (eq (epg-signature-status signature
) 'good
))
1465 (epg-signature-set-validity signature
'undefined
))))
1467 (defun epg--status-TRUST_NEVER (context string
)
1468 (let ((signature (car (epg-context-result-for context
'verify
))))
1470 (eq (epg-signature-status signature
) 'good
))
1471 (epg-signature-set-validity signature
'never
))))
1473 (defun epg--status-TRUST_MARGINAL (context string
)
1474 (let ((signature (car (epg-context-result-for context
'verify
))))
1476 (eq (epg-signature-status signature
) 'marginal
))
1477 (epg-signature-set-validity signature
'marginal
))))
1479 (defun epg--status-TRUST_FULLY (context string
)
1480 (let ((signature (car (epg-context-result-for context
'verify
))))
1482 (eq (epg-signature-status signature
) 'good
))
1483 (epg-signature-set-validity signature
'full
))))
1485 (defun epg--status-TRUST_ULTIMATE (context string
)
1486 (let ((signature (car (epg-context-result-for context
'verify
))))
1488 (eq (epg-signature-status signature
) 'good
))
1489 (epg-signature-set-validity signature
'ultimate
))))
1491 (defun epg--status-NOTATION_NAME (context string
)
1492 (let ((signature (car (epg-context-result-for context
'verify
))))
1494 (epg-signature-set-notations
1496 (cons (epg-make-sig-notation string nil t nil
)
1497 (epg-sig-notations signature
))))))
1499 (defun epg--status-NOTATION_DATA (context string
)
1500 (let ((signature (car (epg-context-result-for context
'verify
)))
1503 (setq notation
(car (epg-sig-notations signature
))))
1504 (epg-sig-notation-set-value notation string
))))
1506 (defun epg--status-POLICY_URL (context string
)
1507 (let ((signature (car (epg-context-result-for context
'verify
))))
1509 (epg-signature-set-notations
1511 (cons (epg-make-sig-notation nil string t nil
)
1512 (epg-sig-notations signature
))))))
1514 (defun epg--status-PROGRESS (context string
)
1515 (if (and (epg-context-progress-callback context
)
1516 (string-match "\\`\\([^ ]+\\) \\([^ ]\\) \\([0-9]+\\) \\([0-9]+\\)"
1518 (funcall (car (epg-context-progress-callback context
))
1520 (match-string 1 string
)
1521 (match-string 2 string
)
1522 (string-to-number (match-string 3 string
))
1523 (string-to-number (match-string 4 string
))
1524 (cdr (epg-context-progress-callback context
)))))
1526 (defun epg--status-ENC_TO (context string
)
1527 (if (string-match "\\`\\([0-9A-Za-z]+\\) \\([0-9]+\\) \\([0-9]+\\)" string
)
1528 (epg-context-set-result-for
1529 context
'encrypted-to
1530 (cons (list (match-string 1 string
)
1531 (string-to-number (match-string 2 string
))
1532 (string-to-number (match-string 3 string
)))
1533 (epg-context-result-for context
'encrypted-to
)))))
1535 (defun epg--status-DECRYPTION_FAILED (context string
)
1536 (epg-context-set-result-for context
'decryption-failed t
))
1538 (defun epg--status-DECRYPTION_OKAY (context string
)
1539 (epg-context-set-result-for context
'decryption-okay t
))
1541 (defun epg--status-NODATA (context string
)
1542 (epg-context-set-result-for
1544 (cons (cons 'no-data
(string-to-number string
))
1545 (epg-context-result-for context
'error
))))
1547 (defun epg--status-UNEXPECTED (context string
)
1548 (epg-context-set-result-for
1550 (cons (cons 'unexpected
(string-to-number string
))
1551 (epg-context-result-for context
'error
))))
1553 (defun epg--status-KEYEXPIRED (context string
)
1554 (epg-context-set-result-for
1556 (cons (list 'key-expired
(cons 'expiration-time
1557 (epg--time-from-seconds string
)))
1558 (epg-context-result-for context
'error
))))
1560 (defun epg--status-KEYREVOKED (context string
)
1561 (epg-context-set-result-for
1563 (cons '(key-revoked)
1564 (epg-context-result-for context
'error
))))
1566 (defun epg--status-BADARMOR (context string
)
1567 (epg-context-set-result-for
1570 (epg-context-result-for context
'error
))))
1572 (defun epg--status-INV_RECP (context string
)
1573 (if (string-match "\\`\\([0-9]+\\) \\(.*\\)" string
)
1574 (epg-context-set-result-for
1576 (cons (list 'invalid-recipient
1578 (string-to-number (match-string 1 string
)))
1579 (cons 'requested-recipient
1580 (match-string 2 string
)))
1581 (epg-context-result-for context
'error
)))))
1583 (defun epg--status-NO_RECP (context string
)
1584 (epg-context-set-result-for
1586 (cons '(no-recipients)
1587 (epg-context-result-for context
'error
))))
1589 (defun epg--status-DELETE_PROBLEM (context string
)
1590 (if (string-match "\\`\\([0-9]+\\)" string
)
1591 (epg-context-set-result-for
1593 (cons (cons 'delete-problem
1594 (string-to-number (match-string 1 string
)))
1595 (epg-context-result-for context
'error
)))))
1597 (defun epg--status-SIG_CREATED (context string
)
1598 (if (string-match "\\`\\([DCS]\\) \\([0-9]+\\) \\([0-9]+\\) \
1599 \\([0-9A-Fa-F][0-9A-Fa-F]\\) \\(.*\\) " string
)
1600 (epg-context-set-result-for
1602 (cons (epg-make-new-signature
1603 (cdr (assq (aref (match-string 1 string
) 0)
1604 epg-new-signature-type-alist
))
1605 (string-to-number (match-string 2 string
))
1606 (string-to-number (match-string 3 string
))
1607 (string-to-number (match-string 4 string
) 16)
1608 (epg--time-from-seconds (match-string 5 string
))
1609 (substring string
(match-end 0)))
1610 (epg-context-result-for context
'sign
)))))
1612 (defun epg--status-KEY_CREATED (context string
)
1613 (if (string-match "\\`\\([BPS]\\) \\([^ ]+\\)" string
)
1614 (epg-context-set-result-for
1615 context
'generate-key
1616 (cons (list (cons 'type
(string-to-char (match-string 1 string
)))
1617 (cons 'fingerprint
(match-string 2 string
)))
1618 (epg-context-result-for context
'generate-key
)))))
1620 (defun epg--status-KEY_NOT_CREATED (context string
)
1621 (epg-context-set-result-for
1623 (cons '(key-not-created)
1624 (epg-context-result-for context
'error
))))
1626 (defun epg--status-IMPORTED (context string
)
1627 (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string
)
1628 (let* ((key-id (match-string 1 string
))
1629 (user-id (match-string 2 string
))
1630 (entry (assoc key-id epg-user-id-alist
)))
1632 (setq user-id
(epg--decode-coding-string
1633 (epg--decode-percent-escape user-id
)
1637 (setcdr entry user-id
)
1638 (setq epg-user-id-alist
(cons (cons key-id user-id
)
1639 epg-user-id-alist
))))))
1641 (defun epg--status-IMPORT_OK (context string
)
1642 (if (string-match "\\`\\([0-9]+\\)\\( \\(.+\\)\\)?" string
)
1643 (let ((reason (string-to-number (match-string 1 string
))))
1644 (epg-context-set-result-for
1645 context
'import-status
1646 (cons (epg-make-import-status (if (match-beginning 2)
1647 (match-string 3 string
))
1649 (/= (logand reason
1) 0)
1650 (/= (logand reason
2) 0)
1651 (/= (logand reason
4) 0)
1652 (/= (logand reason
8) 0)
1653 (/= (logand reason
16) 0))
1654 (epg-context-result-for context
'import-status
))))))
1656 (defun epg--status-IMPORT_PROBLEM (context string
)
1657 (if (string-match "\\`\\([0-9]+\\)\\( \\(.+\\)\\)?" string
)
1658 (epg-context-set-result-for
1659 context
'import-status
1660 (cons (epg-make-import-status
1661 (if (match-beginning 2)
1662 (match-string 3 string
))
1663 (string-to-number (match-string 1 string
)))
1664 (epg-context-result-for context
'import-status
)))))
1666 (defun epg--status-IMPORT_RES (context string
)
1667 (when (string-match "\\`\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \
1668 \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\) \
1669 \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" string
)
1670 (epg-context-set-result-for
1672 (epg-make-import-result (string-to-number (match-string 1 string
))
1673 (string-to-number (match-string 2 string
))
1674 (string-to-number (match-string 3 string
))
1675 (string-to-number (match-string 4 string
))
1676 (string-to-number (match-string 5 string
))
1677 (string-to-number (match-string 6 string
))
1678 (string-to-number (match-string 7 string
))
1679 (string-to-number (match-string 8 string
))
1680 (string-to-number (match-string 9 string
))
1681 (string-to-number (match-string 10 string
))
1682 (string-to-number (match-string 11 string
))
1683 (string-to-number (match-string 12 string
))
1684 (string-to-number (match-string 13 string
))
1685 (epg-context-result-for context
'import-status
)))
1686 (epg-context-set-result-for context
'import-status nil
)))
1688 (defun epg-passphrase-callback-function (context key-id handback
)
1689 (if (eq key-id
'SYM
)
1690 (read-passwd "Passphrase for symmetric encryption: "
1691 (eq (epg-context-operation context
) 'encrypt
))
1693 (if (eq key-id
'PIN
)
1694 "Passphrase for PIN: "
1695 (let ((entry (assoc key-id epg-user-id-alist
)))
1697 (format "Passphrase for %s %s: " key-id
(cdr entry
))
1698 (format "Passphrase for %s: " key-id
)))))))
1700 (make-obsolete 'epg-passphrase-callback-function
1701 'epa-passphrase-callback-function
"23.1")
1703 (defun epg--list-keys-1 (context name mode
)
1704 (let ((args (append (if epg-gpg-home-directory
1705 (list "--homedir" epg-gpg-home-directory
))
1706 '("--with-colons" "--no-greeting" "--batch"
1707 "--with-fingerprint" "--with-fingerprint")
1708 (unless (eq (epg-context-protocol context
) 'CMS
)
1709 '("--fixed-list-mode"))))
1710 (list-keys-option (if (memq mode
'(t secret
))
1711 "--list-secret-keys"
1712 (if (memq mode
'(nil public
))
1715 (coding-system-for-read 'binary
)
1716 keys string field index
)
1719 (unless (listp name
)
1720 (setq name
(list name
)))
1722 (setq args
(append args
(list list-keys-option
(car name
)))
1724 (setq args
(append args
(list list-keys-option
))))
1726 (apply #'call-process
1727 (if (eq (epg-context-protocol context
) 'CMS
)
1730 nil
(list t nil
) nil args
)
1731 (goto-char (point-min))
1732 (while (re-search-forward "^[a-z][a-z][a-z]:.*" nil t
)
1733 (setq keys
(cons (make-vector 15 nil
) keys
)
1734 string
(match-string 0)
1738 (string-match "\\([^:]+\\)?:" string index
))
1739 (setq index
(match-end 0))
1740 (aset (car keys
) field
(match-string 1 string
))
1741 (setq field
(1+ field
))))
1744 (defun epg--make-sub-key-1 (line)
1747 (cdr (assq (string-to-char (aref line
1)) epg-key-validity-alist
)))
1749 (mapcar (lambda (char) (cdr (assq char epg-key-capablity-alist
)))
1751 (member (aref line
0) '("sec" "ssb"))
1752 (string-to-number (aref line
3))
1753 (string-to-number (aref line
2))
1755 (epg--time-from-seconds (aref line
5))
1757 (epg--time-from-seconds (aref line
6)))))
1759 (defun epg-list-keys (context &optional name mode
)
1760 "Return a list of epg-key objects matched with NAME.
1761 If MODE is nil or 'public, only public keyring should be searched.
1762 If MODE is t or 'secret, only secret keyring should be searched.
1763 Otherwise, only public keyring should be searched and the key
1764 signatures should be included.
1765 NAME is either a string or a list of strings."
1766 (let ((lines (epg--list-keys-1 context name mode
))
1767 keys cert pointer pointer-1 index string
)
1770 ((member (aref (car lines
) 0) '("pub" "sec" "crt" "crs"))
1771 (setq cert
(member (aref (car lines
) 0) '("crt" "crs"))
1772 keys
(cons (epg-make-key
1773 (if (aref (car lines
) 8)
1774 (cdr (assq (string-to-char (aref (car lines
) 8))
1775 epg-key-validity-alist
))))
1777 (epg-key-set-sub-key-list
1779 (cons (epg--make-sub-key-1 (car lines
))
1780 (epg-key-sub-key-list (car keys
)))))
1781 ((member (aref (car lines
) 0) '("sub" "ssb"))
1782 (epg-key-set-sub-key-list
1784 (cons (epg--make-sub-key-1 (car lines
))
1785 (epg-key-sub-key-list (car keys
)))))
1786 ((equal (aref (car lines
) 0) "uid")
1787 ;; Decode the UID name as a backslash escaped UTF-8 string,
1788 ;; generated by GnuPG/GpgSM.
1789 (setq string
(copy-sequence (aref (car lines
) 9))
1791 (while (string-match "\"" string index
)
1792 (setq string
(replace-match "\\\"" t t string
)
1793 index
(1+ (match-end 0))))
1795 (setq string
(epg--decode-coding-string
1796 (car (read-from-string (concat "\"" string
"\"")))
1799 (setq string
(aref (car lines
) 9))))
1800 (epg-key-set-user-id-list
1802 (cons (epg-make-user-id
1803 (if (aref (car lines
) 1)
1804 (cdr (assq (string-to-char (aref (car lines
) 1))
1805 epg-key-validity-alist
)))
1808 (epg-dn-from-string string
)
1811 (epg-key-user-id-list (car keys
)))))
1812 ((equal (aref (car lines
) 0) "fpr")
1813 (epg-sub-key-set-fingerprint (car (epg-key-sub-key-list (car keys
)))
1814 (aref (car lines
) 9)))
1815 ((equal (aref (car lines
) 0) "sig")
1816 (epg-user-id-set-signature-list
1817 (car (epg-key-user-id-list (car keys
)))
1819 (epg-make-key-signature
1820 (if (aref (car lines
) 1)
1821 (cdr (assq (string-to-char (aref (car lines
) 1))
1822 epg-key-validity-alist
)))
1823 (string-to-number (aref (car lines
) 3))
1824 (aref (car lines
) 4)
1825 (epg--time-from-seconds (aref (car lines
) 5))
1826 (epg--time-from-seconds (aref (car lines
) 6))
1827 (aref (car lines
) 9)
1828 (string-to-number (aref (car lines
) 10) 16)
1829 (eq (aref (aref (car lines
) 10) 2) ?x
))
1830 (epg-user-id-signature-list
1831 (car (epg-key-user-id-list (car keys
))))))))
1832 (setq lines
(cdr lines
)))
1833 (setq keys
(nreverse keys
)
1836 (epg-key-set-sub-key-list
1838 (nreverse (epg-key-sub-key-list (car pointer
))))
1839 (setq pointer-1
(epg-key-set-user-id-list
1841 (nreverse (epg-key-user-id-list (car pointer
)))))
1843 (epg-user-id-set-signature-list
1845 (nreverse (epg-user-id-signature-list (car pointer-1
))))
1846 (setq pointer-1
(cdr pointer-1
)))
1847 (setq pointer
(cdr pointer
)))
1851 (if (fboundp 'make-temp-file
)
1852 (defalias 'epg--make-temp-file
'make-temp-file
)
1853 (defvar temporary-file-directory
)
1854 ;; stolen from poe.el.
1855 (defun epg--make-temp-file (prefix)
1856 "Create a temporary file.
1857 The returned file name (created by appending some random characters at the end
1858 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1859 is guaranteed to point to a newly created empty file.
1860 You can then use `write-region' to write new data into the file."
1861 (let (tempdir tempfile
)
1862 (setq prefix
(expand-file-name prefix
1863 (if (featurep 'xemacs
)
1865 temporary-file-directory
)))
1868 ;; First, create a temporary directory.
1869 (while (condition-case ()
1871 (setq tempdir
(make-temp-name
1873 (file-name-directory prefix
)
1875 ;; return nil or signal an error.
1876 (make-directory tempdir
))
1878 (file-already-exists t
)))
1879 (set-file-modes tempdir
448)
1880 ;; Second, create a temporary file in the tempdir.
1881 ;; There *is* a race condition between `make-temp-name'
1882 ;; and `write-region', but we don't care it since we are
1883 ;; in a private directory now.
1884 (setq tempfile
(make-temp-name (concat tempdir
"/EMU")))
1885 (write-region "" nil tempfile nil
'silent
)
1886 (set-file-modes tempfile
384)
1887 ;; Finally, make a hard-link from the tempfile.
1888 (while (condition-case ()
1890 (setq file
(make-temp-name prefix
))
1891 ;; return nil or signal an error.
1892 (add-name-to-file tempfile file
))
1894 (file-already-exists t
)))
1896 ;; Cleanup the tempfile.
1898 (file-exists-p tempfile
)
1899 (delete-file tempfile
))
1900 ;; Cleanup the tempdir.
1902 (file-directory-p tempdir
)
1903 (delete-directory tempdir
)))))))
1905 (defun epg--args-from-sig-notations (notations)
1909 (if (and (epg-sig-notation-name notation
)
1910 (not (epg-sig-notation-human-readable notation
)))
1911 (error "Unreadable"))
1912 (if (epg-sig-notation-name notation
)
1913 (list "--sig-notation"
1914 (if (epg-sig-notation-critical notation
)
1915 (concat "!" (epg-sig-notation-name notation
)
1916 "=" (epg-sig-notation-value notation
))
1917 (concat (epg-sig-notation-name notation
)
1918 "=" (epg-sig-notation-value notation
))))
1919 (list "--sig-policy-url"
1920 (if (epg-sig-notation-critical notation
)
1921 (concat "!" (epg-sig-notation-value notation
))
1922 (epg-sig-notation-value notation
)))))
1925 (defun epg-cancel (context)
1926 (if (buffer-live-p (process-buffer (epg-context-process context
)))
1928 (set-buffer (process-buffer (epg-context-process context
)))
1929 (epg-context-set-result-for
1932 (epg-context-result-for epg-context
'error
)))))
1933 (if (eq (process-status (epg-context-process context
)) 'run
)
1934 (delete-process (epg-context-process context
))))
1936 (defun epg-start-decrypt (context cipher
)
1937 "Initiate a decrypt operation on CIPHER.
1938 CIPHER must be a file data object.
1940 If you use this function, you will need to wait for the completion of
1941 `epg-gpg-program' by using `epg-wait-for-completion' and call
1942 `epg-reset' to clear a temporaly output file.
1943 If you are unsure, use synchronous version of this function
1944 `epg-decrypt-file' or `epg-decrypt-string' instead."
1945 (unless (epg-data-file cipher
)
1946 (error "Not a file"))
1947 (epg-context-set-operation context
'decrypt
)
1948 (epg-context-set-result context nil
)
1949 (epg--start context
(list "--decrypt" "--" (epg-data-file cipher
)))
1950 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
1951 (unless (eq (epg-context-protocol context
) 'CMS
)
1952 (epg-wait-for-status context
'("BEGIN_DECRYPTION"))))
1954 (defun epg--check-error-for-decrypt (context)
1955 (if (epg-context-result-for context
'decryption-failed
)
1956 (signal 'epg-error
(list "Decryption failed")))
1957 (if (epg-context-result-for context
'no-secret-key
)
1959 (list "No secret key"
1960 (epg-context-result-for context
'no-secret-key
))))
1961 (unless (epg-context-result-for context
'decryption-okay
)
1962 (let* ((error (epg-context-result-for context
'error
)))
1963 (if (assq 'no-data error
)
1964 (signal 'epg-error
(list "No data")))
1965 (signal 'epg-error
(list "Can't decrypt" error
)))))
1967 (defun epg-decrypt-file (context cipher plain
)
1968 "Decrypt a file CIPHER and store the result to a file PLAIN.
1969 If PLAIN is nil, it returns the result as a string."
1973 (epg-context-set-output-file context plain
)
1974 (epg-context-set-output-file context
1975 (epg--make-temp-file "epg-output")))
1976 (epg-start-decrypt context
(epg-make-data-from-file cipher
))
1977 (epg-wait-for-completion context
)
1978 (epg--check-error-for-decrypt context
)
1980 (epg-read-output context
)))
1982 (epg-delete-output-file context
))
1983 (epg-reset context
)))
1985 (defun epg-decrypt-string (context cipher
)
1986 "Decrypt a string CIPHER and return the plain text."
1987 (let ((input-file (epg--make-temp-file "epg-input"))
1988 (coding-system-for-write 'binary
))
1991 (write-region cipher nil input-file nil
'quiet
)
1992 (epg-context-set-output-file context
1993 (epg--make-temp-file "epg-output"))
1994 (epg-start-decrypt context
(epg-make-data-from-file input-file
))
1995 (epg-wait-for-completion context
)
1996 (epg--check-error-for-decrypt context
)
1997 (epg-read-output context
))
1998 (epg-delete-output-file context
)
1999 (if (file-exists-p input-file
)
2000 (delete-file input-file
))
2001 (epg-reset context
))))
2003 (defun epg-start-verify (context signature
&optional signed-text
)
2004 "Initiate a verify operation on SIGNATURE.
2005 SIGNATURE and SIGNED-TEXT are a data object if they are specified.
2007 For a detached signature, both SIGNATURE and SIGNED-TEXT should be set.
2008 For a normal or a cleartext signature, SIGNED-TEXT should be nil.
2010 If you use this function, you will need to wait for the completion of
2011 `epg-gpg-program' by using `epg-wait-for-completion' and call
2012 `epg-reset' to clear a temporaly output file.
2013 If you are unsure, use synchronous version of this function
2014 `epg-verify-file' or `epg-verify-string' instead."
2015 (epg-context-set-operation context
'verify
)
2016 (epg-context-set-result context nil
)
2018 ;; Detached signature.
2019 (if (epg-data-file signed-text
)
2020 (epg--start context
(list "--verify" "--" (epg-data-file signature
)
2021 (epg-data-file signed-text
)))
2022 (epg--start context
(list "--verify" "--" (epg-data-file signature
)
2024 (if (eq (process-status (epg-context-process context
)) 'run
)
2025 (process-send-string (epg-context-process context
)
2026 (epg-data-string signed-text
)))
2027 (if (eq (process-status (epg-context-process context
)) 'run
)
2028 (process-send-eof (epg-context-process context
))))
2029 ;; Normal (or cleartext) signature.
2030 (if (epg-data-file signature
)
2031 (epg--start context
(if (eq (epg-context-protocol context
) 'CMS
)
2032 (list "--verify" "--" (epg-data-file signature
))
2033 (list "--" (epg-data-file signature
))))
2034 (epg--start context
(if (eq (epg-context-protocol context
) 'CMS
)
2037 (if (eq (process-status (epg-context-process context
)) 'run
)
2038 (process-send-string (epg-context-process context
)
2039 (epg-data-string signature
)))
2040 (if (eq (process-status (epg-context-process context
)) 'run
)
2041 (process-send-eof (epg-context-process context
))))))
2043 (defun epg-verify-file (context signature
&optional signed-text plain
)
2044 "Verify a file SIGNATURE.
2045 SIGNED-TEXT and PLAIN are also a file if they are specified.
2047 For a detached signature, both SIGNATURE and SIGNED-TEXT should be
2048 string. For a normal or a cleartext signature, SIGNED-TEXT should be
2049 nil. In the latter case, if PLAIN is specified, the plaintext is
2050 stored into the file after successful verification."
2054 (epg-context-set-output-file context plain
)
2055 (epg-context-set-output-file context
2056 (epg--make-temp-file "epg-output")))
2058 (epg-start-verify context
2059 (epg-make-data-from-file signature
)
2060 (epg-make-data-from-file signed-text
))
2061 (epg-start-verify context
2062 (epg-make-data-from-file signature
)))
2063 (epg-wait-for-completion context
)
2065 (epg-read-output context
)))
2067 (epg-delete-output-file context
))
2068 (epg-reset context
)))
2070 (defun epg-verify-string (context signature
&optional signed-text
)
2071 "Verify a string SIGNATURE.
2072 SIGNED-TEXT is a string if it is specified.
2074 For a detached signature, both SIGNATURE and SIGNED-TEXT should be
2075 string. For a normal or a cleartext signature, SIGNED-TEXT should be
2076 nil. In the latter case, this function returns the plaintext after
2077 successful verification."
2078 (let ((coding-system-for-write 'binary
)
2082 (epg-context-set-output-file context
2083 (epg--make-temp-file "epg-output"))
2086 (setq input-file
(epg--make-temp-file "epg-signature"))
2087 (write-region signature nil input-file nil
'quiet
)
2088 (epg-start-verify context
2089 (epg-make-data-from-file input-file
)
2090 (epg-make-data-from-string signed-text
)))
2091 (epg-start-verify context
(epg-make-data-from-string signature
)))
2092 (epg-wait-for-completion context
)
2093 (epg-read-output context
))
2094 (epg-delete-output-file context
)
2096 (file-exists-p input-file
))
2097 (delete-file input-file
))
2098 (epg-reset context
))))
2100 (defun epg-start-sign (context plain
&optional mode
)
2101 "Initiate a sign operation on PLAIN.
2102 PLAIN is a data object.
2104 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
2105 If it is nil or 'normal, it makes a normal signature.
2106 Otherwise, it makes a cleartext signature.
2108 If you use this function, you will need to wait for the completion of
2109 `epg-gpg-program' by using `epg-wait-for-completion' and call
2110 `epg-reset' to clear a temporaly output file.
2111 If you are unsure, use synchronous version of this function
2112 `epg-sign-file' or `epg-sign-string' instead."
2113 (epg-context-set-operation context
'sign
)
2114 (epg-context-set-result context nil
)
2115 (unless (memq mode
'(t detached nil normal
)) ;i.e. cleartext
2116 (epg-context-set-armor context nil
)
2117 (epg-context-set-textmode context nil
))
2119 (append (list (if (memq mode
'(t detached
))
2121 (if (memq mode
'(nil normal
))
2129 (car (epg-key-sub-key-list signer
)))))
2130 (epg-context-signers context
)))
2131 (epg--args-from-sig-notations
2132 (epg-context-sig-notations context
))
2133 (if (epg-data-file plain
)
2134 (list "--" (epg-data-file plain
)))))
2135 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
2136 (unless (eq (epg-context-protocol context
) 'CMS
)
2137 (epg-wait-for-status context
'("BEGIN_SIGNING")))
2138 (when (epg-data-string plain
)
2139 (if (eq (process-status (epg-context-process context
)) 'run
)
2140 (process-send-string (epg-context-process context
)
2141 (epg-data-string plain
)))
2142 (if (eq (process-status (epg-context-process context
)) 'run
)
2143 (process-send-eof (epg-context-process context
)))))
2145 (defun epg-sign-file (context plain signature
&optional mode
)
2146 "Sign a file PLAIN and store the result to a file SIGNATURE.
2147 If SIGNATURE is nil, it returns the result as a string.
2148 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
2149 If it is nil or 'normal, it makes a normal signature.
2150 Otherwise, it makes a cleartext signature."
2154 (epg-context-set-output-file context signature
)
2155 (epg-context-set-output-file context
2156 (epg--make-temp-file "epg-output")))
2157 (epg-start-sign context
(epg-make-data-from-file plain
) mode
)
2158 (epg-wait-for-completion context
)
2159 (unless (epg-context-result-for context
'sign
)
2160 (if (epg-context-result-for context
'error
)
2161 (error "Sign failed: %S"
2162 (epg-context-result-for context
'error
))
2163 (error "Sign failed")))
2165 (epg-read-output context
)))
2167 (epg-delete-output-file context
))
2168 (epg-reset context
)))
2170 (defun epg-sign-string (context plain
&optional mode
)
2171 "Sign a string PLAIN and return the output as string.
2172 If optional 3rd argument MODE is t or 'detached, it makes a detached signature.
2173 If it is nil or 'normal, it makes a normal signature.
2174 Otherwise, it makes a cleartext signature."
2176 (unless (or (eq (epg-context-protocol context
) 'CMS
)
2179 (epg-check-configuration (epg-configuration))
2182 (epg--make-temp-file "epg-input")))
2183 (coding-system-for-write 'binary
))
2186 (epg-context-set-output-file context
2187 (epg--make-temp-file "epg-output"))
2189 (write-region plain nil input-file nil
'quiet
))
2190 (epg-start-sign context
2192 (epg-make-data-from-file input-file
)
2193 (epg-make-data-from-string plain
))
2195 (epg-wait-for-completion context
)
2196 (unless (epg-context-result-for context
'sign
)
2197 (if (epg-context-result-for context
'error
)
2198 (error "Sign failed: %S"
2199 (epg-context-result-for context
'error
))
2200 (error "Sign failed")))
2201 (epg-read-output context
))
2202 (epg-delete-output-file context
)
2204 (delete-file input-file
))
2205 (epg-reset context
))))
2207 (defun epg-start-encrypt (context plain recipients
2208 &optional sign always-trust
)
2209 "Initiate an encrypt operation on PLAIN.
2210 PLAIN is a data object.
2211 If RECIPIENTS is nil, it performs symmetric encryption.
2213 If you use this function, you will need to wait for the completion of
2214 `epg-gpg-program' by using `epg-wait-for-completion' and call
2215 `epg-reset' to clear a temporaly output file.
2216 If you are unsure, use synchronous version of this function
2217 `epg-encrypt-file' or `epg-encrypt-string' instead."
2218 (epg-context-set-operation context
'encrypt
)
2219 (epg-context-set-result context nil
)
2221 (append (if always-trust
'("--always-trust"))
2222 (if recipients
'("--encrypt") '("--symmetric"))
2223 (if sign
'("--sign"))
2230 (car (epg-key-sub-key-list
2232 (epg-context-signers context
))))
2234 (epg--args-from-sig-notations
2235 (epg-context-sig-notations context
)))
2241 (car (epg-key-sub-key-list recipient
)))))
2243 (if (epg-data-file plain
)
2244 (list "--" (epg-data-file plain
)))))
2245 ;; `gpgsm' does not read passphrase from stdin, so waiting is not needed.
2246 (unless (eq (epg-context-protocol context
) 'CMS
)
2248 (epg-wait-for-status context
'("BEGIN_SIGNING"))
2249 (epg-wait-for-status context
'("BEGIN_ENCRYPTION"))))
2250 (when (epg-data-string plain
)
2251 (if (eq (process-status (epg-context-process context
)) 'run
)
2252 (process-send-string (epg-context-process context
)
2253 (epg-data-string plain
)))
2254 (if (eq (process-status (epg-context-process context
)) 'run
)
2255 (process-send-eof (epg-context-process context
)))))
2257 (defun epg-encrypt-file (context plain recipients
2258 cipher
&optional sign always-trust
)
2259 "Encrypt a file PLAIN and store the result to a file CIPHER.
2260 If CIPHER is nil, it returns the result as a string.
2261 If RECIPIENTS is nil, it performs symmetric encryption."
2265 (epg-context-set-output-file context cipher
)
2266 (epg-context-set-output-file context
2267 (epg--make-temp-file "epg-output")))
2268 (epg-start-encrypt context
(epg-make-data-from-file plain
)
2269 recipients sign always-trust
)
2270 (epg-wait-for-completion context
)
2272 (not (epg-context-result-for context
'sign
)))
2273 (if (epg-context-result-for context
'error
)
2274 (error "Sign failed: %S"
2275 (epg-context-result-for context
'error
))
2276 (error "Sign failed")))
2277 (if (epg-context-result-for context
'error
)
2278 (error "Encrypt failed: %S"
2279 (epg-context-result-for context
'error
)))
2281 (epg-read-output context
)))
2283 (epg-delete-output-file context
))
2284 (epg-reset context
)))
2286 (defun epg-encrypt-string (context plain recipients
2287 &optional sign always-trust
)
2288 "Encrypt a string PLAIN.
2289 If RECIPIENTS is nil, it performs symmetric encryption."
2291 (unless (or (not sign
)
2292 (eq (epg-context-protocol context
) 'CMS
)
2295 (epg-check-configuration (epg-configuration))
2298 (epg--make-temp-file "epg-input")))
2299 (coding-system-for-write 'binary
))
2302 (epg-context-set-output-file context
2303 (epg--make-temp-file "epg-output"))
2305 (write-region plain nil input-file nil
'quiet
))
2306 (epg-start-encrypt context
2308 (epg-make-data-from-file input-file
)
2309 (epg-make-data-from-string plain
))
2310 recipients sign always-trust
)
2311 (epg-wait-for-completion context
)
2313 (not (epg-context-result-for context
'sign
)))
2314 (if (epg-context-result-for context
'error
)
2315 (error "Sign failed: %S"
2316 (epg-context-result-for context
'error
))
2317 (error "Sign failed")))
2318 (if (epg-context-result-for context
'error
)
2319 (error "Encrypt failed: %S"
2320 (epg-context-result-for context
'error
)))
2321 (epg-read-output context
))
2322 (epg-delete-output-file context
)
2324 (delete-file input-file
))
2325 (epg-reset context
))))
2327 (defun epg-start-export-keys (context keys
)
2328 "Initiate an export keys operation.
2330 If you use this function, you will need to wait for the completion of
2331 `epg-gpg-program' by using `epg-wait-for-completion' and call
2332 `epg-reset' to clear a temporaly output file.
2333 If you are unsure, use synchronous version of this function
2334 `epg-export-keys-to-file' or `epg-export-keys-to-string' instead."
2335 (epg-context-set-operation context
'export-keys
)
2336 (epg-context-set-result context nil
)
2337 (epg--start context
(cons "--export"
2341 (car (epg-key-sub-key-list key
))))
2344 (defun epg-export-keys-to-file (context keys file
)
2345 "Extract public KEYS."
2349 (epg-context-set-output-file context file
)
2350 (epg-context-set-output-file context
2351 (epg--make-temp-file "epg-output")))
2352 (epg-start-export-keys context keys
)
2353 (epg-wait-for-completion context
)
2354 (if (epg-context-result-for context
'error
)
2355 (error "Export keys failed: %S"
2356 (epg-context-result-for context
'error
)))
2358 (epg-read-output context
)))
2360 (epg-delete-output-file context
))
2361 (epg-reset context
)))
2363 (defun epg-export-keys-to-string (context keys
)
2364 "Extract public KEYS and return them as a string."
2365 (epg-export-keys-to-file context keys nil
))
2367 (defun epg-start-import-keys (context keys
)
2368 "Initiate an import keys operation.
2369 KEYS is a data object.
2371 If you use this function, you will need to wait for the completion of
2372 `epg-gpg-program' by using `epg-wait-for-completion' and call
2373 `epg-reset' to clear a temporaly output file.
2374 If you are unsure, use synchronous version of this function
2375 `epg-import-keys-from-file' or `epg-import-keys-from-string' instead."
2376 (epg-context-set-operation context
'import-keys
)
2377 (epg-context-set-result context nil
)
2378 (epg--start context
(if (epg-data-file keys
)
2379 (list "--import" "--" (epg-data-file keys
))
2381 (when (epg-data-string keys
)
2382 (if (eq (process-status (epg-context-process context
)) 'run
)
2383 (process-send-string (epg-context-process context
)
2384 (epg-data-string keys
)))
2385 (if (eq (process-status (epg-context-process context
)) 'run
)
2386 (process-send-eof (epg-context-process context
)))))
2388 (defun epg--import-keys-1 (context keys
)
2391 (epg-start-import-keys context keys
)
2392 (epg-wait-for-completion context
)
2393 (if (epg-context-result-for context
'error
)
2394 (error "Import keys failed: %S"
2395 (epg-context-result-for context
'error
))))
2396 (epg-reset context
)))
2398 (defun epg-import-keys-from-file (context keys
)
2399 "Add keys from a file KEYS."
2400 (epg--import-keys-1 context
(epg-make-data-from-file keys
)))
2402 (defun epg-import-keys-from-string (context keys
)
2403 "Add keys from a string KEYS."
2404 (epg--import-keys-1 context
(epg-make-data-from-string keys
)))
2406 (defun epg-start-receive-keys (context key-id-list
)
2407 "Initiate a receive key operation.
2408 KEY-ID-LIST is a list of key IDs.
2410 If you use this function, you will need to wait for the completion of
2411 `epg-gpg-program' by using `epg-wait-for-completion' and call
2412 `epg-reset' to clear a temporaly output file.
2413 If you are unsure, use synchronous version of this function
2414 `epg-receive-keys' instead."
2415 (epg-context-set-operation context
'receive-keys
)
2416 (epg-context-set-result context nil
)
2417 (epg--start context
(cons "--recv-keys" key-id-list
)))
2419 (defun epg-receive-keys (context keys
)
2420 "Add keys from server.
2421 KEYS is a list of key IDs"
2424 (epg-start-receive-keys context keys
)
2425 (epg-wait-for-completion context
)
2426 (if (epg-context-result-for context
'error
)
2427 (error "Receive keys failed: %S"
2428 (epg-context-result-for context
'error
))))
2429 (epg-reset context
)))
2431 (defalias 'epg-import-keys-from-server
'epg-receive-keys
)
2433 (defun epg-start-delete-keys (context keys
&optional allow-secret
)
2434 "Initiate a delete keys operation.
2436 If you use this function, you will need to wait for the completion of
2437 `epg-gpg-program' by using `epg-wait-for-completion' and call
2438 `epg-reset' to clear a temporaly output file.
2439 If you are unsure, use synchronous version of this function
2440 `epg-delete-keys' instead."
2441 (epg-context-set-operation context
'delete-keys
)
2442 (epg-context-set-result context nil
)
2443 (epg--start context
(cons (if allow-secret
2444 "--delete-secret-key"
2449 (car (epg-key-sub-key-list key
))))
2452 (defun epg-delete-keys (context keys
&optional allow-secret
)
2453 "Delete KEYS from the key ring."
2456 (epg-start-delete-keys context keys allow-secret
)
2457 (epg-wait-for-completion context
)
2458 (let ((entry (assq 'delete-problem
2459 (epg-context-result-for context
'error
))))
2461 (if (setq entry
(assq (cdr entry
)
2462 epg-delete-problem-reason-alist
))
2463 (error "Delete keys failed: %s" (cdr entry
))
2464 (error "Delete keys failed")))))
2465 (epg-reset context
)))
2467 (defun epg-start-sign-keys (context keys
&optional local
)
2468 "Initiate a sign keys operation.
2470 If you use this function, you will need to wait for the completion of
2471 `epg-gpg-program' by using `epg-wait-for-completion' and call
2472 `epg-reset' to clear a temporaly output file.
2473 If you are unsure, use synchronous version of this function
2474 `epg-sign-keys' instead."
2475 (epg-context-set-operation context
'sign-keys
)
2476 (epg-context-set-result context nil
)
2477 (epg--start context
(cons (if local
2483 (car (epg-key-sub-key-list key
))))
2485 (make-obsolete 'epg-start-sign-keys
"do not use." "23.1")
2487 (defun epg-sign-keys (context keys
&optional local
)
2488 "Sign KEYS from the key ring."
2491 (epg-start-sign-keys context keys local
)
2492 (epg-wait-for-completion context
)
2493 (if (epg-context-result-for context
'error
)
2494 (error "Sign keys failed: %S"
2495 (epg-context-result-for context
'error
))))
2496 (epg-reset context
)))
2497 (make-obsolete 'epg-sign-keys
"do not use." "23.1")
2499 (defun epg-start-generate-key (context parameters
)
2500 "Initiate a key generation.
2501 PARAMETERS specifies parameters for the key.
2503 If you use this function, you will need to wait for the completion of
2504 `epg-gpg-program' by using `epg-wait-for-completion' and call
2505 `epg-reset' to clear a temporaly output file.
2506 If you are unsure, use synchronous version of this function
2507 `epg-generate-key-from-file' or `epg-generate-key-from-string' instead."
2508 (epg-context-set-operation context
'generate-key
)
2509 (epg-context-set-result context nil
)
2510 (if (epg-data-file parameters
)
2511 (epg--start context
(list "--batch" "--genkey" "--"
2512 (epg-data-file parameters
)))
2513 (epg--start context
'("--batch" "--genkey"))
2514 (if (eq (process-status (epg-context-process context
)) 'run
)
2515 (process-send-string (epg-context-process context
)
2516 (epg-data-string parameters
)))
2517 (if (eq (process-status (epg-context-process context
)) 'run
)
2518 (process-send-eof (epg-context-process context
)))))
2520 (defun epg-generate-key-from-file (context parameters
)
2521 "Generate a new key pair.
2522 PARAMETERS is a file which tells how to create the key."
2525 (epg-start-generate-key context
(epg-make-data-from-file parameters
))
2526 (epg-wait-for-completion context
)
2527 (if (epg-context-result-for context
'error
)
2528 (error "Generate key failed: %S"
2529 (epg-context-result-for context
'error
))))
2530 (epg-reset context
)))
2532 (defun epg-generate-key-from-string (context parameters
)
2533 "Generate a new key pair.
2534 PARAMETERS is a string which tells how to create the key."
2537 (epg-start-generate-key context
(epg-make-data-from-string parameters
))
2538 (epg-wait-for-completion context
)
2539 (if (epg-context-result-for context
'error
)
2540 (error "Generate key failed: %S"
2541 (epg-context-result-for context
'error
))))
2542 (epg-reset context
)))
2544 (defun epg--decode-percent-escape (string)
2546 (while (string-match "%\\(\\(%\\)\\|\\([0-9A-Fa-f][0-9A-Fa-f]\\)\\)"
2548 (if (match-beginning 2)
2549 (setq string
(replace-match "%" t t string
)
2550 index
(1- (match-end 0)))
2551 (setq string
(replace-match
2552 (string (string-to-number (match-string 3 string
) 16))
2554 index
(- (match-end 0) 2))))
2557 (defun epg--decode-hexstring (string)
2559 (while (eq index
(string-match "[0-9A-Fa-f][0-9A-Fa-f]" string index
))
2560 (setq string
(replace-match (string (string-to-number
2561 (match-string 0 string
) 16))
2563 index
(1- (match-end 0))))
2566 (defun epg--decode-quotedstring (string)
2568 (while (string-match "\\\\\\(\\([,=+<>#;\\\"]\\)\\|\
2569 \\([0-9A-Fa-f][0-9A-Fa-f]\\)\\)"
2571 (if (match-beginning 2)
2572 (setq string
(replace-match "\\2" t nil string
)
2573 index
(1- (match-end 0)))
2574 (if (match-beginning 3)
2575 (setq string
(replace-match (string (string-to-number
2576 (match-string 0 string
) 16))
2578 index
(- (match-end 0) 2)))))
2581 (defun epg-dn-from-string (string)
2582 "Parse STRING as LADPv3 Distinguished Names (RFC2253).
2583 The return value is an alist mapping from types to values."
2585 (length (length string
))
2586 alist type value group
)
2587 (while (< index length
)
2588 (if (eq index
(string-match "[ \t\n\r]*" string index
))
2589 (setq index
(match-end 0)))
2590 (if (eq index
(string-match
2591 "\\([0-9]+\\(\\.[0-9]+\\)*\\)\[ \t\n\r]*=[ \t\n\r]*"
2593 (setq type
(match-string 1 string
)
2594 index
(match-end 0))
2595 (if (eq index
(string-match "\\([0-9A-Za-z]+\\)[ \t\n\r]*=[ \t\n\r]*"
2597 (setq type
(match-string 1 string
)
2598 index
(match-end 0))))
2600 (error "Invalid type"))
2601 (if (eq index
(string-match
2602 "\\([^,=+<>#;\\\"]\\|\\\\.\\)+"
2604 (setq index
(match-end 0)
2605 value
(epg--decode-quotedstring (match-string 0 string
)))
2606 (if (eq index
(string-match "#\\([0-9A-Fa-f]+\\)" string index
))
2607 (setq index
(match-end 0)
2608 value
(epg--decode-hexstring (match-string 1 string
)))
2609 (if (eq index
(string-match "\"\\([^\\\"]\\|\\\\.\\)*\""
2611 (setq index
(match-end 0)
2612 value
(epg--decode-quotedstring
2613 (match-string 0 string
))))))
2615 (if (stringp (car (car alist
)))
2616 (setcar alist
(list (cons type value
) (car alist
)))
2617 (setcar alist
(cons (cons type value
) (car alist
))))
2618 (if (consp (car (car alist
)))
2619 (setcar alist
(nreverse (car alist
))))
2620 (setq alist
(cons (cons type value
) alist
)
2623 (if (eq index
(string-match "[ \t\n\r]*\\([,;+]\\)" string index
))
2624 (setq index
(match-end 0)
2625 group
(eq (aref string
(match-beginning 1)) ?
+))))
2628 (defun epg-decode-dn (alist)
2629 "Convert ALIST returned by `epg-dn-from-string' to a human readable form.
2630 Type names are resolved using `epg-dn-type-alist'."
2633 (if (stringp (car rdn
))
2634 (let ((entry (assoc (car rdn
) epg-dn-type-alist
)))
2636 (format "%s=%s" (cdr entry
) (cdr rdn
))
2637 (format "%s=%s" (car rdn
) (cdr rdn
))))
2638 (concat "(" (epg-decode-dn rdn
) ")")))
2644 ;; arch-tag: de8f0acc-1bcf-4c14-a09e-bfffe1b579b7
2645 ;;; epg.el ends here