Mercurial > emacs
annotate lisp/org/org-crypt.el @ 110960:f5a478bc42bc
* nextstep/AUTHORS: Remove email addresses.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 12 Oct 2010 20:11:08 -0700 |
parents | a150e8a14679 |
children | 5cb272c831e8 |
rev | line source |
---|---|
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
1 ;;; org-crypt.el --- Public key encryption for org-mode entries |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
2 |
106815 | 3 ;; Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
4 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
5 ;; Emacs Lisp Archive Entry |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
6 ;; Filename: org-crypt.el |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
7 ;; Version: 7.01 |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
8 ;; Keywords: org-mode |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
9 ;; Author: John Wiegley <johnw@gnu.org> |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
10 ;; Maintainer: Peter Jones <pjones@pmade.com> |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
11 ;; Description: Adds public key encryption to org-mode buffers |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
12 ;; URL: http://www.newartisans.com/software/emacs.html |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
13 ;; Compatibility: Emacs22 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
14 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
15 ;; This file is part of GNU Emacs. |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
16 ;; |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
17 ;; GNU Emacs is free software: you can redistribute it and/or modify |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
18 ;; it under the terms of the GNU General Public License as published by |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
19 ;; the Free Software Foundation, either version 3 of the License, or |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
20 ;; (at your option) any later version. |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
21 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
22 ;; GNU Emacs is distributed in the hope that it will be useful, |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
25 ;; GNU General Public License for more details. |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
26 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
27 ;; You should have received a copy of the GNU General Public License |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
28 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
29 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
30 ;;; Commentary: |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
31 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
32 ;; Right now this is just a set of functions to play with. It depends |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
33 ;; on the epg library. Here's how you would use it: |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
34 ;; |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
35 ;; 1. To mark an entry for encryption, tag the heading with "crypt". |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
36 ;; You can change the tag to any complex tag matching string by |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
37 ;; setting the `org-crypt-tag-matcher' variable. |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
38 ;; |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
39 ;; 2. Set the encryption key to use in the `org-crypt-key' variable, |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
40 ;; or use `M-x org-set-property' to set the property CRYPTKEY to |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
41 ;; any address in your public keyring. The text of the entry (but |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
42 ;; not its properties or headline) will be encrypted for this user. |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
43 ;; For them to read it, the corresponding secret key must be |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
44 ;; located in the secret key ring of the account where you try to |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
45 ;; decrypt it. This makes it possible to leave secure notes that |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
46 ;; only the intended recipient can read in a shared-org-mode-files |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
47 ;; scenario. |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
48 ;; If the key is not set, org-crypt will default to symmetric encryption. |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
49 ;; |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
50 ;; 3. To later decrypt an entry, use `org-decrypt-entries' or |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
51 ;; `org-decrypt-entry'. It might be useful to bind this to a key, |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
52 ;; like C-c C-/. I hope that in the future, C-c C-r can be might |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
53 ;; overloaded to also decrypt an entry if it's encrypted, since |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
54 ;; that fits nicely with the meaning of "reveal". |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
55 ;; |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
56 ;; 4. To automatically encrypt all necessary entries when saving a |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
57 ;; file, call `org-crypt-use-before-save-magic' after loading |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
58 ;; org-crypt.el. |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
59 ;; |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
60 ;; TODO: |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
61 ;; - Allow symmetric encryption as well |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
62 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
63 ;;; Thanks: |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
64 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
65 ;; - Carsten Dominik |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
66 ;; - Vitaly Ostanin |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
67 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
68 (require 'org) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
69 |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
70 ;;; Code: |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
71 |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
72 (declare-function epg-decrypt-string "epg" (context cipher)) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
73 (declare-function epg-list-keys "epg" (context &optional name mode)) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
74 (declare-function epg-make-context "epg" |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
75 (&optional protocol armor textmode include-certs |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
76 cipher-algorithm digest-algorithm |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
77 compress-algorithm)) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
78 (declare-function epg-encrypt-string "epg" |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
79 (context plain recipients &optional sign always-trust)) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
80 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
81 (defgroup org-crypt nil |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
82 "Org Crypt" |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
83 :tag "Org Crypt" :group 'org) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
84 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
85 (defcustom org-crypt-tag-matcher "crypt" |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
86 "The tag matcher used to find headings whose contents should be encrypted. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
87 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
88 See the \"Match syntax\" section of the org manual for more details." |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
89 :type 'string :group 'org-crypt) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
90 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
91 (defcustom org-crypt-key nil |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
92 "The default key to use when encrypting the contents of a heading. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
93 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
94 This setting can also be overridden in the CRYPTKEY property." |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
95 :type 'string :group 'org-crypt) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
96 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
97 (defun org-crypt-key-for-heading () |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
98 "Return the encryption key for the current heading." |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
99 (save-excursion |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
100 (org-back-to-heading t) |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
101 (or (org-entry-get nil "CRYPTKEY" 'selective) |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
102 org-crypt-key |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
103 (and (boundp 'epa-file-encrypt-to) epa-file-encrypt-to) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
104 (message "No crypt key set, using symmetric encryption.")))) |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
105 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
106 (defun org-encrypt-entry () |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
107 "Encrypt the content of the current headline." |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
108 (interactive) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
109 (require 'epg) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
110 (save-excursion |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
111 (org-back-to-heading t) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
112 (let ((start-heading (point))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
113 (forward-line) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
114 (when (not (looking-at "-----BEGIN PGP MESSAGE-----")) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
115 (let ((folded (org-invisible-p)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
116 (epg-context (epg-make-context nil t t)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
117 (crypt-key (org-crypt-key-for-heading)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
118 (beg (point)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
119 end encrypted-text) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
120 (goto-char start-heading) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
121 (org-end-of-subtree t t) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
122 (org-back-over-empty-lines) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
123 (setq end (point) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
124 encrypted-text |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
125 (epg-encrypt-string |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
126 epg-context |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
127 (buffer-substring-no-properties beg end) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
128 (epg-list-keys epg-context crypt-key))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
129 (delete-region beg end) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
130 (insert encrypted-text) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
131 (when folded |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
132 (goto-char start-heading) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
133 (hide-subtree)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
134 nil))))) |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
135 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
136 (defun org-decrypt-entry () |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
137 "Decrypt the content of the current headline." |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
138 (interactive) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
139 (require 'epg) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
140 (unless (org-before-first-heading-p) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
141 (save-excursion |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
142 (org-back-to-heading t) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
143 (forward-line) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
144 (when (looking-at "-----BEGIN PGP MESSAGE-----") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
145 (let* ((beg (point)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
146 (end (save-excursion |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
147 (search-forward "-----END PGP MESSAGE-----") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
148 (forward-line) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
149 (point))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
150 (epg-context (epg-make-context nil t t)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
151 (decrypted-text |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
152 (decode-coding-string |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
153 (epg-decrypt-string |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
154 epg-context |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
155 (buffer-substring-no-properties beg end)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
156 'utf-8))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
157 (delete-region beg end) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
158 (insert decrypted-text) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
159 nil))))) |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
160 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
161 (defun org-encrypt-entries () |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
162 "Encrypt all top-level entries in the current buffer." |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
163 (interactive) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
164 (org-scan-tags |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
165 'org-encrypt-entry |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
166 (cdr (org-make-tags-matcher org-crypt-tag-matcher)))) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
167 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
168 (defun org-decrypt-entries () |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
169 "Decrypt all entries in the current buffer." |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
170 (interactive) |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
171 (org-scan-tags |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
172 'org-decrypt-entry |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
173 (cdr (org-make-tags-matcher org-crypt-tag-matcher)))) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
174 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
175 (defun org-crypt-use-before-save-magic () |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
107863
diff
changeset
|
176 "Add a hook to automatically encrypt entries before a file is saved to disk." |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
177 (add-hook |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
178 'org-mode-hook |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
179 (lambda () (add-hook 'before-save-hook 'org-encrypt-entries nil t)))) |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
180 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
181 (add-hook 'org-reveal-start-hook 'org-decrypt-entry) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
106815
diff
changeset
|
182 |
105341
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
183 (provide 'org-crypt) |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
184 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
185 ;; arch-tag: 8202ed2c-221e-4001-9e4b-54674a7e846e |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
186 |
2a8a3a69c1c7
2009-10-01 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
187 ;;; org-crypt.el ends here |