b58check_enc function and docs

This commit is contained in:
Luke Dashjr
2014-08-17 12:23:40 +00:00
parent 6a93c8339b
commit b3034841db
3 changed files with 26 additions and 0 deletions

9
README
View File

@@ -40,3 +40,12 @@ itself. When b58enc returns, the variable will be modified to contain the actual
number of bytes used (including the null terminator). If encoding fails for any
reason, or if the string buffer is not large enough for the result, b58enc will
return false. Otherwise, it returns true to indicate success.
Encoding Base58Check
--------------------
Targetting base58check is done similarly to raw base58 encoding, but you must
also provide a version byte:
bool b58check_enc(char *b58c, size_t *b58c_sz, uint8_t ver,
const void *data, size_t datasz)

View File

@@ -158,3 +158,19 @@ bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz)
return true;
}
bool b58check_enc(char *b58c, size_t *b58c_sz, uint8_t ver, const void *data, size_t datasz)
{
uint8_t buf[1 + datasz + 0x20];
uint8_t *hash = &buf[1 + datasz];
buf[0] = ver;
memcpy(&buf[1], data, datasz);
if (!my_dblsha256(hash, buf, datasz + 1))
{
*b58c_sz = 0;
return false;
}
return b58enc(b58c, b58c_sz, buf, 1 + datasz + 4);
}

View File

@@ -10,5 +10,6 @@ extern bool b58tobin(void *bin, size_t binsz, const char *b58, size_t b58sz);
extern int b58check(const void *bin, size_t binsz, const char *b58, size_t b58sz);
extern bool b58enc(char *b58, size_t *b58sz, const void *bin, size_t binsz);
extern bool b58check_enc(char *b58c, size_t *b58c_sz, uint8_t ver, const void *data, size_t datasz);
#endif