* epa.el: Added header.
[elisp/epg.git] / epg.el
diff --git a/epg.el b/epg.el
index 5dc04d6..605f0d1 100644 (file)
--- a/epg.el
+++ b/epg.el
 (defvar epg-debug nil)
 
 (defvar epg-colons-pub-spec
-  '((trust "[^:]")
+  '((validity "[^:]")
     (length "[0-9]+" 0 string-to-number)
     (algorithm "[0-9]+" 0 string-to-number)
     (key-id "[^:]+")
     (creation-date "[0-9]+")
     (expiration-date "[0-9]+")
     nil
-    (ownertrust "[^:]")
+    (owner-trust "[^:]")
     nil
     nil
-    (capability "[escaESCA]*"))
+    (capability "[escaESCA]+"))
   "The schema of keylisting output whose type is \"pub\".
 This is used by `epg-list-keys'.")
 
 (defvar epg-colons-sec-spec
-  '((trust "[^:]")
+  '((validity "[^:]")
     (length "[0-9]+" 0 string-to-number)
     (algorithm "[0-9]+" 0 string-to-number)
     (key-id "[^:]+")
     (creation-date "[0-9]+")
     (expiration-date "[0-9]+")
     nil
-    (ownertrust "[^:]"))
+    (owner-trust "[^:]")
+    nil
+    nil
+    (capability "[escaESCA]+"))
 "The schema of keylisting output whose type is \"sec\".
 This is used by `epg-list-keys'.")
 
 (defvar epg-colons-uid-spec
-  '((trust "[^:]")
+  '((validity "[^:]")
     nil
     nil
     nil
@@ -85,6 +88,53 @@ This is used by `epg-list-keys'.")
   "The schema of keylisting output whose type is \"uid\".
 This is used by `epg-list-keys'.")
 
+(defvar epg-colons-fpr-spec
+  '(nil
+    nil
+    nil
+    nil
+    nil
+    nil
+    nil
+    nil
+    (fingerprint "[^:]+"))
+  "The schema of keylisting output whose type is \"fpr\".
+This is used by `epg-list-keys'.")
+
+(defconst epg-cipher-algorithm-alist
+  '((0 . "NONE")
+    (1 . "IDEA")
+    (2 . "3DES")
+    (3 . "CAST5")
+    (4 . "BLOWFISH")
+    (7 . "AES")
+    (8 . "AES192")
+    (9 . "AES256")
+    (10 . "TWOFISH")
+    (110 . "DUMMY")))
+
+(defconst epg-pubkey-algorithm-alist
+  '((1 . "RSA")
+    (2 . "RSA_E")
+    (3 . "RSA_S")
+    (16 . "ELGAMAL_E")
+    (17 . "DSA")
+    (20 . "ELGAMAL")))
+
+(defconst epg-digest-algorithm-alist
+  '((1 . "MD5")
+    (2 . "SHA1")
+    (3 . "RMD160")
+    (8 . "SHA256")
+    (9 . "SHA384")
+    (10 . "SHA512")))
+
+(defconst epg-compress-algorithm-alist
+  '((0 . "NONE")
+    (1 . "ZIP")
+    (2 . "ZLIB")
+    (3 . "BZIP2")))
+
 (defvar epg-prompt-alist nil)
 
 (defun epg-make-data-from-file (file)
@@ -254,8 +304,7 @@ This function is for internal use only."
   "Start `epg-gpg-program' in a subprocess with given ARGS."
   (let* ((args (append (list "--no-tty"
                             "--status-fd" "1"
-                            "--command-fd" "0"
-                            "--yes") ; overwrite
+                            "--command-fd" "0")
                       (if (epg-context-armor context) '("--armor"))
                       (if (epg-context-textmode context) '("--textmode"))
                       (if (epg-context-output-file context)
@@ -548,17 +597,37 @@ This function is for internal use only."
 (defun epg-progress-callback-function (what char current total handback)
   (message "%s: %d%%/%d%%" what current total))
 
+(defun epg-configuration ()
+  "Return a list of internal configuration parameters of `epg-gpg-program'."
+  (let (config type)
+    (with-temp-buffer
+      (apply #'call-process epg-gpg-program nil (list t nil) nil
+            '("--with-colons" "--list-config"))
+      (goto-char (point-min))
+      (while (re-search-forward "^cfg:\\([^:]+\\):\\(.*\\)" nil t)
+       (setq type (intern (match-string 1))
+             config (cons (cons type
+                                (if (memq type
+                                          '(pubkey cipher digest compress))
+                                    (mapcar #'string-to-number
+                                            (delete "" (split-string
+                                                        (match-string 2)
+                                                        ";")))
+                                  (match-string 2)))
+                          config))))
+    config))
+
 (defun epg-list-keys (name &optional secret)
   "List keys associated with STRING."
-  (let ((args (list "--with-colons" "--no-greeting" "--batch"
-                   "--fixed-list-mode"
-                   (if secret "--list-secret-keys" "--list-keys")
-                   name))
+  (let ((args (append (list "--with-colons" "--no-greeting" "--batch"
+                           "--fixed-list-mode" "--with-fingerprint"
+                           (if secret "--list-secret-keys" "--list-keys"))
+                     (if name (list name))))
        keys type symbol pointer)
     (with-temp-buffer
       (apply #'call-process epg-gpg-program nil (list t nil) nil args)
       (goto-char (point-min))
-      (while (looking-at "\\([a-z][a-z][a-z]\\):\\(.*\\)")
+      (while (re-search-forward "^\\([a-z][a-z][a-z]\\):\\(.*\\)" nil t)
        (setq type (match-string 1)
              symbol (intern-soft (format "epg-colons-%s-spec" type)))
        (if (member type '("pub" "sec"))