clarifying var names, testing base58 and multihash

yamux
jmjatlanta 2016-12-15 12:39:30 -05:00
parent 2ec3886276
commit 7e7a4e0712
5 changed files with 15 additions and 15 deletions

View File

@ -24,7 +24,7 @@
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.888872134" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.623347632" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
<option id="gnu.c.compiler.option.include.paths.1688271638" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<option id="gnu.c.compiler.option.include.paths.1688271638" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/c-multihash/include}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1284958161" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>

View File

@ -124,23 +124,22 @@ int libp2p_crypto_encoding_base58_decode(const char* b58, size_t base58_size, un
* @param base58_size the size of the results buffer
* @returns true(1) on success
*/
//int libp2p_crypto_encoding_base58_encode(const unsigned char* binary_data, size_t binary_data_size, unsigned char* base58, size_t* base58_size)
int libp2p_crypto_encoding_base58_encode(const unsigned char* data, size_t binsz, unsigned char** b58, size_t* b58sz)
int libp2p_crypto_encoding_base58_encode(const unsigned char* binary_data, size_t binary_data_size, unsigned char** base58, size_t* base58_size)
{
const uint8_t* bin = data;
const uint8_t* bin = binary_data;
int carry;
ssize_t i, j, high, zcount = 0;
size_t size;
while (zcount < (ssize_t)binsz && !bin[zcount]) {
while (zcount < (ssize_t)binary_data_size && !bin[zcount]) {
++zcount;
}
size = (binsz - zcount) * 138 / 100 + 1;
size = (binary_data_size - zcount) * 138 / 100 + 1;
uint8_t buf[size];
memset(buf, 0, size);
for (i = zcount, high = size - 1; i < (ssize_t)binsz; ++i, high = j) {
for (i = zcount, high = size - 1; i < (ssize_t)binary_data_size; ++i, high = j) {
for (carry = bin[i], j = size - 1; (j > high) || carry; --j) {
carry += 256 * buf[j];
buf[j] = carry % 58;
@ -151,20 +150,20 @@ int libp2p_crypto_encoding_base58_encode(const unsigned char* data, size_t binsz
for (j = 0; j < (ssize_t)size && !buf[j]; ++j)
;
if (*b58sz <= zcount + size - j) {
*b58sz = zcount + size - j + 1;
if (*base58_size <= zcount + size - j) {
*base58_size = zcount + size - j + 1;
memset(buf, 0, size);
return 0;
}
if (zcount) {
memset(b58, '1', zcount);
memset(base58, '1', zcount);
}
for (i = zcount; j < (ssize_t)size; ++i, ++j) {
(*b58)[i] = b58digits_ordered[buf[j]];
(*base58)[i] = b58digits_ordered[buf[j]];
}
(*b58)[i] = '\0';
*b58sz = i + 1;
(*base58)[i] = '\0';
*base58_size = i + 1;
memset(buf, 0, size);
return 1;

View File

@ -1,8 +1,9 @@
#include "../include/libp2p/multihash_old/multihash.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libp2p/multihash/multihash.h"
#include "libp2p/crypto/encoding/base58.h"

View File

@ -1,7 +1,7 @@
#ifndef test_multihash_h
#define test_multihash_h
#include "libp2p/multihash/multihash.h"
#include "../../include/libp2p/multihash_old/multihash.h"
#include "libp2p/crypto/encoding/base58.h"
int test_multihash_encode() {