- (condition-case error
- (setq string (epg-encrypt-string context string nil))
- (error
- (if (setq entry (riece-identity-assoc riece-current-channel
- riece-epg-passphrase-alist))
- (setcdr entry nil))
- (signal (car error) (cdr error))))
- (riece-command-send-message
- (concat "[OpenPGP Encrypted:" (base64-encode-string string t) "]")
- nil)
- (let ((next-line-add-newlines t))
- (next-line 1))))
+ (riece-send-string
+ (format "PRIVMSG %s :[encrypted:%s]\r\n"
+ (riece-identity-prefix riece-current-channel)
+ (base64-encode-string
+ (riece-epg-funcall-clear-passphrase
+ riece-current-channel
+ #'epg-encrypt-string
+ context
+ (riece-with-server-buffer
+ (riece-identity-server riece-current-channel)
+ (riece-encode-coding-string-for-identity
+ string
+ riece-current-channel))
+ nil)
+ t)))
+ (riece-display-message
+ (riece-make-message (riece-current-nickname) riece-current-channel
+ (concat "[encrypted:" string "]") nil t))
+ (if (> (forward-line) 0)
+ (insert "\n"))))
+
+(defun riece-command-set-passphrase (identity passphrase)
+ "Set PASSPHRASE associated with IDENTITY."
+ (interactive
+ (let ((identity
+ (riece-completing-read-identity
+ "Channel/user: "
+ riece-current-channels nil t nil nil
+ (riece-format-identity riece-current-channel))))
+ (list identity
+ (read-passwd (format "Passphrase for %s: "
+ (riece-format-identity identity))))))
+ (let ((entry (riece-identity-assoc identity riece-epg-passphrase-alist)))
+ (if (equal passphrase "")
+ (if entry
+ (setq riece-epg-passphrase-alist
+ (delq entry riece-epg-passphrase-alist)))
+ (if entry
+ (setcdr entry passphrase)
+ (setq riece-epg-passphrase-alist
+ (cons (cons identity passphrase)
+ riece-epg-passphrase-alist))))))
+
+(defun riece-epg-decrypt-string-for-identity (context cipher target)
+ (let ((coding-system
+ (or (riece-coding-system-for-identity target)
+ riece-default-coding-system)))
+ (riece-with-server-buffer (riece-identity-server target)
+ (decode-coding-string
+ (riece-epg-funcall-clear-passphrase
+ target
+ #'epg-decrypt-string
+ context
+ (base64-decode-string cipher))
+ (if (consp coding-system)
+ (car coding-system)
+ coding-system)))))