[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
GnuPG support from inside emacs?
From: |
Rajesh Vaidheeswarran |
Subject: |
GnuPG support from inside emacs? |
Date: |
Thu, 21 Jun 2001 10:21:14 -0400 (EDT) |
Folks,
I use emacs as my mailer, and frequently use GPG to sign my mails. So,
I took a stab at a gpg-sign defun for emacs. This is decidedly not the
coolest way of doing it.. but as I started to go deep into it, I
wanted to make sure I wasn't duplicating effort.
If this seems useful, and anyone is willing to review and make
suggestions on things about either(better still, contribute), I'd be
happy to formalize it into a library with other useful stuff.
rv
(defun gpg-sign (p m)
"gpg signs a given region"
(interactive "r")
(let ((passstr "Enter passphrase: ")
(pass (read-passwd "Enter passphrase: "))
(gpg-buf (get-buffer-create "**gpg-sign**"))
(gpg-prog "gpg")
(proc ""))
;; create a gpg signing buffer and clear it up.
(save-excursion
(set-buffer gpg-buf)
(display-buffer gpg-buf t t)
(goto-char (point-min))
(kill-region (point-min) (point-max))
(insert "gpg process: " proc "\n"))
;; start the process
(setq proc (start-process "gpg" gpg-buf gpg-prog "--clearsign"))
;; make sure that it has asked for the pass phrase....
(save-excursion
(set-buffer gpg-buf)
(goto-char (point-min))
(while (equal nil (re-search-forward passstr (point-max) t))
(message "waiting for gpg...")
(sleep-for 0 500)))
;; send the passphrase..
(process-send-string proc pass)
(process-send-string proc "\n")
(process-send-string proc "\n")
;; send a newline to the buffer (not the process) for clarity
;; and ease of cut and paste.
(save-excursion
(set-buffer gpg-buf)
(goto-char (point-max))
(insert "\n\n"))
(message "inserting contents between %s and %s into %s" p m proc)
;; send the text to be signed...
(save-restriction
(narrow-to-region p m)
(process-send-region proc (point-min) (point-max)))
;; and close the input stream.
(process-send-eof proc)
(process-send-eof proc)
;; if called with prefix-arg, replace the source region with the
;; signed region.
(if current-prefix-arg
(let ((str ""))
(save-excursion
(set-buffer gpg-buf)
(goto-char (point-min))
(setq str (gpg-search-region (point-min) (point-max))))
(save-restriction
(narrow-to-region p m)
;;(goto-char (point-min))
(goto-char (point-max))
;;(delete-region (point-min) (point-max))
(insert str))))))
(defun gpg-search-region (p m)
(interactive "r")
(let ((str ""))
(save-restriction
(goto-char p)
(set-mark m)
(narrow-to-region p m)
(if (search-forward "-----BEGIN PGP SIGNED MESSAGE-----")
(save-restriction
(narrow-to-region (match-beginning 0) (point-max))
(goto-char (point-min))
(if (search-forward "-----END PGP SIGNATURE-----")
(save-restriction
(narrow-to-region (point-min) (match-end 0))
(setq str (buffer-string)))
(message "No match for END found!")))
(message "No match for BEGIN found!"))
str)))
- GnuPG support from inside emacs?,
Rajesh Vaidheeswarran <=