b58check_enc function and docs
This commit is contained in:
9
README
9
README
@@ -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)
|
||||
|
||||
16
base58.c
16
base58.c
@@ -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);
|
||||
}
|
||||
|
||||
1
base58.h
1
base58.h
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user