emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/pdf-tools 98bfeb638a 3/7: Don't retry with the same cached


From: ELPA Syncer
Subject: [nongnu] elpa/pdf-tools 98bfeb638a 3/7: Don't retry with the same cached password upon decryption failure
Date: Thu, 14 Mar 2024 07:01:12 -0400 (EDT)

branch: elpa/pdf-tools
commit 98bfeb638aaef37c17266accdb3b5a153540d452
Author: Miha Rihtaršič <miha@kamnitnik.top>
Commit: Miha Rihtaršič <miha@kamnitnik.top>

    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.
---
 lisp/pdf-view.el | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index d45571adfd..9cfb188183 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]