X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/2a268ee2c53f278336ec1b788c5bcb0122a91940..562dd5e9532d75d18843a37a1e42a1f4398d4823:/lisp/epg.el diff --git a/lisp/epg.el b/lisp/epg.el index 5c9fd9b882..348ad970b1 100644 --- a/lisp/epg.el +++ b/lisp/epg.el @@ -1,9 +1,9 @@ -;;; epg.el --- the EasyPG Library -;; Copyright (C) 1999, 2000, 2002, 2003, 2004, -;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +;;; epg.el --- the EasyPG Library -*- lexical-binding: t -*- +;; Copyright (C) 1999-2000, 2002-2011 Free Software Foundation, Inc. ;; Author: Daiki Ueno ;; Keywords: PGP, GnuPG +;; Version: 1.0.0 ;; This file is part of GNU Emacs. @@ -49,6 +49,8 @@ (8 . "AES192") (9 . "AES256") (10 . "TWOFISH") + (11 . "CAMELLIA128") + (12 . "CAMELLIA256") (110 . "DUMMY"))) ;; from gnupg/include/cipher.h @@ -64,10 +66,11 @@ (defconst epg-digest-algorithm-alist '((1 . "MD5") (2 . "SHA1") - (3 . "RMD160") + (3 . "RIPEMD160") (8 . "SHA256") (9 . "SHA384") - (10 . "SHA512"))) + (10 . "SHA512") + (11 . "SHA224"))) ;; from gnupg/include/cipher.h (defconst epg-compress-algorithm-alist @@ -134,7 +137,8 @@ '((?e . encrypt) (?s . sign) (?c . certify) - (?a . authentication))) + (?a . authentication) + (?D . disabled))) (defvar epg-new-signature-type-alist '((?D . detached) @@ -178,6 +182,7 @@ (signal 'wrong-type-argument (list 'epg-data-p data))) (aref (cdr data) 1)) +;;;###autoload (defun epg-make-context (&optional protocol armor textmode include-certs cipher-algorithm digest-algorithm compress-algorithm) @@ -325,7 +330,19 @@ This function is for internal use only." (defun epg-context-set-passphrase-callback (context passphrase-callback) - "Set the function used to query passphrase." + "Set the function used to query passphrase. + +PASSPHRASE-CALLBACK is either a function, or a cons-cell whose +car is a function and cdr is a callback data. + +The function gets three arguments: the context, the key-id in +question, and the callback data (if any). + +The callback may not be called if you use GnuPG 2.x, which relies +on the external program called `gpg-agent' for passphrase query. +If you really want to intercept passphrase query, consider +installing GnuPG 1.x _along with_ GnuPG 2.x, which does passphrase +query by itself and Emacs can intercept them." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) (aset (cdr context) 7 (if (consp passphrase-callback) @@ -335,7 +352,14 @@ This function is for internal use only." (defun epg-context-set-progress-callback (context progress-callback) "Set the function which handles progress update. -If optional argument HANDBACK is specified, it is passed to PROGRESS-CALLBACK." + +PROGRESS-CALLBACK is either a function, or a cons-cell whose +car is a function and cdr is a callback data. + +The function gets five arguments: the context, the operation +description, the character to display a progress unit, the +current amount done, the total amount to be done, and the +callback data (if any)." (unless (eq (car-safe context) 'epg-context) (signal 'wrong-type-argument (list 'epg-context-p context))) (aset (cdr context) 8 (if (consp progress-callback) @@ -1126,8 +1150,7 @@ This function is for internal use only." (goto-char (point-max)) (insert input))) (if (buffer-live-p (process-buffer process)) - (save-excursion - (set-buffer (process-buffer process)) + (with-current-buffer (process-buffer process) (goto-char (point-max)) (insert input) (unless epg-process-filter-running @@ -1170,7 +1193,10 @@ This function is for internal use only." epg-pending-status-list) (accept-process-output (epg-context-process context) 1)) (if epg-pending-status-list - (epg-context-set-result-for context 'error 'exit)))) + (epg-context-set-result-for + context 'error + (cons (list 'exit) + (epg-context-result-for context 'error)))))) (defun epg-wait-for-completion (context) "Wait until the `epg-gpg-program' process completes." @@ -1197,7 +1223,7 @@ This function is for internal use only." (defalias 'epg--decode-coding-string 'decode-coding-string) (defalias 'epg--decode-coding-string 'identity))) -(defun epg--status-USERID_HINT (context string) +(defun epg--status-USERID_HINT (_context string) (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string) (let* ((key-id (match-string 1 string)) (user-id (match-string 2 string)) @@ -1212,14 +1238,14 @@ This function is for internal use only." (setq epg-user-id-alist (cons (cons key-id user-id) epg-user-id-alist)))))) -(defun epg--status-NEED_PASSPHRASE (context string) +(defun epg--status-NEED_PASSPHRASE (_context string) (if (string-match "\\`\\([^ ]+\\)" string) (setq epg-key-id (match-string 1 string)))) -(defun epg--status-NEED_PASSPHRASE_SYM (context string) +(defun epg--status-NEED_PASSPHRASE_SYM (_context _string) (setq epg-key-id 'SYM)) -(defun epg--status-NEED_PASSPHRASE_PIN (context string) +(defun epg--status-NEED_PASSPHRASE_PIN (_context _string) (setq epg-key-id 'PIN)) (eval-and-compile @@ -1282,11 +1308,11 @@ This function is for internal use only." (if encoded-passphrase-with-new-line (epg--clear-string encoded-passphrase-with-new-line)))))) -(defun epg--prompt-GET_BOOL (context string) +(defun epg--prompt-GET_BOOL (_context string) (let ((entry (assoc string epg-prompt-alist))) (y-or-n-p (if entry (cdr entry) (concat string "? "))))) -(defun epg--prompt-GET_BOOL-untrusted_key.override (context string) +(defun epg--prompt-GET_BOOL-untrusted_key.override (_context _string) (y-or-n-p (if (and (equal (car epg-last-status) "USERID_HINT") (string-match "\\`\\([^ ]+\\) \\(.*\\)" (cdr epg-last-status))) @@ -1441,31 +1467,31 @@ This function is for internal use only." signature (string-to-number (match-string 7 string) 16))))) -(defun epg--status-TRUST_UNDEFINED (context string) +(defun epg--status-TRUST_UNDEFINED (context _string) (let ((signature (car (epg-context-result-for context 'verify)))) (if (and signature (eq (epg-signature-status signature) 'good)) (epg-signature-set-validity signature 'undefined)))) -(defun epg--status-TRUST_NEVER (context string) +(defun epg--status-TRUST_NEVER (context _string) (let ((signature (car (epg-context-result-for context 'verify)))) (if (and signature (eq (epg-signature-status signature) 'good)) (epg-signature-set-validity signature 'never)))) -(defun epg--status-TRUST_MARGINAL (context string) +(defun epg--status-TRUST_MARGINAL (context _string) (let ((signature (car (epg-context-result-for context 'verify)))) (if (and signature (eq (epg-signature-status signature) 'marginal)) (epg-signature-set-validity signature 'marginal)))) -(defun epg--status-TRUST_FULLY (context string) +(defun epg--status-TRUST_FULLY (context _string) (let ((signature (car (epg-context-result-for context 'verify)))) (if (and signature (eq (epg-signature-status signature) 'good)) (epg-signature-set-validity signature 'full)))) -(defun epg--status-TRUST_ULTIMATE (context string) +(defun epg--status-TRUST_ULTIMATE (context _string) (let ((signature (car (epg-context-result-for context 'verify)))) (if (and signature (eq (epg-signature-status signature) 'good)) @@ -1515,10 +1541,10 @@ This function is for internal use only." (string-to-number (match-string 3 string))) (epg-context-result-for context 'encrypted-to))))) -(defun epg--status-DECRYPTION_FAILED (context string) +(defun epg--status-DECRYPTION_FAILED (context _string) (epg-context-set-result-for context 'decryption-failed t)) -(defun epg--status-DECRYPTION_OKAY (context string) +(defun epg--status-DECRYPTION_OKAY (context _string) (epg-context-set-result-for context 'decryption-okay t)) (defun epg--status-NODATA (context string) @@ -1535,18 +1561,18 @@ This function is for internal use only." (defun epg--status-KEYEXPIRED (context string) (epg-context-set-result-for - context 'error + context 'key (cons (list 'key-expired (cons 'expiration-time (epg--time-from-seconds string))) (epg-context-result-for context 'error)))) -(defun epg--status-KEYREVOKED (context string) +(defun epg--status-KEYREVOKED (context _string) (epg-context-set-result-for - context 'error + context 'key (cons '(key-revoked) (epg-context-result-for context 'error)))) -(defun epg--status-BADARMOR (context string) +(defun epg--status-BADARMOR (context _string) (epg-context-set-result-for context 'error (cons '(bad-armor) @@ -1563,7 +1589,7 @@ This function is for internal use only." (match-string 2 string))) (epg-context-result-for context 'error))))) -(defun epg--status-NO_RECP (context string) +(defun epg--status-NO_RECP (context _string) (epg-context-set-result-for context 'error (cons '(no-recipients) @@ -1600,13 +1626,13 @@ This function is for internal use only." (cons 'fingerprint (match-string 2 string))) (epg-context-result-for context 'generate-key))))) -(defun epg--status-KEY_NOT_CREATED (context string) +(defun epg--status-KEY_NOT_CREATED (context _string) (epg-context-set-result-for context 'error (cons '(key-not-created) (epg-context-result-for context 'error)))) -(defun epg--status-IMPORTED (context string) +(defun epg--status-IMPORTED (_context string) (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string) (let* ((key-id (match-string 1 string)) (user-id (match-string 2 string)) @@ -1668,7 +1694,7 @@ This function is for internal use only." (epg-context-result-for context 'import-status))) (epg-context-set-result-for context 'import-status nil))) -(defun epg-passphrase-callback-function (context key-id handback) +(defun epg-passphrase-callback-function (context key-id _handback) (if (eq key-id 'SYM) (read-passwd "Passphrase for symmetric encryption: " (eq (epg-context-operation context) 'encrypt)) @@ -1681,7 +1707,7 @@ This function is for internal use only." (format "Passphrase for %s: " key-id))))))) (make-obsolete 'epg-passphrase-callback-function - 'epa-passphrase-callback-function) + 'epa-passphrase-callback-function "23.1") (defun epg--list-keys-1 (context name mode) (let ((args (append (if epg-gpg-home-directory @@ -1739,7 +1765,6 @@ This function is for internal use only." (if (aref line 6) (epg--time-from-seconds (aref line 6))))) -;;;###autoload (defun epg-list-keys (context &optional name mode) "Return a list of epg-key objects matched with NAME. If MODE is nil or 'public, only public keyring should be searched. @@ -1906,11 +1931,9 @@ You can then use `write-region' to write new data into the file." (epg-sig-notation-value notation))))) notations))) -;;;###autoload (defun epg-cancel (context) (if (buffer-live-p (process-buffer (epg-context-process context))) - (save-excursion - (set-buffer (process-buffer (epg-context-process context))) + (with-current-buffer (process-buffer (epg-context-process context)) (epg-context-set-result-for epg-context 'error (cons '(quit) @@ -1918,7 +1941,6 @@ You can then use `write-region' to write new data into the file." (if (eq (process-status (epg-context-process context)) 'run) (delete-process (epg-context-process context)))) -;;;###autoload (defun epg-start-decrypt (context cipher) "Initiate a decrypt operation on CIPHER. CIPHER must be a file data object. @@ -1950,7 +1972,6 @@ If you are unsure, use synchronous version of this function (signal 'epg-error (list "No data"))) (signal 'epg-error (list "Can't decrypt" error))))) -;;;###autoload (defun epg-decrypt-file (context cipher plain) "Decrypt a file CIPHER and store the result to a file PLAIN. If PLAIN is nil, it returns the result as a string." @@ -1969,7 +1990,6 @@ If PLAIN is nil, it returns the result as a string." (epg-delete-output-file context)) (epg-reset context))) -;;;###autoload (defun epg-decrypt-string (context cipher) "Decrypt a string CIPHER and return the plain text." (let ((input-file (epg--make-temp-file "epg-input")) @@ -1988,7 +2008,6 @@ If PLAIN is nil, it returns the result as a string." (delete-file input-file)) (epg-reset context)))) -;;;###autoload (defun epg-start-verify (context signature &optional signed-text) "Initiate a verify operation on SIGNATURE. SIGNATURE and SIGNED-TEXT are a data object if they are specified. @@ -2029,7 +2048,6 @@ If you are unsure, use synchronous version of this function (if (eq (process-status (epg-context-process context)) 'run) (process-send-eof (epg-context-process context)))))) -;;;###autoload (defun epg-verify-file (context signature &optional signed-text plain) "Verify a file SIGNATURE. SIGNED-TEXT and PLAIN are also a file if they are specified. @@ -2057,7 +2075,6 @@ stored into the file after successful verification." (epg-delete-output-file context)) (epg-reset context))) -;;;###autoload (defun epg-verify-string (context signature &optional signed-text) "Verify a string SIGNATURE. SIGNED-TEXT is a string if it is specified. @@ -2088,7 +2105,6 @@ successful verification." (delete-file input-file)) (epg-reset context)))) -;;;###autoload (defun epg-start-sign (context plain &optional mode) "Initiate a sign operation on PLAIN. PLAIN is a data object. @@ -2134,7 +2150,6 @@ If you are unsure, use synchronous version of this function (if (eq (process-status (epg-context-process context)) 'run) (process-send-eof (epg-context-process context))))) -;;;###autoload (defun epg-sign-file (context plain signature &optional mode) "Sign a file PLAIN and store the result to a file SIGNATURE. If SIGNATURE is nil, it returns the result as a string. @@ -2160,7 +2175,6 @@ Otherwise, it makes a cleartext signature." (epg-delete-output-file context)) (epg-reset context))) -;;;###autoload (defun epg-sign-string (context plain &optional mode) "Sign a string PLAIN and return the output as string. If optional 3rd argument MODE is t or 'detached, it makes a detached signature. @@ -2198,7 +2212,6 @@ Otherwise, it makes a cleartext signature." (delete-file input-file)) (epg-reset context)))) -;;;###autoload (defun epg-start-encrypt (context plain recipients &optional sign always-trust) "Initiate an encrypt operation on PLAIN. @@ -2249,7 +2262,6 @@ If you are unsure, use synchronous version of this function (if (eq (process-status (epg-context-process context)) 'run) (process-send-eof (epg-context-process context))))) -;;;###autoload (defun epg-encrypt-file (context plain recipients cipher &optional sign always-trust) "Encrypt a file PLAIN and store the result to a file CIPHER. @@ -2279,7 +2291,6 @@ If RECIPIENTS is nil, it performs symmetric encryption." (epg-delete-output-file context)) (epg-reset context))) -;;;###autoload (defun epg-encrypt-string (context plain recipients &optional sign always-trust) "Encrypt a string PLAIN. @@ -2321,7 +2332,6 @@ If RECIPIENTS is nil, it performs symmetric encryption." (delete-file input-file)) (epg-reset context)))) -;;;###autoload (defun epg-start-export-keys (context keys) "Initiate an export keys operation. @@ -2339,7 +2349,6 @@ If you are unsure, use synchronous version of this function (car (epg-key-sub-key-list key)))) keys)))) -;;;###autoload (defun epg-export-keys-to-file (context keys file) "Extract public KEYS." (unwind-protect @@ -2359,12 +2368,10 @@ If you are unsure, use synchronous version of this function (epg-delete-output-file context)) (epg-reset context))) -;;;###autoload (defun epg-export-keys-to-string (context keys) "Extract public KEYS and return them as a string." (epg-export-keys-to-file context keys nil)) -;;;###autoload (defun epg-start-import-keys (context keys) "Initiate an import keys operation. KEYS is a data object. @@ -2396,17 +2403,14 @@ If you are unsure, use synchronous version of this function (epg-context-result-for context 'error)))) (epg-reset context))) -;;;###autoload (defun epg-import-keys-from-file (context keys) "Add keys from a file KEYS." (epg--import-keys-1 context (epg-make-data-from-file keys))) -;;;###autoload (defun epg-import-keys-from-string (context keys) "Add keys from a string KEYS." (epg--import-keys-1 context (epg-make-data-from-string keys))) -;;;###autoload (defun epg-start-receive-keys (context key-id-list) "Initiate a receive key operation. KEY-ID-LIST is a list of key IDs. @@ -2420,7 +2424,6 @@ If you are unsure, use synchronous version of this function (epg-context-set-result context nil) (epg--start context (cons "--recv-keys" key-id-list))) -;;;###autoload (defun epg-receive-keys (context keys) "Add keys from server. KEYS is a list of key IDs" @@ -2433,10 +2436,8 @@ KEYS is a list of key IDs" (epg-context-result-for context 'error)))) (epg-reset context))) -;;;###autoload (defalias 'epg-import-keys-from-server 'epg-receive-keys) -;;;###autoload (defun epg-start-delete-keys (context keys &optional allow-secret) "Initiate a delete keys operation. @@ -2456,7 +2457,6 @@ If you are unsure, use synchronous version of this function (car (epg-key-sub-key-list key)))) keys)))) -;;;###autoload (defun epg-delete-keys (context keys &optional allow-secret) "Delete KEYS from the key ring." (unwind-protect @@ -2472,7 +2472,6 @@ If you are unsure, use synchronous version of this function (error "Delete keys failed"))))) (epg-reset context))) -;;;###autoload (defun epg-start-sign-keys (context keys &optional local) "Initiate a sign keys operation. @@ -2491,9 +2490,8 @@ If you are unsure, use synchronous version of this function (epg-sub-key-id (car (epg-key-sub-key-list key)))) keys)))) -(make-obsolete 'epg-start-sign-keys "do not use.") +(make-obsolete 'epg-start-sign-keys "do not use." "23.1") -;;;###autoload (defun epg-sign-keys (context keys &optional local) "Sign KEYS from the key ring." (unwind-protect @@ -2504,9 +2502,8 @@ If you are unsure, use synchronous version of this function (error "Sign keys failed: %S" (epg-context-result-for context 'error)))) (epg-reset context))) -(make-obsolete 'epg-sign-keys "do not use.") +(make-obsolete 'epg-sign-keys "do not use." "23.1") -;;;###autoload (defun epg-start-generate-key (context parameters) "Initiate a key generation. PARAMETERS specifies parameters for the key. @@ -2528,7 +2525,6 @@ If you are unsure, use synchronous version of this function (if (eq (process-status (epg-context-process context)) 'run) (process-send-eof (epg-context-process context))))) -;;;###autoload (defun epg-generate-key-from-file (context parameters) "Generate a new key pair. PARAMETERS is a file which tells how to create the key." @@ -2541,7 +2537,6 @@ PARAMETERS is a file which tells how to create the key." (epg-context-result-for context 'error)))) (epg-reset context))) -;;;###autoload (defun epg-generate-key-from-string (context parameters) "Generate a new key pair. PARAMETERS is a string which tells how to create the key." @@ -2654,5 +2649,4 @@ Type names are resolved using `epg-dn-type-alist'." (provide 'epg) -;; arch-tag: de8f0acc-1bcf-4c14-a09e-bfffe1b579b7 ;;; epg.el ends here