clarifying var names, testing base58 and multihash

This commit is contained in:
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"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.888872134" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool> </tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.623347632" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"> <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;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/c-multihash/include}&quot;"/>
</option> </option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1284958161" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> <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 * @param base58_size the size of the results buffer
* @returns true(1) on success * @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* 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)
{ {
const uint8_t* bin = data; const uint8_t* bin = binary_data;
int carry; int carry;
ssize_t i, j, high, zcount = 0; ssize_t i, j, high, zcount = 0;
size_t size; size_t size;
while (zcount < (ssize_t)binsz && !bin[zcount]) { while (zcount < (ssize_t)binary_data_size && !bin[zcount]) {
++zcount; ++zcount;
} }
size = (binsz - zcount) * 138 / 100 + 1; size = (binary_data_size - zcount) * 138 / 100 + 1;
uint8_t buf[size]; uint8_t buf[size];
memset(buf, 0, 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) { for (carry = bin[i], j = size - 1; (j > high) || carry; --j) {
carry += 256 * buf[j]; carry += 256 * buf[j];
buf[j] = carry % 58; 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) for (j = 0; j < (ssize_t)size && !buf[j]; ++j)
; ;
if (*b58sz <= zcount + size - j) { if (*base58_size <= zcount + size - j) {
*b58sz = zcount + size - j + 1; *base58_size = zcount + size - j + 1;
memset(buf, 0, size); memset(buf, 0, size);
return 0; return 0;
} }
if (zcount) { if (zcount) {
memset(b58, '1', zcount); memset(base58, '1', zcount);
} }
for (i = zcount; j < (ssize_t)size; ++i, ++j) { for (i = zcount; j < (ssize_t)size; ++i, ++j) {
(*b58)[i] = b58digits_ordered[buf[j]]; (*base58)[i] = b58digits_ordered[buf[j]];
} }
(*b58)[i] = '\0'; (*base58)[i] = '\0';
*b58sz = i + 1; *base58_size = i + 1;
memset(buf, 0, size); memset(buf, 0, size);
return 1; return 1;

View file

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

View file

@ -1,7 +1,7 @@
#ifndef test_multihash_h #ifndef test_multihash_h
#define 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" #include "libp2p/crypto/encoding/base58.h"
int test_multihash_encode() { int test_multihash_encode() {