[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Helper function for logging ed25519 public keys.



commit 2cdd24ddd69a3cde2deae3eb69c24ae179d83834
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Nov 10 10:43:28 2016 -0500

    Helper function for logging ed25519 public keys.
---
 src/common/crypto_format.c | 16 ++++++++++++++++
 src/common/crypto_format.h |  1 +
 2 files changed, 17 insertions(+)

diff --git a/src/common/crypto_format.c b/src/common/crypto_format.c
index 2f6d847..483013e 100644
--- a/src/common/crypto_format.c
+++ b/src/common/crypto_format.c
@@ -161,6 +161,22 @@ curve25519_public_from_base64(curve25519_public_key_t *pkey,
   }
 }
 
+/** For convenience: Convert <b>pkey</b> to a statically allocated base64
+ * string and return it. Not threadsafe. Subsequent calls invalidate
+ * previous returns. */
+const char *
+ed25519_fmt(const ed25519_public_key_t *pkey)
+{
+  static char formatted[ED25519_BASE64_LEN+1];
+  if (pkey) {
+    int r = ed25519_public_to_base64(formatted, pkey);
+    tor_assert(!r);
+  } else {
+    strlcpy(formatted, "<null>", sizeof(formatted));
+  }
+  return formatted;
+}
+
 /** Try to decode the string <b>input</b> into an ed25519 public key. On
  * success, store the value in <b>pkey</b> and return 0. Otherwise return
  * -1. */
diff --git a/src/common/crypto_format.h b/src/common/crypto_format.h
index 012e228..86c29d3 100644
--- a/src/common/crypto_format.h
+++ b/src/common/crypto_format.h
@@ -28,6 +28,7 @@ int ed25519_public_from_base64(ed25519_public_key_t *pkey,
                                const char *input);
 int ed25519_public_to_base64(char *output,
                              const ed25519_public_key_t *pkey);
+const char *ed25519_fmt(const ed25519_public_key_t *pkey);
 
 /* XXXX move these to crypto_format.h */
 #define ED25519_SIG_BASE64_LEN 86



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits