diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-04-15 13:11:39 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-04-24 11:01:40 -0400 |
commit | 69a212ff3df2020fe67cedb71982b2198c31fe18 (patch) | |
tree | 1389d51d1ee95010d41b54159868b997dcc4f5db /src/or/consdiffmgr.c | |
parent | 655f1c8e011a52910152ba52fc24c6e5b85023b4 (diff) | |
download | tor-69a212ff3df2020fe67cedb71982b2198c31fe18.tar.gz tor-69a212ff3df2020fe67cedb71982b2198c31fe18.zip |
Consdiffmgr: extract "get a sha3 digest" function.
I'll be using this a lot in the hashtable tweaks here.
Diffstat (limited to 'src/or/consdiffmgr.c')
-rw-r--r-- | src/or/consdiffmgr.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/or/consdiffmgr.c b/src/or/consdiffmgr.c index dce8c8b437..16778b71a1 100644 --- a/src/or/consdiffmgr.c +++ b/src/or/consdiffmgr.c @@ -123,6 +123,29 @@ cdm_labels_prepend_sha3(config_line_t **labels, config_line_prepend(labels, LABEL_SHA3_DIGEST, hexdigest); } +/** Helper: if there is a sha3-256 hex-encoded digest in <b>ent</b> with the + * given label, set <b>digest_out</b> to that value (decoded), and return 0. + * + * Return -1 if there is no such label, and -2 if it is badly formatted. */ +static int +cdm_entry_get_sha3_value(uint8_t *digest_out, + consensus_cache_entry_t *ent, + const char *label) +{ + if (ent == NULL) + return -1; + + const char *hex = consensus_cache_entry_get_value(ent, label); + if (hex == NULL) + return -1; + + int n = base16_decode((char*)digest_out, DIGEST256_LEN, hex, strlen(hex)); + if (n != DIGEST256_LEN) + return -2; + else + return 0; +} + /** * Helper: look for a consensus with the given <b>flavor</b> and * <b>valid_after</b> time in the cache. Return that consensus if it's @@ -403,11 +426,6 @@ consdiffmgr_validate(void) consensus_cache_find_all(objects, cdm_cache_get(), NULL, NULL); SMARTLIST_FOREACH_BEGIN(objects, consensus_cache_entry_t *, obj) { - const char *lv_sha3 = - consensus_cache_entry_get_value(obj, LABEL_SHA3_DIGEST); - if (lv_sha3 == NULL) - continue; - uint8_t sha3_expected[DIGEST256_LEN]; uint8_t sha3_received[DIGEST256_LEN]; int r = cdm_entry_get_sha3_value(sha3_expected, obj, LABEL_SHA3_DIGEST); |