summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorMiha Rihtaršič <miha@kamnitnik.top>2024-03-09 11:27:50 +0100
committerMiha Rihtaršič <miha@kamnitnik.top>2024-03-09 11:35:08 +0100
commit98bfeb638aaef37c17266accdb3b5a153540d452 (patch)
tree1d598aee80b3ffad0b9ec64f5469b6d9367b7b52 /lisp
parent388950ae94558654fcc9c19bfd7530328f326919 (diff)
Don't retry with the same cached password upon decryption failure
Password cache may contain a stale password if a pdf file's password is modified. Re-read a new password without cache in this case, rather than retry with the same cached password 3 times and fail.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/pdf-view.el13
1 files changed, 11 insertions, 2 deletions
diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index d45571a..9cfb188 100644
--- a/lisp/pdf-view.el
+++ b/lisp/pdf-view.el
@@ -470,14 +470,23 @@ PNG images in Emacs buffers."
(prompt "Enter password for pdf document: ")
(i 3)
key password)
+
(when fn
(setq prompt (format "Enter password for `%s': "
(abbreviate-file-name fn)))
- (setq key (concat "/pdf-tools" fn)))
+ (setq key (concat "/pdf-tools" fn))
+ ;; First, try with a cached password
+ (when (setq password (password-read-from-cache key))
+ (ignore-errors (pdf-info-open nil password))
+ (when (pdf-info-encrypted-p)
+ (password-cache-remove key))))
+
(while (and (> i 0)
(pdf-info-encrypted-p))
(setq i (1- i))
- (setq password (password-read prompt key))
+ ;; Cached password was not present or valid, try reading a new password
+ ;; without cache.
+ (setq password (password-read prompt))
(setq prompt "Invalid password, try again: ")
(ignore-errors (pdf-info-open nil password)))
(pdf-info-open nil password)