emacs-devel
[Top][All Lists]
Advanced

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

pgg symmetric encryption patch (was: new version of allout.el - patch an


From: Sascha Wilde
Subject: pgg symmetric encryption patch (was: new version of allout.el - patch and ChangeLog)
Date: Mon, 3 Oct 2005 21:25:03 +0200
User-agent: Mutt/1.5.9i

On Sun, Oct 02, 2005 at 04:31:10PM -0400, Richard M. Stallman wrote:
>     So you would consider switching to pgg, if it would provide an
>     interface to symmetric encryption?
> 
> If someone wants to do it, and assuming the result is clean, it would 
> be a good thing to do.

Enclosed you'll find my preliminary patch to make symmetric encryption
possible with pgg.

The new function pgg-encrypt-symmetric-region asks for a passphrase
and uses it to symmetrically encrypt the given region.

Please note, this is by no means complete, just a small proof of concept.

Ken, would something along this lines be sufficient for use with allout?

cheers
sascha

cvs server: Diffing .
Index: pgg-gpg.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/gnus/pgg-gpg.el,v
retrieving revision 1.6
diff -u -r1.6 pgg-gpg.el
--- pgg-gpg.el  6 Aug 2005 19:51:42 -0000       1.6
+++ pgg-gpg.el  3 Oct 2005 19:13:34 -0000
@@ -4,6 +4,7 @@
 ;;   2005 Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <address@hidden>
+;; Symmetric encryption added by: Sascha Wilde <address@hidden>
 ;; Created: 1999/10/28
 ;; Keywords: PGP, OpenPGP, GnuPG
 
@@ -141,24 +142,32 @@
 
 (defun pgg-gpg-encrypt-region (start end recipients &optional sign)
   "Encrypt the current region between START and END.
+If recipients is :symmetric do symmetric encryption
 If optional argument SIGN is non-nil, do a combined sign and encrypt."
   (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
+        (symmetric-encryption (eq recipients :symmetric))
         (passphrase
-         (when sign
-           (pgg-read-passphrase
-            (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
-            pgg-gpg-user-id)))
+         (if symmetric-encryption
+             (pgg-read-passphrase
+              "GnuPG passphrase for symmetric encryption: ")
+           (when sign
+             (pgg-read-passphrase
+              (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
+              pgg-gpg-user-id))))
         (args
          (append
-          (list "--batch" "--armor" "--always-trust" "--encrypt")
+          (list "--batch" "--armor" "--always-trust" 
+                (if symmetric-encryption "--symmetric" "--encrypt"))
           (if sign (list "--sign" "--local-user" pgg-gpg-user-id))
-          (if recipients
-              (apply #'nconc
-                     (mapcar (lambda (rcpt)
-                               (list pgg-gpg-recipient-argument rcpt))
-                             (append recipients
-                                     (if pgg-encrypt-for-me
-                                         (list pgg-gpg-user-id)))))))))
+          (if symmetric-encryption
+              nil
+              (if recipients
+                  (apply #'nconc
+                         (mapcar (lambda (rcpt)
+                                   (list pgg-gpg-recipient-argument rcpt))
+                                 (append recipients
+                                         (if pgg-encrypt-for-me
+                                             (list pgg-gpg-user-id))))))))))
     (pgg-as-lbt start end 'CRLF
       (pgg-gpg-process-region start end passphrase pgg-gpg-program args))
     (when sign
Index: pgg.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/gnus/pgg.el,v
retrieving revision 1.8
diff -u -r1.8 pgg.el
--- pgg.el      26 Aug 2005 00:02:05 -0000      1.8
+++ pgg.el      3 Oct 2005 19:13:34 -0000
@@ -4,6 +4,7 @@
 ;;   2005 Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <address@hidden>
+;; Symmetric encryption added by: Sascha Wilde <address@hidden>
 ;; Created: 1999/10/28
 ;; Keywords: PGP
 
@@ -232,6 +233,18 @@
         (pgg-save-coding-system start end
           (pgg-invoke "encrypt-region" (or pgg-scheme pgg-default-scheme)
                       (point-min) (point-max) rcpts sign))))
+    (when (interactive-p)
+      (pgg-display-output-buffer start end status))
+    status))
+
+;;;###autoload
+(defun pgg-encrypt-symmetric-region (start end)
+  "Encrypt the current region between START and END symmetric with passphrase."
+  (interactive "r")
+  (let ((status
+        (pgg-save-coding-system start end
+          (pgg-invoke "encrypt-region" (or pgg-scheme pgg-default-scheme)
+                      (point-min) (point-max) :symmetric))))
     (when (interactive-p)
       (pgg-display-output-buffer start end status))
     status))


-- 
Sascha Wilde : The most exciting phrase to hear in science, the one
             : that heralds new discoveries, is not "Eureka!" (I found
             : it!) but "That's funny ..." -- Isaac Asimov

Attachment: pgpOjOrIYalXN.pgp
Description: PGP signature


reply via email to

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