Base64

Base64 Utilities. More...

Modules

Types
Base64 data types.
 

Functions

int32_t base64_encode (unsigned char *dst, uint32_t *dlen, const unsigned char *src, uint32_t slen)
 Encode a buffer into base64 format. More...
 
int32_t base64_decode (unsigned char *dst, uint32_t *dlen, const unsigned char *src, uint32_t slen)
 Decode a base64-formatted buffer. More...
 
zos_result_t base64_init_decode_context (base64_decode_context_t **context_ptr, void *user, uint32_t processing_buffer_size)
 Initialize base64_decode_context_t. More...
 
zos_result_t base64_init_encode_context (base64_encode_context_t **context_ptr, void *user, uint32_t processing_buffer_size)
 Initialize base64_encode_context_t. More...
 
zos_result_t base64_encode_with_writer (base64_encode_context_t *context, const void *data, uint32_t data_len, base64_writer_t writer)
 Base64 encode binary data with writer callback. More...
 
zos_result_t base64_decode_with_reader (base64_decode_context_t *context, void *data, uint32_t data_len, base64_reader_t reader)
 Base64 decode into binaryd data with reader callback. More...
 
void base64_destroy_context (void *context)
 Cleanup encode/decode context. More...
 

Detailed Description

Base64 Utilities.

Function Documentation

int32_t base64_decode ( unsigned char *  dst,
uint32_t *  dlen,
const unsigned char *  src,
uint32_t  slen 
)

Decode a base64-formatted buffer.

Parameters
dstdestination buffer
dlensize of the buffer
srcsource buffer
slenamount of data to be decoded
Returns
0 if successful, MYKROSSL_ERR_BASE64_BUFFER_TOO_SMALL, or MYKROSSL_ERR_BASE64_INVALID_DATA if the input data is not correct. *dlen is always updated to reflect the amount of data that has (or would have) been written.
Note
Call this function with *dlen = 0 to obtain the required buffer size in *dlen
zos_result_t base64_decode_with_reader ( base64_decode_context_t context,
void *  data,
uint32_t  data_len,
base64_reader_t  reader 
)

Base64 decode into binaryd data with reader callback.

Chunks of base64 encoded data are read using the supplied reader callback and decoded into the supplied buffer. This API is useful as it ensures each chunk of arbitrary length data is properly decoded without requiring base64 padding of the chunks.

Note
This API requires that the length of the non-base64 encoded data is known a priori. While this API may be called as many times as needed. The total sum of the supplied 'data_len' arguments must equal length of the non-base64 encoded binary data in bytes.
Parameters
[in]contextDecoding context pre-initialized with base64_init_decode_context()
[in]dataBuffer to hold decoded binary data
[in]data_lenLength of supplied data buffer
[in]readerReader callback to read base64 encoded data
Returns
zos_result_t
void base64_destroy_context ( void *  context)

Cleanup encode/decode context.

This cleans up (i.e de-allocates) a context allocated by base64_init_encode_context() or base64_init_decode_context()

Parameters
[in]contextContext to be de-allocated
int32_t base64_encode ( unsigned char *  dst,
uint32_t *  dlen,
const unsigned char *  src,
uint32_t  slen 
)

Encode a buffer into base64 format.

Parameters
dstdestination buffer
dlensize of the buffer
srcsource buffer
slenamount of data to be encoded
Returns
0 if successful, or MYKROSSL_ERR_BASE64_BUFFER_TOO_SMALL. *dlen is always updated to reflect the amount of data that has (or would have) been written.
Note
Call this function with *dlen = 0 to obtain the required buffer size in *dlen
zos_result_t base64_encode_with_writer ( base64_encode_context_t context,
const void *  data,
uint32_t  data_len,
base64_writer_t  writer 
)

Base64 encode binary data with writer callback.

Arbitrary chunks of binary data are base64 encoded and written using the supplied 'writer' callback. This API is useful as the supplied chunks may be any length. The API ensures the written data is properly base64 encoded as a continuous stream of data (i.e. it ensures no base64 encode padding is applied to the end of the data chunks).

Note
To ensure proper base64 encode padding, once all data is written call this API a final time with a NULL data buffer, e.g. base64_encode_with_writer(context, NULL, 0, base64_writer_callback);
Parameters
[in]contextEncoding context pre-initialized with base64_init_encode_context()
[in]dataBinary data to base64 encode
[in]data_lenLength of supplied data buffer
[in]writerWriter callback to write base64 encoded data
Returns
zos_result_t
zos_result_t base64_init_decode_context ( base64_decode_context_t **  context_ptr,
void *  user,
uint32_t  processing_buffer_size 
)

Initialize base64_decode_context_t.

This must be called before base64_decode_with_reader()

Use base64_destroy_context() to cleanup the context.

Parameters
[out]context_ptrPointer to hold allocated base64_decode_context_t
[in]userUser specificied argument passed to base64_reader_t
[in]processing_buffer_sizesize of decode processing buffer. A larger buffer typically means faster decoding. Typical value is 1024.
zos_result_t base64_init_encode_context ( base64_encode_context_t **  context_ptr,
void *  user,
uint32_t  processing_buffer_size 
)

Initialize base64_encode_context_t.

Use base64_destroy_context() to cleanup the context.

Parameters
[out]context_ptrPointer to hold allocated base64_encode_context_t
[in]userUser specificied argument passed to base64_writer_t
[in]processing_buffer_sizesize of encoding processing buffer. A larger buffer typically means faster encoding. Typical value is 1024.