From 8e19636de5fc64d2042eb9889606742766791f66 Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 2 Feb 2017 19:09:50 -0500 Subject: [PATCH] Removed old peer id method --- repo/config/identity.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/repo/config/identity.c b/repo/config/identity.c index c21c94b..03be46b 100644 --- a/repo/config/identity.c +++ b/repo/config/identity.c @@ -11,6 +11,7 @@ #include "libp2p/crypto/peerutils.h" #include "libp2p/crypto/encoding/base64.h" #include "libp2p/crypto/encoding/x509.h" +#include "libp2p/crypto/key.h" /** * Builds the Peer ID using the private key, and places it in the identity->peer_id @@ -18,25 +19,13 @@ * @returns true(1) on success */ int repo_config_identity_build_peer_id(struct Identity* identity) { - // ic key and PeerID - unsigned char hash[32]; - ID_FromPK_non_null_terminated((char*)hash, (unsigned char*)identity->private_key.der, identity->private_key.der_length); - // peer id is multihashed - size_t sz = 255; - unsigned char results[sz]; - if (PrettyID(results, &sz, hash, 32) == 0) + struct PublicKey public_key; + public_key.data = (unsigned char*)identity->private_key.public_key_der; + public_key.data_size = identity->private_key.public_key_length; + public_key.type = KEYTYPE_RSA; + if (!libp2p_crypto_public_key_to_peer_id(&public_key, &identity->peer_id)) return 0; - - // copy it into the structure - if (identity->peer_id != NULL) - free(identity->peer_id); - identity->peer_id = (char*)malloc(sz + 1); - if (identity->peer_id == NULL) - return 0; - - strncpy(identity->peer_id, (char*)results, sz); - identity->peer_id[sz] = 0; return 1; }