(defun epa-file-passphrase-callback-function (key-id buffer)
(save-excursion
(set-buffer buffer)
- (if (and (eq key-id 'SYM)
- epa-file)
+ (if (eq key-id 'SYM)
(or epa-passphrase
(let ((passphrase (epg-passphrase-callback-function
key-id buffer)))
(setq buffer-undo-list nil)
(make-local-variable 'epa-passphrase)
(setq epa-passphrase passphrase)))
+ (make-local-variable 'epa-passphrase)
(make-local-variable 'epa-file)
- (setq epa-file (buffer-file-name))
- (make-local-variable 'epa-passphrase)))
+ (setq epa-file (buffer-file-name))))
(defun epa-write-file ()
- (when epa-file
- (let* ((coding-system (if (boundp 'last-coding-system-used)
- (condition-case nil
- (write-region (point-min) (point-max) "/")
- (error last-coding-system-used))
- buffer-file-coding-system))
- (coding-system-for-write 'binary)
- (context (epg-make-context)))
- (epg-context-set-passphrase-callback
- context
- (cons #'epa-file-passphrase-callback-function
- (current-buffer)))
- (write-region
- (epg-encrypt-string
- context
- (encode-coding-string (buffer-string) coding-system)
- (mapcar (lambda (key)
- (epg-sub-key-id (car (epg-key-sub-key-list key))))
- (unless epa-passphrase
- (epa-select-keys
- "Select recipents for encryption.
+ (if epa-file
+ (let* ((coding-system (if (boundp 'last-coding-system-used)
+ (condition-case nil
+ (write-region (point-min) (point-max) "/")
+ (error last-coding-system-used))
+ buffer-file-coding-system))
+ (context (epg-make-context))
+ (coding-system-for-write 'binary))
+ (epg-context-set-passphrase-callback
+ context
+ (cons #'epa-file-passphrase-callback-function
+ (current-buffer)))
+ (write-region
+ (epg-encrypt-string
+ context
+ (encode-coding-string (buffer-string) coding-system)
+ (mapcar (lambda (key)
+ (epg-sub-key-id (car (epg-key-sub-key-list key))))
+ (unless epa-passphrase
+ (epa-select-keys
+ "Select recipents for encryption.
If no one is selected, symmetric encryption will be performed. "))))
- nil (expand-file-name (buffer-file-name))))
- (set-visited-file-modtime)
- (set-buffer-modified-p nil)
- t))
+ nil (expand-file-name (buffer-file-name)))
+ (if (boundp 'last-coding-system-used)
+ (setq last-coding-system-used coding-system))
+ (set-visited-file-modtime)
+ (set-buffer-modified-p nil)
+ t)))
(provide 'epa-file)