sks-devel
[Top][All Lists]
Advanced

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

[Sks-devel] [PATCH] add fingerprint line to machine readable output


From: Stefan Tomanek
Subject: [Sks-devel] [PATCH] add fingerprint line to machine readable output
Date: Wed, 11 Sep 2013 02:36:05 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

With this change, an additional line is appended to each search result when
using the machine readable output. This line is prefixed with "fpr:" and
contains the fingerprint of the key returned, making it possible to distinguish
keys from each other before downloading them - even if a key id collision has
occured.

Signed-off-by: Stefan Tomanek <address@hidden>
---
 dbserver.ml |    2 +-
 mRindex.ml  |   17 +++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/dbserver.ml b/dbserver.ml
index c8f8a96..073c6c1 100644
--- a/dbserver.ml
+++ b/dbserver.ml
@@ -298,7 +298,7 @@ struct
           if request.machine_readable then
             ("text/plain",
              count,
-             MRindex.keys_to_index keys)
+             MRindex.keys_to_index ~with_fpr:request.fingerprint keys)
           else
             begin
               try
diff --git a/mRindex.ml b/mRindex.ml
index 366b704..8758aeb 100644
--- a/mRindex.ml
+++ b/mRindex.ml
@@ -121,7 +121,7 @@ let key_expiration_from_uids keyid pk_ctime uids =
 (** number of seconds in a day *)
 let daysecs = Int64.of_int (60 * 60 * 24)
 
-let key_to_lines key =
+let key_to_lines ?(with_fpr=false) key =
   let full_keyid = Fingerprint.keyid_from_key ~short:false key in
   let keyid = Fingerprint.keyid_to_string ~short:false full_keyid in
   let fpr =  Utils.hexstring (Fingerprint.fp_from_key key) in
@@ -151,6 +151,8 @@ let key_to_lines key =
                    key_expiry_string
                    (if (Index.is_revoked key) then "r" else "")
   in
+  (* In any case, add an additional line with the complete fingerprint *)
+  let fpr_line = sprintf "fpr:%s" fpr in
   let uid_lines =
     List.map ~f:(fun (uid,sigs) ->
       match uid.packet_type with
@@ -159,12 +161,15 @@ let key_to_lines key =
         | _ -> "???::::"
       ) uids
   in
-  key_line::uid_lines
+  if with_fpr then
+    key_line::fpr_line::uid_lines
+  else
+    key_line::uid_lines
 
-let keys_to_lines keys =
+let keys_to_lines ?(with_fpr=false) keys =
   let first = sprintf "info:%d:%d" mr_version (List.length keys) in
-  let keylines = List.concat (List.map ~f:key_to_lines keys) in
+  let keylines = List.concat (List.map ~f:(key_to_lines ~with_fpr) keys) in
   first::keylines
 
-let keys_to_index keys =
-  (String.concat ~sep:"\n" (keys_to_lines keys)) ^ "\n"
+let keys_to_index ?(with_fpr=false) keys =
+  (String.concat ~sep:"\n" (keys_to_lines ~with_fpr keys)) ^ "\n"
-- 
1.7.10.4

Attachment: signature.asc
Description: Digital signature


reply via email to

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