- (interactive "fFile to write: ")
- (let* ((model (or model (encrypt-find-model file)))
- (method (nth 0 model))
- (cipher (nth 1 model))
- (password-key (format "encrypt-password-%s-%s %s"
- (symbol-name method) cipher file))
- (passphrase
- (password-read
- (format "%s password for cipher %s? "
- (symbol-name method) cipher)
- password-key))
- outdata)
-
- (cond
- ((eq method 'gpg)
- (setq outdata (encrypt-gpg-encode-buffer passphrase cipher)))
- ((eq method 'encrypt-xor)
- (setq outdata (encrypt-xor-encode-buffer passphrase cipher))))
-
- (if outdata
- (progn
- (message "%s was encrypted with %s (cipher %s)"
- file (symbol-name method) cipher)
- (delete-region (point-min) (point-max))
- (goto-char (point-min))
- (insert outdata)
- ;; do not confirm overwrites
- (write-file file nil))
- ;; the decryption failed, alas
- (password-cache-remove password-key)
- (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)"
- file (symbol-name method) cipher))))
+ (interactive "sFile to write: ")
+ (setq model (or model (encrypt-find-model file)))
+ (if model
+ (let* ((method (nth 0 model))
+ (cipher (nth 1 model))
+ (password-key (format "encrypt-password-%s-%s %s"
+ (symbol-name method) cipher file))
+ (passphrase
+ (password-read
+ (format "%s password for cipher %s? "
+ (symbol-name method) cipher)
+ password-key))
+ outdata)
+
+ (cond
+ ((eq method 'gpg)
+ (setq outdata (encrypt-gpg-encode-buffer passphrase cipher)))
+ ((eq method 'encrypt-xor)
+ (setq outdata (encrypt-xor-encode-buffer passphrase cipher))))
+
+ (if outdata
+ (progn
+ (message "%s was encrypted with %s (cipher %s)"
+ file (symbol-name method) cipher)
+ (delete-region (point-min) (point-max))
+ (goto-char (point-min))
+ (insert outdata)
+ ;; do not confirm overwrites
+ (write-file file nil))
+ ;; the decryption failed, alas
+ (password-cache-remove password-key)
+ (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)"
+ file (symbol-name method) cipher)))
+ (gnus-error 1 "%s has no associated encryption model! See encrypt-file-alist." file)))