Browse Source

crypt: Allow nil value for `org-crypt-key'

* lisp/org-crypt.el (org-crypt-key): Allow nil value.
(org-crypt-key-for-heading): Handle nil value for `org-crypt-key'.
Nicolas Goaziou 4 years ago
parent
commit
9bc0cc7fb3
1 changed files with 17 additions and 11 deletions
  1. 17 11
      lisp/org-crypt.el

+ 17 - 11
lisp/org-crypt.el

@@ -94,15 +94,18 @@ See the \"Match syntax\" section of the org manual for more details."
 (defcustom org-crypt-key ""
 (defcustom org-crypt-key ""
   "The default key to use when encrypting the contents of a heading.
   "The default key to use when encrypting the contents of a heading.
 
 
-The string is matched against all keys in the key ring.  In
-particular, the empty string matches no key.
+If this variable is nil, always use symmetric encryption, unconditionally.
 
 
-This setting can be overridden in the CRYPTKEY property.
+Otherwise, The string is matched against all keys in the key ring.
+In particular, the empty string matches no key.  If no key is found,
+look for the `epa-file-encrypt-to' local variable.  Ultimately fall back
+to symmetric encryption.
 
 
-If no key is found, look for the `epa-file-encrypt-to' local
-variable.  Ultimately fall back to symmetric encryption."
+This setting can be overridden in the CRYPTKEY property."
   :group 'org-crypt
   :group 'org-crypt
-  :type 'string)
+  :type '(choice
+	  (string :tag "Public key(s) matching")
+	  (const :tag "Symmetric encryption" nil)))
 
 
 (defcustom org-crypt-disable-auto-save 'ask
 (defcustom org-crypt-disable-auto-save 'ask
   "What org-decrypt should do if `auto-save-mode' is enabled.
   "What org-decrypt should do if `auto-save-mode' is enabled.
@@ -191,11 +194,14 @@ See `org-crypt-disable-auto-save'."
 (defun org-crypt-key-for-heading ()
 (defun org-crypt-key-for-heading ()
   "Return the encryption key(s) for the current heading.
   "Return the encryption key(s) for the current heading.
 Assume `epg-context' is set."
 Assume `epg-context' is set."
-  (or (epg-list-keys epg-context
-		     (or (org-entry-get nil "CRYPTKEY" 'selective)
-			 org-crypt-key))
-      (bound-and-true-p epa-file-encrypt-to)
-      (progn (message "No crypt key set, using symmetric encryption.") nil)))
+  (and org-crypt-key
+       (or (epg-list-keys epg-context
+			  (or (org-entry-get nil "CRYPTKEY" 'selective)
+			      org-crypt-key))
+	   (bound-and-true-p epa-file-encrypt-to)
+	   (progn
+	     (message "No crypt key set, using symmetric encryption.")
+	     nil))))
 
 
 ;;;###autoload
 ;;;###autoload
 (defun org-encrypt-entry ()
 (defun org-encrypt-entry ()