commit 8406677a5e6db74bd593a7d43868054b54b147df Author: Nick Mathewson nickm@torproject.org Date: Wed Sep 14 14:28:11 2016 -0400
Accessor functions to get a node's ID keys. --- src/or/nodelist.c | 33 +++++++++++++++++++++++++++++++++ src/or/nodelist.h | 2 ++ 2 files changed, 35 insertions(+)
diff --git a/src/or/nodelist.c b/src/or/nodelist.c index 2802d5b..9486224 100644 --- a/src/or/nodelist.c +++ b/src/or/nodelist.c @@ -53,6 +53,7 @@ #include "router.h" #include "routerlist.h" #include "routerset.h" +#include "torcert.h"
#include <string.h>
@@ -646,6 +647,38 @@ node_get_by_nickname,(const char *nickname, int warn_if_unnamed)) } }
+/** Return the Ed25519 identity key for the provided node, or NULL if it + * doesn't have one. */ +const ed25519_public_key_t * +node_get_ed25519_id(const node_t *node) +{ + if (node->ri) { + if (node->ri->cache_info.signing_key_cert) { + const ed25519_public_key_t *pk = + &node->ri->cache_info.signing_key_cert->signing_key; + if (BUG(ed25519_public_key_is_zero(pk))) + goto try_the_md; + return pk; + } + } + try_the_md: + if (node->md) { + if (node->md->ed25519_identity_pkey) { + return node->md->ed25519_identity_pkey; + } + } + return NULL; +} + +/** Return the RSA ID key's SHA1 digest for the provided node. */ +const uint8_t * +node_get_rsa_id_digest(const node_t *node) +{ + tor_assert(node); + return (const uint8_t*)node->identity; +} + + /** Return the nickname of <b>node</b>, or NULL if we can't find one. */ const char * node_get_nickname(const node_t *node) diff --git a/src/or/nodelist.h b/src/or/nodelist.h index 71a91e1..2cdcdce 100644 --- a/src/or/nodelist.h +++ b/src/or/nodelist.h @@ -55,6 +55,8 @@ void node_get_address_string(const node_t *node, char *cp, size_t len); long node_get_declared_uptime(const node_t *node); time_t node_get_published_on(const node_t *node); const smartlist_t *node_get_declared_family(const node_t *node); +const ed25519_public_key_t *node_get_ed25519_id(const node_t *node); +const uint8_t *node_get_rsa_id_digest(const node_t *node);
int node_has_ipv6_addr(const node_t *node); int node_has_ipv6_orport(const node_t *node);