diff options
Diffstat (limited to 'lisp/epa.el')
-rw-r--r-- | lisp/epa.el | 120 |
1 files changed, 24 insertions, 96 deletions
diff --git a/lisp/epa.el b/lisp/epa.el index e442c12a7d6..9e6edf463c6 100644 --- a/lisp/epa.el +++ b/lisp/epa.el @@ -56,28 +56,6 @@ If neither t nor nil, ask user for confirmation." :type 'integer :group 'epa) -;; In the doc string below, we say "symbol `error'" to avoid producing -;; a hyperlink for `error' the function. -(defcustom epa-pinentry-mode nil - "The pinentry mode. - -GnuPG 2.1 or later has an option to control the behavior of -Pinentry invocation. The value should be the symbol `error', -`ask', `cancel', or `loopback'. See the GnuPG manual for the -meanings. - -In epa commands, a particularly useful mode is `loopback', which -redirects all Pinentry queries to the caller, so Emacs can query -passphrase through the minibuffer, instead of external Pinentry -program." - :type '(choice (const nil) - (const ask) - (const cancel) - (const error) - (const loopback)) - :group 'epa - :version "25.1") - (defgroup epa-faces nil "Faces for epa-mode." :version "23.1" @@ -307,21 +285,12 @@ You should bind this variable with `let', but do not set it globally.") (epg-sub-key-id (car (epg-key-sub-key-list (widget-get widget :value)))))) -(defalias 'epa--encode-coding-string - (if (fboundp 'encode-coding-string) #'encode-coding-string #'identity)) - -(defalias 'epa--decode-coding-string - (if (fboundp 'decode-coding-string) #'decode-coding-string #'identity)) - (define-derived-mode epa-key-list-mode special-mode "Keys" "Major mode for `epa-list-keys'." (buffer-disable-undo) (setq truncate-lines t buffer-read-only t) (setq-local font-lock-defaults '(epa-font-lock-keywords t)) - ;; In XEmacs, auto-initialization of font-lock is not effective - ;; if buffer-file-name is not set. - (font-lock-set-defaults) (make-local-variable 'epa-exit-buffer-function) (setq-local revert-buffer-function #'epa--key-list-revert-buffer)) @@ -331,9 +300,6 @@ You should bind this variable with `let', but do not set it globally.") (setq truncate-lines t buffer-read-only t) (setq-local font-lock-defaults '(epa-font-lock-keywords t)) - ;; In XEmacs, auto-initialization of font-lock is not effective - ;; if buffer-file-name is not set. - (font-lock-set-defaults) (make-local-variable 'epa-exit-buffer-function)) (define-derived-mode epa-info-mode special-mode "Info" @@ -565,7 +531,7 @@ If SECRET is non-nil, list secret keys instead of public keys." (epg-sub-key-creation-time (car pointer))) (error "????-??-??")) (if (epg-sub-key-expiration-time (car pointer)) - (format (if (time-less-p (current-time) + (format (if (time-less-p nil (epg-sub-key-expiration-time (car pointer))) "\n\tExpires: %s" @@ -625,12 +591,12 @@ If SECRET is non-nil, list secret keys instead of public keys." (erase-buffer) (insert (format (pcase (epg-context-operation context) - (`decrypt "Error while decrypting with \"%s\":") - (`verify "Error while verifying with \"%s\":") - (`sign "Error while signing with \"%s\":") - (`encrypt "Error while encrypting with \"%s\":") - (`import-keys "Error while importing keys with \"%s\":") - (`export-keys "Error while exporting keys with \"%s\":") + ('decrypt "Error while decrypting with \"%s\":") + ('verify "Error while verifying with \"%s\":") + ('sign "Error while signing with \"%s\":") + ('encrypt "Error while encrypting with \"%s\":") + ('import-keys "Error while importing keys with \"%s\":") + ('export-keys "Error while exporting keys with \"%s\":") (_ "Error while executing \"%s\":\n\n")) (epg-context-program context)) "\n\n" @@ -701,7 +667,6 @@ If you do not specify PLAIN-FILE, this functions prompts for the value to use." #'epa-progress-callback-function (format "Decrypting %s..." (file-name-nondirectory decrypt-file)))) - (setf (epg-context-pinentry-mode context) epa-pinentry-mode) (message "Decrypting %s..." (file-name-nondirectory decrypt-file)) (condition-case error (epg-decrypt-file context decrypt-file plain-file) @@ -797,7 +762,6 @@ If no one is selected, default secret key is used. " #'epa-progress-callback-function (format "Signing %s..." (file-name-nondirectory file)))) - (setf (epg-context-pinentry-mode context) epa-pinentry-mode) (message "Signing %s..." (file-name-nondirectory file)) (condition-case error (epg-sign-file context file signature mode) @@ -828,7 +792,6 @@ If no one is selected, symmetric encryption will be performed. "))) #'epa-progress-callback-function (format "Encrypting %s..." (file-name-nondirectory file)))) - (setf (epg-context-pinentry-mode context) epa-pinentry-mode) (message "Encrypting %s..." (file-name-nondirectory file)) (condition-case error (epg-encrypt-file context file recipients cipher) @@ -871,7 +834,6 @@ For example: (cons #'epa-progress-callback-function "Decrypting...")) - (setf (epg-context-pinentry-mode context) epa-pinentry-mode) (message "Decrypting...") (condition-case error (setq plain (epg-decrypt-string context (buffer-substring start end))) @@ -879,7 +841,7 @@ For example: (epa-display-error context) (signal (car error) (cdr error)))) (message "Decrypting...done") - (setq plain (epa--decode-coding-string + (setq plain (decode-coding-string plain (or coding-system-for-read (get-text-property start 'epa-coding-system-used) @@ -904,16 +866,13 @@ For example: (epg-context-result-for context 'verify))))))) (defun epa--find-coding-system-for-mime-charset (mime-charset) - (if (featurep 'xemacs) - (if (fboundp 'find-coding-system) - (find-coding-system mime-charset)) - ;; Find the first coding system which corresponds to MIME-CHARSET. - (let ((pointer (coding-system-list))) - (while (and pointer - (not (eq (coding-system-get (car pointer) 'mime-charset) - mime-charset))) - (setq pointer (cdr pointer))) - (car pointer)))) + ;; Find the first coding system which corresponds to MIME-CHARSET. + (let ((pointer (coding-system-list))) + (while (and pointer + (not (eq (coding-system-get (car pointer) 'mime-charset) + mime-charset))) + (setq pointer (cdr pointer))) + (car pointer))) ;;;###autoload (defun epa-decrypt-armor-in-region (start end) @@ -973,7 +932,7 @@ For example: (condition-case error (setq plain (epg-verify-string context - (epa--encode-coding-string + (encode-coding-string (buffer-substring start end) (or coding-system-for-write (get-text-property start 'epa-coding-system-used))))) @@ -981,7 +940,7 @@ For example: (epa-display-error context) (signal (car error) (cdr error)))) (message "Verifying...done") - (setq plain (epa--decode-coding-string + (setq plain (decode-coding-string plain (or coding-system-for-read (get-text-property start 'epa-coding-system-used) @@ -1027,13 +986,8 @@ See the reason described in the `epa-verify-region' documentation." nil t)) (unless cleartext-end (error "No cleartext tail")) - (epa-verify-region cleartext-start cleartext-end)))))) - -(defalias 'epa--select-safe-coding-system - (if (fboundp 'select-safe-coding-system) - #'select-safe-coding-system - (lambda (_from _to) - buffer-file-coding-system))) + (with-suppressed-warnings ((interactive-only epa-verify-region)) + (epa-verify-region cleartext-start cleartext-end))))))) ;;;###autoload (defun epa-sign-region (start end signers mode) @@ -1057,7 +1011,7 @@ For example: (let ((verbose current-prefix-arg)) (setq epa-last-coding-system-specified (or coding-system-for-write - (epa--select-safe-coding-system + (select-safe-coding-system (region-beginning) (region-end)))) (list (region-beginning) (region-end) (if verbose @@ -1082,11 +1036,10 @@ If no one is selected, default secret key is used. " (cons #'epa-progress-callback-function "Signing...")) - (setf (epg-context-pinentry-mode context) epa-pinentry-mode) (message "Signing...") (condition-case error (setq signature (epg-sign-string context - (epa--encode-coding-string + (encode-coding-string (buffer-substring start end) epa-last-coding-system-specified) mode)) @@ -1098,7 +1051,7 @@ If no one is selected, default secret key is used. " (goto-char start) (add-text-properties (point) (progn - (insert (epa--decode-coding-string + (insert (decode-coding-string signature (or coding-system-for-read epa-last-coding-system-specified))) @@ -1146,7 +1099,7 @@ For example: sign) (setq epa-last-coding-system-specified (or coding-system-for-write - (epa--select-safe-coding-system + (select-safe-coding-system (region-beginning) (region-end)))) (list (region-beginning) (region-end) (epa-select-keys context @@ -1171,11 +1124,10 @@ If no one is selected, symmetric encryption will be performed. ") (cons #'epa-progress-callback-function "Encrypting...")) - (setf (epg-context-pinentry-mode context) epa-pinentry-mode) (message "Encrypting...") (condition-case error (setq cipher (epg-encrypt-string context - (epa--encode-coding-string + (encode-coding-string (buffer-substring start end) epa-last-coding-system-specified) recipients @@ -1322,30 +1274,6 @@ If no one is selected, default public key is exported. "))) (epa-display-error context) (signal (car error) (cdr error)))))) -;; (defun epa-sign-keys (keys &optional local) -;; "Sign selected KEYS. -;; If a prefix-arg is specified, the signature is marked as non exportable. - -;; Don't use this command in Lisp programs!" -;; (declare (interactive-only t)) -;; (interactive -;; (let ((keys (epa--marked-keys))) -;; (unless keys -;; (error "No keys selected")) -;; (list keys current-prefix-arg))) -;; (let ((context (epg-make-context epa-protocol))) -;; (epg-context-set-passphrase-callback context -;; #'epa-passphrase-callback-function) -;; (epg-context-set-progress-callback context -;; (cons -;; #'epa-progress-callback-function -;; "Signing keys...")) -;; (setf (epg-context-pinentry-mode context) epa-pinentry-mode) -;; (message "Signing keys...") -;; (epg-sign-keys context keys local) -;; (message "Signing keys...done"))) -;; (make-obsolete 'epa-sign-keys "Do not use.") - (provide 'epa) ;;; epa.el ends here |