aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-22 15:15:40 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-22 15:15:40 +0000
commit883972c483849025aeb4943281edfef3df04a609 (patch)
tree11d0a9588337c33e8383dfc21fed1f9a9d4ad456 /src
parent74bc80c0b5dc7206724d459a2a65552143af8d73 (diff)
downloadgnunet-883972c483849025aeb4943281edfef3df04a609.tar.gz
gnunet-883972c483849025aeb4943281edfef3df04a609.zip
-implementing zkey <-> pkey conversion functions
Diffstat (limited to 'src')
-rw-r--r--src/namestore/namestore_api_common.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/namestore/namestore_api_common.c b/src/namestore/namestore_api_common.c
index 4ca672f1e..3094d1aad 100644
--- a/src/namestore/namestore_api_common.c
+++ b/src/namestore/namestore_api_common.c
@@ -967,8 +967,19 @@ GNUNET_NAMESTORE_query_from_public_key (const struct GNUNET_CRYPTO_EccPublicKey
967const char * 967const char *
968GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey) 968GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EccPublicKey *pkey)
969{ 969{
970 GNUNET_break (0); // not implemented 970 static char ret[256];
971 return NULL; 971 char *pkeys;
972 size_t slen;
973
974 pkeys = GNUNET_CRYPTO_ecc_public_key_to_string (pkey);
975 slen = strlen (pkeys);
976 GNUNET_snprintf (ret,
977 sizeof (ret),
978 "%s.%.*s.zkey",
979 &pkeys[slen / 2],
980 (int) (slen / 2),
981 pkeys);
982 return ret;
972} 983}
973 984
974 985
@@ -985,7 +996,41 @@ int
985GNUNET_NAMESTORE_zkey_to_pkey (const char *zkey, 996GNUNET_NAMESTORE_zkey_to_pkey (const char *zkey,
986 struct GNUNET_CRYPTO_EccPublicKey *pkey) 997 struct GNUNET_CRYPTO_EccPublicKey *pkey)
987{ 998{
988 GNUNET_break (0); // not implemented 999 char *cpy;
1000 char *dot;
1001 const char *x;
1002 const char *y;
1003 char *pkeys;
1004
1005 cpy = GNUNET_strdup (zkey);
1006 y = cpy;
1007 if (NULL == (dot = strchr (y, (int) '.')))
1008 goto error;
1009 *dot = '\0';
1010 x = dot + 1;
1011 if (NULL == (dot = strchr (x, (int) '.')))
1012 goto error;
1013 *dot = '\0';
1014 if (0 != strcasecmp (dot + 1,
1015 "zkey"))
1016 goto error;
1017 GNUNET_asprintf (&pkeys,
1018 "%s%s",
1019 x, y);
1020 GNUNET_free (cpy);
1021 if (GNUNET_OK !=
1022 GNUNET_CRYPTO_ecc_public_key_from_string (pkeys,
1023 strlen (pkeys),
1024 pkey))
1025 {
1026 GNUNET_free (pkeys);
1027 return GNUNET_SYSERR;
1028 }
1029 GNUNET_free (pkeys);
1030 return GNUNET_OK;
1031 error:
1032 GNUNET_break (0);
1033 GNUNET_free (cpy);
989 return GNUNET_SYSERR; 1034 return GNUNET_SYSERR;
990} 1035}
991 1036