diff --git a/src/common/crypto.c b/src/common/crypto.c index 4fe2ae0e85..e63a92c99b 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1470,6 +1470,16 @@ int crypto_pseudo_rand_int(unsigned int max) { } } +/** Return a randomly chosen element of sl; or NULL if sl is empty. + */ +void *smartlist_choose(const smartlist_t *sl) { + size_t len; + len = smartlist_len(sl); + if(len) + return smartlist_get(sl,crypto_pseudo_rand_int(len)); + return NULL; /* no elements to choose from */ +} + /** Base-64 encode srclen bytes of data from src. Write * the result into dest, if it will fit within destlen * bytes. Return the number of bytes written on success; -1 if @@ -1540,59 +1550,6 @@ base32_encode(char *dest, size_t destlen, const char *src, size_t srclen) dest[i] = '\0'; } -void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen) -{ - const char *end; - char *cp; - - tor_assert(destlen >= srclen*2+1); - - cp = dest; - end = src+srclen; - while (srclist[i]); } -/** Return a randomly chosen element of sl; or NULL if sl is empty. - */ -void *smartlist_choose(const smartlist_t *sl) { - if(sl->num_used) - return sl->list[crypto_pseudo_rand_int(sl->num_used)]; - return NULL; /* no elements to choose from */ -} - /** Return the idxth element of sl. */ void *smartlist_get(const smartlist_t *sl, int idx) @@ -2402,6 +2394,60 @@ void tor_mutex_release(tor_mutex_t *m) #endif +void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen) +{ + const char *end; + char *cp; + + tor_assert(destlen >= srclen*2+1); + + cp = dest; + end = src+srclen; + while (src