summaryrefslogtreecommitdiff
path: root/lisp/epg.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/epg.el')
-rw-r--r--lisp/epg.el145
1 files changed, 35 insertions, 110 deletions
diff --git a/lisp/epg.el b/lisp/epg.el
index 539dcf3ca22..e06cc06a7d1 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -174,10 +174,6 @@
(file nil :read-only t)
(string nil :read-only t))
-(defmacro epg--gv-nreverse (place)
- (gv-letplace (getter setter) place
- (funcall setter `(nreverse ,getter))))
-
(cl-defstruct (epg-context
(:constructor nil)
(:constructor epg-context--make
@@ -211,7 +207,7 @@
output-file
result
operation
- pinentry-mode
+ (pinentry-mode epg-pinentry-mode)
(error-output "")
error-buffer)
@@ -612,7 +608,9 @@ callback data (if any)."
;; for more details.
(when (and agent-info (string-match "\\(.*\\):[0-9]+:[0-9]+" agent-info))
(setq agent-file (match-string 1 agent-info)
- agent-mtime (or (nth 5 (file-attributes agent-file)) '(0 0 0 0))))
+ agent-mtime (or (file-attribute-modification-time
+ (file-attributes agent-file))
+ '(0 0 0 0))))
(if epg-debug
(save-excursion
(unless epg-debug-buffer
@@ -739,7 +737,9 @@ callback data (if any)."
(if (with-current-buffer (process-buffer (epg-context-process context))
(and epg-agent-file
(time-less-p epg-agent-mtime
- (or (nth 5 (file-attributes epg-agent-file)) 0))))
+ (or (file-attribute-modification-time
+ (file-attributes epg-agent-file))
+ 0))))
(redraw-frame))
(epg-context-set-result-for
context 'error
@@ -764,18 +764,13 @@ callback data (if any)."
(file-exists-p (epg-context-output-file context)))
(delete-file (epg-context-output-file context))))
-(eval-and-compile
- (if (fboundp 'decode-coding-string)
- (defalias 'epg--decode-coding-string 'decode-coding-string)
- (defalias 'epg--decode-coding-string 'identity)))
-
(defun epg--status-USERID_HINT (_context string)
(if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
(let* ((key-id (match-string 1 string))
(user-id (match-string 2 string))
(entry (assoc key-id epg-user-id-alist)))
(condition-case nil
- (setq user-id (epg--decode-coding-string
+ (setq user-id (decode-coding-string
(epg--decode-percent-escape user-id)
'utf-8))
(error))
@@ -794,17 +789,6 @@ callback data (if any)."
(defun epg--status-NEED_PASSPHRASE_PIN (_context _string)
(setq epg-key-id 'PIN))
-(eval-and-compile
- (if (fboundp 'clear-string)
- (defalias 'epg--clear-string 'clear-string)
- (defun epg--clear-string (string)
- (fillarray string 0))))
-
-(eval-and-compile
- (if (fboundp 'encode-coding-string)
- (defalias 'epg--encode-coding-string 'encode-coding-string)
- (defalias 'epg--encode-coding-string 'identity)))
-
(defun epg--status-GET_HIDDEN (context string)
(when (and epg-key-id
(string-match "\\`passphrase\\." string))
@@ -825,16 +809,16 @@ callback data (if any)."
(cdr (epg-context-passphrase-callback context))))
(when passphrase
(setq passphrase-with-new-line (concat passphrase "\n"))
- (epg--clear-string passphrase)
+ (clear-string passphrase)
(setq passphrase nil)
(if epg-passphrase-coding-system
(progn
(setq encoded-passphrase-with-new-line
- (epg--encode-coding-string
+ (encode-coding-string
passphrase-with-new-line
(coding-system-change-eol-conversion
epg-passphrase-coding-system 'unix)))
- (epg--clear-string passphrase-with-new-line)
+ (clear-string passphrase-with-new-line)
(setq passphrase-with-new-line nil))
(setq encoded-passphrase-with-new-line
passphrase-with-new-line
@@ -848,11 +832,11 @@ callback data (if any)."
(epg-context-result-for context 'error)))
(delete-process (epg-context-process context))))
(if passphrase
- (epg--clear-string passphrase))
+ (clear-string passphrase))
(if passphrase-with-new-line
- (epg--clear-string passphrase-with-new-line))
+ (clear-string passphrase-with-new-line))
(if encoded-passphrase-with-new-line
- (epg--clear-string encoded-passphrase-with-new-line))))))
+ (clear-string encoded-passphrase-with-new-line))))))
(defun epg--prompt-GET_BOOL (_context string)
(let ((entry (assoc string epg-prompt-alist)))
@@ -915,7 +899,7 @@ callback data (if any)."
(condition-case nil
(if (eq (epg-context-protocol context) 'CMS)
(setq user-id (epg-dn-from-string user-id))
- (setq user-id (epg--decode-coding-string
+ (setq user-id (decode-coding-string
(epg--decode-percent-escape user-id)
'utf-8)))
(error))
@@ -962,10 +946,7 @@ callback data (if any)."
(cons (cons 'no-seckey string)
(epg-context-result-for context 'error))))
-(defun epg--time-from-seconds (seconds)
- (let ((number-seconds (string-to-number (concat seconds ".0"))))
- (cons (floor (/ number-seconds 65536))
- (floor (mod number-seconds 65536)))))
+(defalias 'epg--time-from-seconds #'string-to-number)
(defun epg--status-ERRSIG (context string)
(if (string-match "\\`\\([^ ]+\\) \\([0-9]+\\) \\([0-9]+\\) \
@@ -1163,7 +1144,7 @@ callback data (if any)."
(defun epg--status-SIG_CREATED (context string)
(if (string-match "\\`\\([DCS]\\) \\([0-9]+\\) \\([0-9]+\\) \
-\\([0-9A-Fa-F][0-9A-Fa-F]\\) \\(.*\\) " string)
+\\([0-9A-Fa-f][0-9A-Fa-f]\\) \\(.*\\) " string)
(epg-context-set-result-for
context 'sign
(cons (epg-make-new-signature
@@ -1196,7 +1177,7 @@ callback data (if any)."
(user-id (match-string 2 string))
(entry (assoc key-id epg-user-id-alist)))
(condition-case nil
- (setq user-id (epg--decode-coding-string
+ (setq user-id (decode-coding-string
(epg--decode-percent-escape user-id)
'utf-8))
(error))
@@ -1353,7 +1334,7 @@ NAME is either a string or a list of strings."
(setq string (replace-match "\\\"" t t string)
index (1+ (match-end 0))))
(condition-case nil
- (setq string (epg--decode-coding-string
+ (setq string (decode-coding-string
(car (read-from-string (concat "\"" string "\"")))
'utf-8))
(error
@@ -1390,70 +1371,14 @@ NAME is either a string or a list of strings."
(setq keys (nreverse keys)
pointer keys)
(while pointer
- (epg--gv-nreverse (epg-key-sub-key-list (car pointer)))
- (setq pointer-1 (epg--gv-nreverse (epg-key-user-id-list (car pointer))))
+ (cl-callf nreverse (epg-key-sub-key-list (car pointer)))
+ (setq pointer-1 (cl-callf nreverse (epg-key-user-id-list (car pointer))))
(while pointer-1
- (epg--gv-nreverse (epg-user-id-signature-list (car pointer-1)))
+ (cl-callf nreverse (epg-user-id-signature-list (car pointer-1)))
(setq pointer-1 (cdr pointer-1)))
(setq pointer (cdr pointer)))
keys))
-(eval-and-compile
- (if (fboundp 'make-temp-file)
- (defalias 'epg--make-temp-file 'make-temp-file)
- (defvar temporary-file-directory)
- ;; stolen from poe.el.
- (defun epg--make-temp-file (prefix)
- "Create a temporary file.
-The returned file name (created by appending some random characters at the end
-of PREFIX, and expanding against `temporary-file-directory' if necessary),
-is guaranteed to point to a newly created empty file.
-You can then use `write-region' to write new data into the file."
- (let ((orig-modes (default-file-modes))
- tempdir tempfile)
- (setq prefix (expand-file-name prefix
- (if (featurep 'xemacs)
- (temp-directory)
- temporary-file-directory)))
- (unwind-protect
- (let (file)
- ;; First, create a temporary directory.
- (set-default-file-modes #o700)
- (while (condition-case ()
- (progn
- (setq tempdir (make-temp-name
- (concat
- (file-name-directory prefix)
- "DIR")))
- ;; return nil or signal an error.
- (make-directory tempdir))
- ;; let's try again.
- (file-already-exists t)))
- ;; Second, create a temporary file in the tempdir.
- ;; There *is* a race condition between `make-temp-name'
- ;; and `write-region', but we don't care it since we are
- ;; in a private directory now.
- (setq tempfile (make-temp-name (concat tempdir "/EMU")))
- (write-region "" nil tempfile nil 'silent)
- ;; Finally, make a hard-link from the tempfile.
- (while (condition-case ()
- (progn
- (setq file (make-temp-name prefix))
- ;; return nil or signal an error.
- (add-name-to-file tempfile file))
- ;; let's try again.
- (file-already-exists t)))
- file)
- (set-default-file-modes orig-modes)
- ;; Cleanup the tempfile.
- (and tempfile
- (file-exists-p tempfile)
- (delete-file tempfile))
- ;; Cleanup the tempdir.
- (and tempdir
- (file-directory-p tempdir)
- (delete-directory tempdir)))))))
-
(defun epg--args-from-sig-notations (notations)
(apply #'nconc
(mapcar
@@ -1517,7 +1442,7 @@ If PLAIN is nil, it returns the result as a string."
(unwind-protect
(progn
(setf (epg-context-output-file context)
- (or plain (epg--make-temp-file "epg-output")))
+ (or plain (make-temp-file "epg-output")))
(epg-start-decrypt context (epg-make-data-from-file cipher))
(epg-wait-for-completion context)
(epg--check-error-for-decrypt context)
@@ -1529,13 +1454,13 @@ If PLAIN is nil, it returns the result as a string."
(defun epg-decrypt-string (context cipher)
"Decrypt a string CIPHER and return the plain text."
- (let ((input-file (epg--make-temp-file "epg-input"))
+ (let ((input-file (make-temp-file "epg-input"))
(coding-system-for-write 'binary))
(unwind-protect
(progn
(write-region cipher nil input-file nil 'quiet)
(setf (epg-context-output-file context)
- (epg--make-temp-file "epg-output"))
+ (make-temp-file "epg-output"))
(epg-start-decrypt context (epg-make-data-from-file input-file))
(epg-wait-for-completion context)
(epg--check-error-for-decrypt context)
@@ -1606,7 +1531,7 @@ which will return a list of `epg-signature' object."
(unwind-protect
(progn
(setf (epg-context-output-file context)
- (or plain (epg--make-temp-file "epg-output")))
+ (or plain (make-temp-file "epg-output")))
(if signed-text
(epg-start-verify context
(epg-make-data-from-file signature)
@@ -1643,10 +1568,10 @@ which will return a list of `epg-signature' object."
(unwind-protect
(progn
(setf (epg-context-output-file context)
- (epg--make-temp-file "epg-output"))
+ (make-temp-file "epg-output"))
(if signed-text
(progn
- (setq input-file (epg--make-temp-file "epg-signature"))
+ (setq input-file (make-temp-file "epg-signature"))
(write-region signature nil input-file nil 'quiet)
(epg-start-verify context
(epg-make-data-from-file input-file)
@@ -1714,7 +1639,7 @@ Otherwise, it makes a cleartext signature."
(unwind-protect
(progn
(setf (epg-context-output-file context)
- (or signature (epg--make-temp-file "epg-output")))
+ (or signature (make-temp-file "epg-output")))
(epg-start-sign context (epg-make-data-from-file plain) mode)
(epg-wait-for-completion context)
(unless (epg-context-result-for context 'sign)
@@ -1734,12 +1659,12 @@ If it is nil or `normal', it makes a normal signature.
Otherwise, it makes a cleartext signature."
(let ((input-file
(unless (eq (epg-context-protocol context) 'CMS)
- (epg--make-temp-file "epg-input")))
+ (make-temp-file "epg-input")))
(coding-system-for-write 'binary))
(unwind-protect
(progn
(setf (epg-context-output-file context)
- (epg--make-temp-file "epg-output"))
+ (make-temp-file "epg-output"))
(if input-file
(write-region plain nil input-file nil 'quiet))
(epg-start-sign context
@@ -1816,7 +1741,7 @@ If RECIPIENTS is nil, it performs symmetric encryption."
(unwind-protect
(progn
(setf (epg-context-output-file context)
- (or cipher (epg--make-temp-file "epg-output")))
+ (or cipher (make-temp-file "epg-output")))
(epg-start-encrypt context (epg-make-data-from-file plain)
recipients sign always-trust)
(epg-wait-for-completion context)
@@ -1841,12 +1766,12 @@ If RECIPIENTS is nil, it performs symmetric encryption."
(let ((input-file
(unless (or (not sign)
(eq (epg-context-protocol context) 'CMS))
- (epg--make-temp-file "epg-input")))
+ (make-temp-file "epg-input")))
(coding-system-for-write 'binary))
(unwind-protect
(progn
(setf (epg-context-output-file context)
- (epg--make-temp-file "epg-output"))
+ (make-temp-file "epg-output"))
(if input-file
(write-region plain nil input-file nil 'quiet))
(epg-start-encrypt context
@@ -1891,7 +1816,7 @@ If you are unsure, use synchronous version of this function
(unwind-protect
(progn
(setf (epg-context-output-file context)
- (or file (epg--make-temp-file "epg-output")))
+ (or file (make-temp-file "epg-output")))
(epg-start-export-keys context keys)
(epg-wait-for-completion context)
(let ((errors (epg-context-result-for context 'error)))