diff options
| author | Daiki Ueno | 2014-11-06 12:04:22 +0900 |
|---|---|---|
| committer | Daiki Ueno | 2014-11-06 12:04:22 +0900 |
| commit | 9e48a95cf29f39b30b03e946cdd05c7664053fd7 (patch) | |
| tree | d326b72cab3c7aa3d17411bd017207e59d263bce | |
| parent | e1418d0e252b8f2b42eea18f16b25a78ca2ac721 (diff) | |
| download | emacs-9e48a95cf29f39b30b03e946cdd05c7664053fd7.tar.gz emacs-9e48a95cf29f39b30b03e946cdd05c7664053fd7.zip | |
epg: Improve error handling
* epa.el (epa-error-buffer): New variable.
(epa-display-error): New function.
(epa-decrypt-file, epa-verify-file, epa-verify-region)
(epa-delete-keys, epa-import-keys): Display output sent to stderr.
(epa-sign-file, epa-sign-region, epa-encrypt-region)
(epa-export-keys, epa-insert-keys): Display output sent to stderr.
Use setf instead of epg-context-set-*.
* epa-file.el (epa-file-insert-file-contents): Use
epa-display-error instead of epa-display-info. Mimic the behavior
of jka-compr when decryption program is not found.
(epa-file-write-region): Use epa-display-error instead of
epa-display-info.
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/epa-file.el | 28 | ||||
| -rw-r--r-- | lisp/epa.el | 261 |
3 files changed, 197 insertions, 107 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a0108305ac3..e81b3a736a7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2014-11-06 Daiki Ueno <ueno@gnu.org> | ||
| 2 | |||
| 3 | * epa.el (epa-error-buffer): New variable. | ||
| 4 | (epa-display-error): New function. | ||
| 5 | (epa-decrypt-file, epa-verify-file, epa-verify-region) | ||
| 6 | (epa-delete-keys, epa-import-keys): Display output sent to stderr. | ||
| 7 | (epa-sign-file, epa-sign-region, epa-encrypt-region) | ||
| 8 | (epa-export-keys, epa-insert-keys): Display output sent to stderr. | ||
| 9 | Use setf instead of epg-context-set-*. | ||
| 10 | * epa-file.el (epa-file-insert-file-contents): Use | ||
| 11 | epa-display-error instead of epa-display-info. Mimic the behavior | ||
| 12 | of jka-compr when decryption program is not found. | ||
| 13 | (epa-file-write-region): Use epa-display-error instead of | ||
| 14 | epa-display-info. | ||
| 15 | |||
| 1 | 2014-11-05 Stefan Monnier <monnier@iro.umontreal.ca> | 16 | 2014-11-05 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 17 | ||
| 3 | * vc/vc.el (vc-region-history): New command. | 18 | * vc/vc.el (vc-region-history): New command. |
diff --git a/lisp/epa-file.el b/lisp/epa-file.el index 6f3bb188190..759271bc4e8 100644 --- a/lisp/epa-file.el +++ b/lisp/epa-file.el | |||
| @@ -105,9 +105,9 @@ encryption is used." | |||
| 105 | (insert (if enable-multibyte-characters | 105 | (insert (if enable-multibyte-characters |
| 106 | (string-to-multibyte string) | 106 | (string-to-multibyte string) |
| 107 | string)) | 107 | string)) |
| 108 | (decode-coding-inserted-region | 108 | (decode-coding-inserted-region |
| 109 | (point-min) (point-max) | 109 | (point-min) (point-max) |
| 110 | (substring file 0 (string-match epa-file-name-regexp file)) | 110 | (substring file 0 (string-match epa-file-name-regexp file)) |
| 111 | visit beg end replace)) | 111 | visit beg end replace)) |
| 112 | (insert (epa-file--decode-coding-string string (or coding-system-for-read | 112 | (insert (epa-file--decode-coding-string string (or coding-system-for-read |
| 113 | 'undecided))))) | 113 | 'undecided))))) |
| @@ -151,8 +151,17 @@ encryption is used." | |||
| 151 | (condition-case error | 151 | (condition-case error |
| 152 | (setq string (epg-decrypt-file context local-file nil)) | 152 | (setq string (epg-decrypt-file context local-file nil)) |
| 153 | (error | 153 | (error |
| 154 | (epa-display-error context) | ||
| 154 | (if (setq entry (assoc file epa-file-passphrase-alist)) | 155 | (if (setq entry (assoc file epa-file-passphrase-alist)) |
| 155 | (setcdr entry nil)) | 156 | (setcdr entry nil)) |
| 157 | ;; If the decryption program can't be found, | ||
| 158 | ;; signal that as a non-file error | ||
| 159 | ;; so that find-file-noselect-1 won't handle it. | ||
| 160 | ;; Borrowed from jka-compr.el. | ||
| 161 | (if (and (eq (car error) 'file-error) | ||
| 162 | (equal (cadr error) "Searching for program")) | ||
| 163 | (error "Decryption program `%s' not found" | ||
| 164 | (nth 3 error))) | ||
| 156 | ;; Hack to prevent find-file from opening empty buffer | 165 | ;; Hack to prevent find-file from opening empty buffer |
| 157 | ;; when decryption failed (bug#6568). See the place | 166 | ;; when decryption failed (bug#6568). See the place |
| 158 | ;; where `find-file-not-found-functions' are called in | 167 | ;; where `find-file-not-found-functions' are called in |
| @@ -162,11 +171,6 @@ encryption is used." | |||
| 162 | (add-hook 'find-file-not-found-functions | 171 | (add-hook 'find-file-not-found-functions |
| 163 | 'epa-file--find-file-not-found-function | 172 | 'epa-file--find-file-not-found-function |
| 164 | nil t)) | 173 | nil t)) |
| 165 | (if (epg-context-error-output context) | ||
| 166 | (epa-display-info | ||
| 167 | (concat (format "Error while executing \"%s\":\n\n" | ||
| 168 | epg-gpg-program) | ||
| 169 | (epg-context-error-output context)))) | ||
| 170 | (signal 'file-error | 174 | (signal 'file-error |
| 171 | (cons "Opening input file" (cdr error))))) | 175 | (cons "Opening input file" (cdr error))))) |
| 172 | (set-buffer buf) ;In case timer/filter changed/killed it (bug#16029)! | 176 | (set-buffer buf) ;In case timer/filter changed/killed it (bug#16029)! |
| @@ -226,7 +230,7 @@ encryption is used." | |||
| 226 | context | 230 | context |
| 227 | (cons #'epa-progress-callback-function | 231 | (cons #'epa-progress-callback-function |
| 228 | (format "Encrypting %s" file))) | 232 | (format "Encrypting %s" file))) |
| 229 | (epg-context-set-armor context epa-armor) | 233 | (setf (epg-context-armor context) epa-armor) |
| 230 | (condition-case error | 234 | (condition-case error |
| 231 | (setq string | 235 | (setq string |
| 232 | (epg-encrypt-string | 236 | (epg-encrypt-string |
| @@ -260,13 +264,9 @@ If no one is selected, symmetric encryption will be performed. " | |||
| 260 | (if epa-file-encrypt-to | 264 | (if epa-file-encrypt-to |
| 261 | (epg-list-keys context recipients))))) | 265 | (epg-list-keys context recipients))))) |
| 262 | (error | 266 | (error |
| 267 | (epa-display-error context) | ||
| 263 | (if (setq entry (assoc file epa-file-passphrase-alist)) | 268 | (if (setq entry (assoc file epa-file-passphrase-alist)) |
| 264 | (setcdr entry nil)) | 269 | (setcdr entry nil)) |
| 265 | (if (epg-context-error-output context) | ||
| 266 | (epa-display-info | ||
| 267 | (concat (format "Error while executing \"%s\":\n\n" | ||
| 268 | epg-gpg-program) | ||
| 269 | (epg-context-error-output context)))) | ||
| 270 | (signal 'file-error (cons "Opening output file" (cdr error))))) | 270 | (signal 'file-error (cons "Opening output file" (cdr error))))) |
| 271 | (epa-file-run-real-handler | 271 | (epa-file-run-real-handler |
| 272 | #'write-region | 272 | #'write-region |
diff --git a/lisp/epa.el b/lisp/epa.el index 0c833ab84d6..6d20a190d9c 100644 --- a/lisp/epa.el +++ b/lisp/epa.el | |||
| @@ -166,6 +166,7 @@ You should bind this variable with `let', but do not set it globally.") | |||
| 166 | (defvar epa-key nil) | 166 | (defvar epa-key nil) |
| 167 | (defvar epa-list-keys-arguments nil) | 167 | (defvar epa-list-keys-arguments nil) |
| 168 | (defvar epa-info-buffer nil) | 168 | (defvar epa-info-buffer nil) |
| 169 | (defvar epa-error-buffer nil) | ||
| 169 | (defvar epa-last-coding-system-specified nil) | 170 | (defvar epa-last-coding-system-specified nil) |
| 170 | 171 | ||
| 171 | (defvar epa-key-list-mode-map | 172 | (defvar epa-key-list-mode-map |
| @@ -578,6 +579,34 @@ If SECRET is non-nil, list secret keys instead of public keys." | |||
| 578 | (shrink-window (- (window-height) epa-info-window-height))))) | 579 | (shrink-window (- (window-height) epa-info-window-height))))) |
| 579 | (message "%s" info))) | 580 | (message "%s" info))) |
| 580 | 581 | ||
| 582 | (defun epa-display-error (context) | ||
| 583 | (unless (equal (epg-context-error-output context) "") | ||
| 584 | (let ((buffer (get-buffer-create "*Error*"))) | ||
| 585 | (save-selected-window | ||
| 586 | (unless (and epa-error-buffer (buffer-live-p epa-error-buffer)) | ||
| 587 | (setq epa-error-buffer (generate-new-buffer "*Error*"))) | ||
| 588 | (if (get-buffer-window epa-error-buffer) | ||
| 589 | (delete-window (get-buffer-window epa-error-buffer))) | ||
| 590 | (with-current-buffer buffer | ||
| 591 | (let ((inhibit-read-only t) | ||
| 592 | buffer-read-only) | ||
| 593 | (erase-buffer) | ||
| 594 | (insert (format | ||
| 595 | (pcase (epg-context-operation context) | ||
| 596 | (`decrypt "Error while decrypting with \"%s\":") | ||
| 597 | (`verify "Error while verifying with \"%s\":") | ||
| 598 | (`sign "Error while signing with \"%s\":") | ||
| 599 | (`encrypt "Error while encrypting with \"%s\":") | ||
| 600 | (`import-keys "Error while importing keys with \"%s\":") | ||
| 601 | (`export-keys "Error while exporting keys with \"%s\":") | ||
| 602 | (_ "Error while executing \"%s\":\n\n")) | ||
| 603 | epg-gpg-program) | ||
| 604 | "\n\n" | ||
| 605 | (epg-context-error-output context))) | ||
| 606 | (epa-info-mode) | ||
| 607 | (goto-char (point-min))) | ||
| 608 | (display-buffer buffer))))) | ||
| 609 | |||
| 581 | (defun epa-display-verify-result (verify-result) | 610 | (defun epa-display-verify-result (verify-result) |
| 582 | (declare (obsolete epa-display-info "23.1")) | 611 | (declare (obsolete epa-display-info "23.1")) |
| 583 | (epa-display-info (epg-verify-result-to-string verify-result))) | 612 | (epa-display-info (epg-verify-result-to-string verify-result))) |
| @@ -593,14 +622,14 @@ If SECRET is non-nil, list secret keys instead of public keys." | |||
| 593 | (eq (epg-context-operation context) 'encrypt)) | 622 | (eq (epg-context-operation context) 'encrypt)) |
| 594 | (read-passwd | 623 | (read-passwd |
| 595 | (if (eq key-id 'PIN) | 624 | (if (eq key-id 'PIN) |
| 596 | "Passphrase for PIN: " | 625 | "Passphrase for PIN: " |
| 597 | (let ((entry (assoc key-id epg-user-id-alist))) | 626 | (let ((entry (assoc key-id epg-user-id-alist))) |
| 598 | (if entry | 627 | (if entry |
| 599 | (format "Passphrase for %s %s: " key-id (cdr entry)) | 628 | (format "Passphrase for %s %s: " key-id (cdr entry)) |
| 600 | (format "Passphrase for %s: " key-id))))))) | 629 | (format "Passphrase for %s: " key-id))))))) |
| 601 | 630 | ||
| 602 | (defun epa-progress-callback-function (_context what _char current total | 631 | (defun epa-progress-callback-function (_context what _char current total |
| 603 | handback) | 632 | handback) |
| 604 | (let ((prompt (or handback | 633 | (let ((prompt (or handback |
| 605 | (format "Processing %s: " what)))) | 634 | (format "Processing %s: " what)))) |
| 606 | ;; According to gnupg/doc/DETAIL: a "total" of 0 indicates that | 635 | ;; According to gnupg/doc/DETAIL: a "total" of 0 indicates that |
| @@ -641,7 +670,11 @@ If you do not specify PLAIN-FILE, this functions prompts for the value to use." | |||
| 641 | (format "Decrypting %s..." | 670 | (format "Decrypting %s..." |
| 642 | (file-name-nondirectory decrypt-file)))) | 671 | (file-name-nondirectory decrypt-file)))) |
| 643 | (message "Decrypting %s..." (file-name-nondirectory decrypt-file)) | 672 | (message "Decrypting %s..." (file-name-nondirectory decrypt-file)) |
| 644 | (epg-decrypt-file context decrypt-file plain-file) | 673 | (condition-case error |
| 674 | (epg-decrypt-file context decrypt-file plain-file) | ||
| 675 | (error | ||
| 676 | (epa-display-error context) | ||
| 677 | (signal (car error) (cdr error)))) | ||
| 645 | (message "Decrypting %s...wrote %s" (file-name-nondirectory decrypt-file) | 678 | (message "Decrypting %s...wrote %s" (file-name-nondirectory decrypt-file) |
| 646 | (file-name-nondirectory plain-file)) | 679 | (file-name-nondirectory plain-file)) |
| 647 | (if (epg-context-result-for context 'verify) | 680 | (if (epg-context-result-for context 'verify) |
| @@ -662,7 +695,11 @@ If you do not specify PLAIN-FILE, this functions prompts for the value to use." | |||
| 662 | (format "Verifying %s..." | 695 | (format "Verifying %s..." |
| 663 | (file-name-nondirectory file)))) | 696 | (file-name-nondirectory file)))) |
| 664 | (message "Verifying %s..." (file-name-nondirectory file)) | 697 | (message "Verifying %s..." (file-name-nondirectory file)) |
| 665 | (epg-verify-file context file plain) | 698 | (condition-case error |
| 699 | (epg-verify-file context file plain) | ||
| 700 | (error | ||
| 701 | (epa-display-error context) | ||
| 702 | (signal (car error) (cdr error)))) | ||
| 666 | (message "Verifying %s...done" (file-name-nondirectory file)) | 703 | (message "Verifying %s...done" (file-name-nondirectory file)) |
| 667 | (if (epg-context-result-for context 'verify) | 704 | (if (epg-context-result-for context 'verify) |
| 668 | (epa-display-info (epg-verify-result-to-string | 705 | (epa-display-info (epg-verify-result-to-string |
| @@ -717,18 +754,22 @@ If no one is selected, default secret key is used. " | |||
| 717 | ".p7s" | 754 | ".p7s" |
| 718 | ".p7m")))) | 755 | ".p7m")))) |
| 719 | (context (epg-make-context epa-protocol))) | 756 | (context (epg-make-context epa-protocol))) |
| 720 | (epg-context-set-armor context epa-armor) | 757 | (setf (epg-context-armor context) epa-armor) |
| 721 | (epg-context-set-textmode context epa-textmode) | 758 | (setf (epg-context-textmode context) epa-textmode) |
| 722 | (epg-context-set-signers context signers) | 759 | (setf (epg-context-signers context) signers) |
| 723 | (epg-context-set-passphrase-callback context | 760 | (setf (epg-context-passphrase-callback context) |
| 724 | #'epa-passphrase-callback-function) | 761 | #'epa-passphrase-callback-function) |
| 725 | (epg-context-set-progress-callback context | 762 | (setf (epg-context-progress-callback context) |
| 726 | (cons | 763 | (cons |
| 727 | #'epa-progress-callback-function | 764 | #'epa-progress-callback-function |
| 728 | (format "Signing %s..." | 765 | (format "Signing %s..." |
| 729 | (file-name-nondirectory file)))) | 766 | (file-name-nondirectory file)))) |
| 730 | (message "Signing %s..." (file-name-nondirectory file)) | 767 | (message "Signing %s..." (file-name-nondirectory file)) |
| 731 | (epg-sign-file context file signature mode) | 768 | (condition-case error |
| 769 | (epg-sign-file context file signature mode) | ||
| 770 | (error | ||
| 771 | (epa-display-error context) | ||
| 772 | (signal (car error) (cdr error)))) | ||
| 732 | (message "Signing %s...wrote %s" (file-name-nondirectory file) | 773 | (message "Signing %s...wrote %s" (file-name-nondirectory file) |
| 733 | (file-name-nondirectory signature)))) | 774 | (file-name-nondirectory signature)))) |
| 734 | 775 | ||
| @@ -744,17 +785,21 @@ If no one is selected, symmetric encryption will be performed. "))) | |||
| 744 | (if epa-armor ".asc" ".gpg") | 785 | (if epa-armor ".asc" ".gpg") |
| 745 | ".p7m"))) | 786 | ".p7m"))) |
| 746 | (context (epg-make-context epa-protocol))) | 787 | (context (epg-make-context epa-protocol))) |
| 747 | (epg-context-set-armor context epa-armor) | 788 | (setf (epg-context-armor context) epa-armor) |
| 748 | (epg-context-set-textmode context epa-textmode) | 789 | (setf (epg-context-textmode context) epa-textmode) |
| 749 | (epg-context-set-passphrase-callback context | 790 | (setf (epg-context-passphrase-callback context) |
| 750 | #'epa-passphrase-callback-function) | 791 | #'epa-passphrase-callback-function) |
| 751 | (epg-context-set-progress-callback context | 792 | (setf (epg-context-progress-callback context) |
| 752 | (cons | 793 | (cons |
| 753 | #'epa-progress-callback-function | 794 | #'epa-progress-callback-function |
| 754 | (format "Encrypting %s..." | 795 | (format "Encrypting %s..." |
| 755 | (file-name-nondirectory file)))) | 796 | (file-name-nondirectory file)))) |
| 756 | (message "Encrypting %s..." (file-name-nondirectory file)) | 797 | (message "Encrypting %s..." (file-name-nondirectory file)) |
| 757 | (epg-encrypt-file context file recipients cipher) | 798 | (condition-case error |
| 799 | (epg-encrypt-file context file recipients cipher) | ||
| 800 | (error | ||
| 801 | (epa-display-error context) | ||
| 802 | (signal (car error) (cdr error)))) | ||
| 758 | (message "Encrypting %s...wrote %s" (file-name-nondirectory file) | 803 | (message "Encrypting %s...wrote %s" (file-name-nondirectory file) |
| 759 | (file-name-nondirectory cipher)))) | 804 | (file-name-nondirectory cipher)))) |
| 760 | 805 | ||
| @@ -785,14 +830,18 @@ For example: | |||
| 785 | (save-excursion | 830 | (save-excursion |
| 786 | (let ((context (epg-make-context epa-protocol)) | 831 | (let ((context (epg-make-context epa-protocol)) |
| 787 | plain) | 832 | plain) |
| 788 | (epg-context-set-passphrase-callback context | 833 | (setf (epg-context-passphrase-callback context) |
| 789 | #'epa-passphrase-callback-function) | 834 | #'epa-passphrase-callback-function) |
| 790 | (epg-context-set-progress-callback context | 835 | (setf (epg-context-progress-callback context) |
| 791 | (cons | 836 | (cons |
| 792 | #'epa-progress-callback-function | 837 | #'epa-progress-callback-function |
| 793 | "Decrypting...")) | 838 | "Decrypting...")) |
| 794 | (message "Decrypting...") | 839 | (message "Decrypting...") |
| 795 | (setq plain (epg-decrypt-string context (buffer-substring start end))) | 840 | (condition-case error |
| 841 | (setq plain (epg-decrypt-string context (buffer-substring start end))) | ||
| 842 | (error | ||
| 843 | (epa-display-error context) | ||
| 844 | (signal (car error) (cdr error)))) | ||
| 796 | (message "Decrypting...done") | 845 | (message "Decrypting...done") |
| 797 | (setq plain (epa--decode-coding-string | 846 | (setq plain (epa--decode-coding-string |
| 798 | plain | 847 | plain |
| @@ -810,8 +859,8 @@ For example: | |||
| 810 | (insert plain)) | 859 | (insert plain)) |
| 811 | (with-output-to-temp-buffer "*Temp*" | 860 | (with-output-to-temp-buffer "*Temp*" |
| 812 | (set-buffer standard-output) | 861 | (set-buffer standard-output) |
| 813 | (insert plain) | 862 | (insert plain) |
| 814 | (epa-info-mode)))) | 863 | (epa-info-mode)))) |
| 815 | (if (epg-context-result-for context 'verify) | 864 | (if (epg-context-result-for context 'verify) |
| 816 | (epa-display-info (epg-verify-result-to-string | 865 | (epa-display-info (epg-verify-result-to-string |
| 817 | (epg-context-result-for context 'verify))))))) | 866 | (epg-context-result-for context 'verify))))))) |
| @@ -878,17 +927,21 @@ For example: | |||
| 878 | (interactive "r") | 927 | (interactive "r") |
| 879 | (let ((context (epg-make-context epa-protocol)) | 928 | (let ((context (epg-make-context epa-protocol)) |
| 880 | plain) | 929 | plain) |
| 881 | (epg-context-set-progress-callback context | 930 | (setf (epg-context-progress-callback context) |
| 882 | (cons | 931 | (cons |
| 883 | #'epa-progress-callback-function | 932 | #'epa-progress-callback-function |
| 884 | "Verifying...")) | 933 | "Verifying...")) |
| 885 | (message "Verifying...") | 934 | (message "Verifying...") |
| 886 | (setq plain (epg-verify-string | 935 | (condition-case error |
| 887 | context | 936 | (setq plain (epg-verify-string |
| 888 | (epa--encode-coding-string | 937 | context |
| 889 | (buffer-substring start end) | 938 | (epa--encode-coding-string |
| 890 | (or coding-system-for-write | 939 | (buffer-substring start end) |
| 891 | (get-text-property start 'epa-coding-system-used))))) | 940 | (or coding-system-for-write |
| 941 | (get-text-property start 'epa-coding-system-used))))) | ||
| 942 | (error | ||
| 943 | (epa-display-error context) | ||
| 944 | (signal (car error) (cdr error)))) | ||
| 892 | (message "Verifying...done") | 945 | (message "Verifying...done") |
| 893 | (setq plain (epa--decode-coding-string | 946 | (setq plain (epa--decode-coding-string |
| 894 | plain | 947 | plain |
| @@ -927,11 +980,11 @@ See the reason described in the `epa-verify-region' documentation." | |||
| 927 | nil t) | 980 | nil t) |
| 928 | (setq cleartext-start (match-beginning 0)) | 981 | (setq cleartext-start (match-beginning 0)) |
| 929 | (unless (re-search-forward "^-----BEGIN PGP SIGNATURE-----$" | 982 | (unless (re-search-forward "^-----BEGIN PGP SIGNATURE-----$" |
| 930 | nil t) | 983 | nil t) |
| 931 | (error "Invalid cleartext signed message")) | 984 | (error "Invalid cleartext signed message")) |
| 932 | (setq cleartext-end (re-search-forward | 985 | (setq cleartext-end (re-search-forward |
| 933 | "^-----END PGP SIGNATURE-----$" | 986 | "^-----END PGP SIGNATURE-----$" |
| 934 | nil t)) | 987 | nil t)) |
| 935 | (unless cleartext-end | 988 | (unless cleartext-end |
| 936 | (error "No cleartext tail")) | 989 | (error "No cleartext tail")) |
| 937 | (epa-verify-region cleartext-start cleartext-end)))))) | 990 | (epa-verify-region cleartext-start cleartext-end)))))) |
| @@ -978,23 +1031,27 @@ If no one is selected, default secret key is used. " | |||
| 978 | (save-excursion | 1031 | (save-excursion |
| 979 | (let ((context (epg-make-context epa-protocol)) | 1032 | (let ((context (epg-make-context epa-protocol)) |
| 980 | signature) | 1033 | signature) |
| 981 | ;;(epg-context-set-armor context epa-armor) | 1034 | ;;(setf (epg-context-armor context) epa-armor) |
| 982 | (epg-context-set-armor context t) | 1035 | (setf (epg-context-armor context) t) |
| 983 | ;;(epg-context-set-textmode context epa-textmode) | 1036 | ;;(setf (epg-context-textmode context) epa-textmode) |
| 984 | (epg-context-set-textmode context t) | 1037 | (setf (epg-context-textmode context) t) |
| 985 | (epg-context-set-signers context signers) | 1038 | (setf (epg-context-signers context) signers) |
| 986 | (epg-context-set-passphrase-callback context | 1039 | (setf (epg-context-passphrase-callback context) |
| 987 | #'epa-passphrase-callback-function) | 1040 | #'epa-passphrase-callback-function) |
| 988 | (epg-context-set-progress-callback context | 1041 | (setf (epg-context-progress-callback context) |
| 989 | (cons | 1042 | (cons |
| 990 | #'epa-progress-callback-function | 1043 | #'epa-progress-callback-function |
| 991 | "Signing...")) | 1044 | "Signing...")) |
| 992 | (message "Signing...") | 1045 | (message "Signing...") |
| 993 | (setq signature (epg-sign-string context | 1046 | (condition-case error |
| 994 | (epa--encode-coding-string | 1047 | (setq signature (epg-sign-string context |
| 995 | (buffer-substring start end) | 1048 | (epa--encode-coding-string |
| 996 | epa-last-coding-system-specified) | 1049 | (buffer-substring start end) |
| 997 | mode)) | 1050 | epa-last-coding-system-specified) |
| 1051 | mode)) | ||
| 1052 | (error | ||
| 1053 | (epa-display-error context) | ||
| 1054 | (signal (car error) (cdr error)))) | ||
| 998 | (message "Signing...done") | 1055 | (message "Signing...done") |
| 999 | (delete-region start end) | 1056 | (delete-region start end) |
| 1000 | (goto-char start) | 1057 | (goto-char start) |
| @@ -1061,25 +1118,29 @@ If no one is selected, symmetric encryption will be performed. ") | |||
| 1061 | (save-excursion | 1118 | (save-excursion |
| 1062 | (let ((context (epg-make-context epa-protocol)) | 1119 | (let ((context (epg-make-context epa-protocol)) |
| 1063 | cipher) | 1120 | cipher) |
| 1064 | ;;(epg-context-set-armor context epa-armor) | 1121 | ;;(setf (epg-context-armor context) epa-armor) |
| 1065 | (epg-context-set-armor context t) | 1122 | (setf (epg-context-armor context) t) |
| 1066 | ;;(epg-context-set-textmode context epa-textmode) | 1123 | ;;(setf (epg-context-textmode context) epa-textmode) |
| 1067 | (epg-context-set-textmode context t) | 1124 | (setf (epg-context-textmode context) t) |
| 1068 | (if sign | 1125 | (if sign |
| 1069 | (epg-context-set-signers context signers)) | 1126 | (setf (epg-context-signers context) signers)) |
| 1070 | (epg-context-set-passphrase-callback context | 1127 | (setf (epg-context-passphrase-callback context) |
| 1071 | #'epa-passphrase-callback-function) | 1128 | #'epa-passphrase-callback-function) |
| 1072 | (epg-context-set-progress-callback context | 1129 | (setf (epg-context-progress-callback context) |
| 1073 | (cons | 1130 | (cons |
| 1074 | #'epa-progress-callback-function | 1131 | #'epa-progress-callback-function |
| 1075 | "Encrypting...")) | 1132 | "Encrypting...")) |
| 1076 | (message "Encrypting...") | 1133 | (message "Encrypting...") |
| 1077 | (setq cipher (epg-encrypt-string context | 1134 | (condition-case error |
| 1078 | (epa--encode-coding-string | 1135 | (setq cipher (epg-encrypt-string context |
| 1079 | (buffer-substring start end) | 1136 | (epa--encode-coding-string |
| 1080 | epa-last-coding-system-specified) | 1137 | (buffer-substring start end) |
| 1081 | recipients | 1138 | epa-last-coding-system-specified) |
| 1082 | sign)) | 1139 | recipients |
| 1140 | sign)) | ||
| 1141 | (error | ||
| 1142 | (epa-display-error context) | ||
| 1143 | (signal (car error) (cdr error)))) | ||
| 1083 | (message "Encrypting...done") | 1144 | (message "Encrypting...done") |
| 1084 | (delete-region start end) | 1145 | (delete-region start end) |
| 1085 | (goto-char start) | 1146 | (goto-char start) |
| @@ -1105,7 +1166,11 @@ If no one is selected, symmetric encryption will be performed. ") | |||
| 1105 | (eq (nth 1 epa-list-keys-arguments) t)))) | 1166 | (eq (nth 1 epa-list-keys-arguments) t)))) |
| 1106 | (let ((context (epg-make-context epa-protocol))) | 1167 | (let ((context (epg-make-context epa-protocol))) |
| 1107 | (message "Deleting...") | 1168 | (message "Deleting...") |
| 1108 | (epg-delete-keys context keys allow-secret) | 1169 | (condition-case error |
| 1170 | (epg-delete-keys context keys allow-secret) | ||
| 1171 | (error | ||
| 1172 | (epa-display-error context) | ||
| 1173 | (signal (car error) (cdr error)))) | ||
| 1109 | (message "Deleting...done") | 1174 | (message "Deleting...done") |
| 1110 | (apply #'epa--list-keys epa-list-keys-arguments))) | 1175 | (apply #'epa--list-keys epa-list-keys-arguments))) |
| 1111 | 1176 | ||
| @@ -1121,6 +1186,7 @@ If no one is selected, symmetric encryption will be performed. ") | |||
| 1121 | (epg-import-keys-from-file context file) | 1186 | (epg-import-keys-from-file context file) |
| 1122 | (message "Importing %s...done" (file-name-nondirectory file))) | 1187 | (message "Importing %s...done" (file-name-nondirectory file))) |
| 1123 | (error | 1188 | (error |
| 1189 | (epa-display-error context) | ||
| 1124 | (message "Importing %s...failed" (file-name-nondirectory file)))) | 1190 | (message "Importing %s...failed" (file-name-nondirectory file)))) |
| 1125 | (if (epg-context-result-for context 'import) | 1191 | (if (epg-context-result-for context 'import) |
| 1126 | (epa-display-info (epg-import-result-to-string | 1192 | (epa-display-info (epg-import-result-to-string |
| @@ -1140,6 +1206,7 @@ If no one is selected, symmetric encryption will be performed. ") | |||
| 1140 | (epg-import-keys-from-string context (buffer-substring start end)) | 1206 | (epg-import-keys-from-string context (buffer-substring start end)) |
| 1141 | (message "Importing...done")) | 1207 | (message "Importing...done")) |
| 1142 | (error | 1208 | (error |
| 1209 | (epa-display-error context) | ||
| 1143 | (message "Importing...failed"))) | 1210 | (message "Importing...failed"))) |
| 1144 | (if (epg-context-result-for context 'import) | 1211 | (if (epg-context-result-for context 'import) |
| 1145 | (epa-display-info (epg-import-result-to-string | 1212 | (epa-display-info (epg-import-result-to-string |
| @@ -1188,9 +1255,13 @@ between START and END." | |||
| 1188 | (file-name-directory default-name) | 1255 | (file-name-directory default-name) |
| 1189 | default-name))))) | 1256 | default-name))))) |
| 1190 | (let ((context (epg-make-context epa-protocol))) | 1257 | (let ((context (epg-make-context epa-protocol))) |
| 1191 | (epg-context-set-armor context epa-armor) | 1258 | (setf (epg-context-armor context) epa-armor) |
| 1192 | (message "Exporting to %s..." (file-name-nondirectory file)) | 1259 | (message "Exporting to %s..." (file-name-nondirectory file)) |
| 1193 | (epg-export-keys-to-file context keys file) | 1260 | (condition-case error |
| 1261 | (epg-export-keys-to-file context keys file) | ||
| 1262 | (error | ||
| 1263 | (epa-display-error context) | ||
| 1264 | (signal (car error) (cdr error)))) | ||
| 1194 | (message "Exporting to %s...done" (file-name-nondirectory file)))) | 1265 | (message "Exporting to %s...done" (file-name-nondirectory file)))) |
| 1195 | 1266 | ||
| 1196 | ;;;###autoload | 1267 | ;;;###autoload |
| @@ -1198,12 +1269,16 @@ between START and END." | |||
| 1198 | "Insert selected KEYS after the point." | 1269 | "Insert selected KEYS after the point." |
| 1199 | (interactive | 1270 | (interactive |
| 1200 | (list (epa-select-keys (epg-make-context epa-protocol) | 1271 | (list (epa-select-keys (epg-make-context epa-protocol) |
| 1201 | "Select keys to export. | 1272 | "Select keys to export. |
| 1202 | If no one is selected, default public key is exported. "))) | 1273 | If no one is selected, default public key is exported. "))) |
| 1203 | (let ((context (epg-make-context epa-protocol))) | 1274 | (let ((context (epg-make-context epa-protocol))) |
| 1204 | ;;(epg-context-set-armor context epa-armor) | 1275 | ;;(setf (epg-context-armor context) epa-armor) |
| 1205 | (epg-context-set-armor context t) | 1276 | (setf (epg-context-armor context) t) |
| 1206 | (insert (epg-export-keys-to-string context keys)))) | 1277 | (condition-case error |
| 1278 | (insert (epg-export-keys-to-string context keys)) | ||
| 1279 | (error | ||
| 1280 | (epa-display-error context) | ||
| 1281 | (signal (car error) (cdr error)))))) | ||
| 1207 | 1282 | ||
| 1208 | ;; (defun epa-sign-keys (keys &optional local) | 1283 | ;; (defun epa-sign-keys (keys &optional local) |
| 1209 | ;; "Sign selected KEYS. | 1284 | ;; "Sign selected KEYS. |
| @@ -1217,12 +1292,12 @@ If no one is selected, default public key is exported. "))) | |||
| 1217 | ;; (error "No keys selected")) | 1292 | ;; (error "No keys selected")) |
| 1218 | ;; (list keys current-prefix-arg))) | 1293 | ;; (list keys current-prefix-arg))) |
| 1219 | ;; (let ((context (epg-make-context epa-protocol))) | 1294 | ;; (let ((context (epg-make-context epa-protocol))) |
| 1220 | ;; (epg-context-set-passphrase-callback context | 1295 | ;; (setf (epg-context-passphrase-callback context) |
| 1221 | ;; #'epa-passphrase-callback-function) | 1296 | ;; #'epa-passphrase-callback-function) |
| 1222 | ;; (epg-context-set-progress-callback context | 1297 | ;; (setf (epg-context-progress-callback context) |
| 1223 | ;; (cons | 1298 | ;; (cons |
| 1224 | ;; #'epa-progress-callback-function | 1299 | ;; #'epa-progress-callback-function |
| 1225 | ;; "Signing keys...")) | 1300 | ;; "Signing keys...")) |
| 1226 | ;; (message "Signing keys...") | 1301 | ;; (message "Signing keys...") |
| 1227 | ;; (epg-sign-keys context keys local) | 1302 | ;; (epg-sign-keys context keys local) |
| 1228 | ;; (message "Signing keys...done"))) | 1303 | ;; (message "Signing keys...done"))) |