Function: tramp-crypt-do-encrypt-or-decrypt-file-name

tramp-crypt-do-encrypt-or-decrypt-file-name is a byte-compiled function defined in tramp-crypt.el.gz.

Signature

(tramp-crypt-do-encrypt-or-decrypt-file-name OP NAME)

Documentation

Return encrypted / decrypted NAME if NAME belongs to an encrypted directory.

OP must be encrypt or decrypt. Raise an error if this fails. Otherwise, return NAME.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-crypt.el.gz
(defun tramp-crypt-do-encrypt-or-decrypt-file-name (op name)
  "Return encrypted / decrypted NAME if NAME belongs to an encrypted directory.
OP must be `encrypt' or `decrypt'.  Raise an error if this fails.
Otherwise, return NAME."
  (if-let* ((tramp-crypt-enabled t)
	    (dir (tramp-crypt-file-name-p name))
	    ;; It must be absolute for the cache.
	    (localname (substring name (1- (length dir))))
	    (crypt-vec (tramp-crypt-dissect-file-name dir)))
      ;; Preserve trailing "/".
      (funcall
       (if (directory-name-p name) #'file-name-as-directory #'identity)
       (concat
	dir
	(unless (string-match-p (rx bos (? "/") eos) localname)
	  (with-tramp-file-property
	      crypt-vec localname (concat (symbol-name op) "-file-name")
	    (unless (tramp-crypt-send-command
		     crypt-vec (if (eq op 'encrypt) "encode" "decode")
		     tramp-compat-temporary-file-directory localname)
	      (tramp-error
	       crypt-vec 'file-error "%s of file name %s failed"
	       (if (eq op 'encrypt) "Encoding" "Decoding") name))
	    (with-current-buffer (tramp-get-connection-buffer crypt-vec)
	      (goto-char (point-min))
	      (buffer-substring (point-min) (line-end-position)))))))
    ;; Nothing to do.
    name))