emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] GPG in Emacs-Wiki


From: Anirudh Sasikumar
Subject: [emacs-wiki-discuss] GPG in Emacs-Wiki
Date: Mon, 25 Oct 2004 02:15:02 +0530
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3

Hi.

Not sure if this has to sent to the mailing list or posted on the Wiki
Page. Apology in advance if this is the wrong place to post this.

I wrote these functions to make gpg encryption and decryption with the
recipient as myself using PGG easier and then found use for them within
emacs-wiki-mode especially to maintain sections of encrypted text in a
wiki.

;pgg setting
(setq pgg-gpg-user-id "Your user id")

;encrypting version
(defun pgg-encrypt-sign-self (&optional start end showout)
  "Encrypt and sign the current buffer for self.
If optional arguments START and END are specified, only encrypt within
the region.showout causes region between start and end to be replaced
with the output."
  (interactive "*")
  ;change value of rcpts if you require another recipent
  ;try using read-string to get the rcpt
  (let* ((rcpts (list pgg-gpg-user-id))
         (sign t)
         (start (or start (point-min)))
         (end (or end (point-max)))
         (status (pgg-encrypt-region start end rcpts sign)))
    (when (or (interactive-p) showout)
      (pgg-display-output-buffer start end status))
    status))

;decrypting version
(defun pgg-decrypt-self (&optional start end showout)
  "Decrypt the current buffer.
If optional arguments START and END are specified, only decrypt within
the region. showout causes region between start and end to be replaced
with the output."
  (interactive "*")
  (let* ((start (or start (point-min)))
         (end (or end (point-max)))
         (status (pgg-decrypt-region start end)))
    (when (or (interactive-p) showout)
      (pgg-display-output-buffer start end status))
    status))

I use these functions to have gpg encrypted text within my emacs-wiki
file between gpg or gpge tags. 

The first idea is that there will be text between gpg tags and
pressing C-c C-S-e will encrypt the text between each gpg tag while
C-c C-S-d will decrypt. A simple handler for the gpg tags in
emacs-wiki causes text between gpg tags to be published just like as
if they were enclosed in the example tag.

Here's the code:

(defun emacs-wiki-decrypt-gpg ()
  "Find all gpg tags and decrypt their contents."
  (interactive)
  (let (tagbegin tagend)
    (save-excursion
      (goto-char 0)
      (while (re-search-forward "<gpg>" nil t)    
        (setq tagbegin (match-end 0))
        (if (re-search-forward "</gpg>" nil t)
            (progn
              (setq tagend (match-beginning 0))
              (pgg-decrypt-self tagbegin tagend t))
          (message "No closing gpg tags found"))))))

(defun emacs-wiki-encrypt-gpg ()
  "Find all gpg tags and encrypt their contents."
  (interactive)
  (let (tagbegin tagend)
    (save-excursion
      (goto-char 0)
      (while (re-search-forward "<gpg>" nil t)    
        (setq tagbegin (match-end 0))
        (re-search-forward "</gpg>" nil t)
        (setq tagend (match-beginning 0))
        (pgg-encrypt-sign-self tagbegin tagend t)))))

;key bindings
(define-key emacs-wiki-mode-map
  [(control ?c) (control ?E)]
  'emacs-wiki-encrypt-gpg)

(define-key emacs-wiki-mode-map
  [(control ?c) (control ?D)]
  'emacs-wiki-decrypt-gpg)

;wiki handler of gpg tag
(defun emacs-wiki-gpg-tag (beg end highlight-p)
  (if highlight-p
      (progn
        (emacs-wiki-multiline-maybe beg end)
        (goto-char end))
    (insert "<pre class=\"example\">")
    (when (< (point) end)
      (goto-char end))
    (insert "</pre>")
    (add-text-properties beg end '(rear-nonsticky (read-only)
                                                  read-only t))))

(push '("gpg" t nil t emacs-wiki-gpg-tag) emacs-wiki-markup-tags)


The second idea is that the wiki source file will have unencrypted
text between gpge tags. When published to html, the text will be
encrypted.

Here's the code:

;wiki handler of gpge tag
(defun emacs-wiki-gpg-encrypt-tag (beg end highlight-p)
  (if highlight-p
      (progn
        (emacs-wiki-multiline-maybe beg end)
        (goto-char end))
    (insert "<pre class=\"example\">")
    (pgg-encrypt-sign-self (point) end t)
    (when (< (point) end)
      (goto-char end))
    (insert "</pre>")
    (add-text-properties beg (point) '(rear-nonsticky (read-only)
                                                  read-only t))))
(push '("gpge" t nil t emacs-wiki-gpg-encrypt-tag) emacs-wiki-markup-tags)

Note: Am using outdated emacs-wiki version 2004.04.07-01.45-dev :).

Cheers,
-- 
Anirudh.Sasikumar - PGP Key ID: 96F81F5D
http://www.aloofhosting.com/anisk/ or http://www.anirudhs.tk




reply via email to

[Prev in Thread] Current Thread [Next in Thread]