libbase58check
Library for Base58Check encoding and decoding
Functions
base58check.h File Reference
Include dependency graph for base58check.h:

Functions

int base58check_decode (unsigned char **restrict out, size_t *n_out, const char *restrict in, size_t n_in, size_t n_hdr)
 Decodes data from Base58Check format. More...
 
size_t base58check_decode_buffer_size (const char *in, size_t n_in, size_t n_pad)
 Returns the recommended size of a buffer to hold the decoding of the specified Base58Check encoding. More...
 
int base58check_encode (char **restrict out, size_t *n_out, const unsigned char *restrict in, size_t n_in, size_t n_hdr)
 Encodes data in Base58Check format. More...
 
size_t base58check_encode_buffer_size (const unsigned char *in, size_t n_in, size_t n_pad)
 Returns the recommended size of a buffer to hold the Base58Check encoding of the specified input data. More...
 
void base58check_free (void *ptr)
 Frees memory allocated by base58check_malloc(). More...
 
void * base58check_malloc (size_t size)
 Allocates memory. More...
 

Function Documentation

◆ base58check_decode()

int base58check_decode ( unsigned char **restrict  out,
size_t *  n_out,
const char *restrict  in,
size_t  n_in,
size_t  n_hdr 
)

Decodes data from Base58Check format.

Parameters
[in,out]out

A pointer to the address of a buffer into which the decoded data are to be written. Must not be NULL.

If *out is NULL upon entry, then this function will allocate a suitably sized buffer by calling base58check_malloc() and will set *out to the address of that buffer. It is the caller's responsibility to free the allocated buffer by passing its address to base58check_free().

If *out is not NULL upon entry, then this function will write the decoded data to the buffer at address *out, which is of size given by *n_out.

[in,out]n_out

If *out is not NULL upon entry, a pointer to the size of the buffer at address *out, or else a pointer to the minimum number of excess bytes of buffer space to allocate beyond the end of the decoded data. Must not be NULL.

Upon return, *n_out will be set to the size of the decoded data, including any n_hdr bytes but not including any excess.

[in]inA pointer to the Base58Check encoding to be decoded. Must not be NULL.
n_inThe size of the Base58Check encoding at in, not including any possible terminator.
n_hdrThe number of bytes to skip at *out before writing the decoded data.
Returns
0 if the decoding was successful, or a negative number upon error, which may be because n_in was too large, *n_out was too small or too large, n_hdr was too large, the encoding at in contained an illegal character, there was a checksum mismatch, or there was a failure to allocate memory.

◆ base58check_decode_buffer_size()

size_t base58check_decode_buffer_size ( const char *  in,
size_t  n_in,
size_t  n_pad 
)

Returns the recommended size of a buffer to hold the decoding of the specified Base58Check encoding.

Parameters
[in]inA pointer to the Base58Check encoding needing to be decoded. Must not be NULL.
n_inThe size of the Base58Check encoding at in, not including any possible terminator.
n_padThe minimum number of excess bytes to include in the returned estimate.
Returns
An upper-bound estimate of the size of the decoding of the specified Base58Check encoding, or SIZE_MAX upon overflow.

◆ base58check_encode()

int base58check_encode ( char **restrict  out,
size_t *  n_out,
const unsigned char *restrict  in,
size_t  n_in,
size_t  n_hdr 
)

Encodes data in Base58Check format.

Parameters
[in,out]out

A pointer to the address of a buffer into which the encoding is to be written. Must not be NULL.

If *out is NULL upon entry, then this function will allocate a suitably sized buffer by calling base58check_malloc() and will set *out to the address of that buffer. It is the caller's responsibility to free the allocated buffer by passing its address to base58check_free().

If *out is not NULL upon entry, then this function will write the encoding to the buffer at address *out, which is of size given by *n_out.

[in,out]n_out

If *out is not NULL upon entry, a pointer to the size of the buffer at address *out, or else a pointer to the minimum number of excess bytes of buffer space to allocate beyond the end of the encoding. Must not be NULL.

Upon return, *n_out will be set to the size of the encoding, including any n_hdr bytes but not including any excess.

[in]inA pointer to the input data to be encoded. Must not be NULL.
n_inThe number of bytes of input data at in.
n_hdrThe number of bytes to skip at *out before writing the encoding.
Returns
0 if the encoding was successful, or a negative number upon error, which may be because n_in was too large, *n_out was too small or too large, n_hdr was too large, or there was a failure to allocate memory.

◆ base58check_encode_buffer_size()

size_t base58check_encode_buffer_size ( const unsigned char *  in,
size_t  n_in,
size_t  n_pad 
)

Returns the recommended size of a buffer to hold the Base58Check encoding of the specified input data.

Parameters
[in]inA pointer to the input data needing to be encoded. Must not be NULL.
n_inThe number of bytes of input data at in.
n_padThe minimum number of excess bytes to include in the returned estimate.
Returns
An upper-bound estimate of the size of the Base58Check encoding of the specified input data, or SIZE_MAX upon overflow.

◆ base58check_free()

void base58check_free ( void *  ptr)

Frees memory allocated by base58check_malloc().

Note
This is a weak symbol in libbase58check that may be overridden at (dynamic) link time. The default implementation forwards to free.
Parameters
ptrA pointer to the memory allocation to be freed. Must have been previously returned by base58check_malloc() and must not be NULL.

◆ base58check_malloc()

void* base58check_malloc ( size_t  size)

Allocates memory.

Note
This is a weak symbol in libbase58check that may be overridden at (dynamic) link time. The default implementation forwards to malloc.
Parameters
sizeThe size of the requested allocation.
Returns
A pointer to the allocated memory, or NULL if a memory allocation of the requested size could not be provided. If not NULL, this pointer must be passed to base58check_free() to free the allocation.