Loading...
Searching...
No Matches
base64 encoder decoder

base64 encoder and decoder More...

Detailed Description

base64 encoder and decoder

encoding and decoding functions for base64

Author
Martin Landsmann Marti.nosp@m.n.La.nosp@m.ndsma.nosp@m.nn@H.nosp@m.AW-Ha.nosp@m.mbur.nosp@m.g.de

Macros

#define BASE64_SUCCESS   (0)
 return value for success

 
#define BASE64_ERROR_BUFFER_OUT   (-1)
 error value for invalid output buffer pointer

 
#define BASE64_ERROR_BUFFER_OUT_SIZE   (-2)
 error value for invalid output buffer size

 
#define BASE64_ERROR_DATA_IN   (-3)
 error value for invalid input buffer

 
#define BASE64_ERROR_DATA_IN_SIZE   (-4)
 error value for invalid input buffer size

 

Functions

static size_t base64_estimate_decode_size (size_t base64_in_size)
 Estimates the amount of bytes needed for decoding base64_in_size characters from base64.
 
static size_t base64_estimate_encode_size (size_t data_in_size)
 Estimates the length of the resulting string after encoding data_in_size bytes into base64.
 
int base64_encode (const void *data_in, size_t data_in_size, void *base64_out, size_t *base64_out_size)
 Encodes a given datum to base64 and save the result to the given destination.
 
int base64url_encode (const void *data_in, size_t data_in_size, void *base64_out, size_t *base64_out_size)
 Encodes a given datum to base64 with URL and Filename Safe Alphabet and save the result to the given destination.
 
int base64_decode (const void *base64_in, size_t base64_in_size, void *data_out, size_t *data_out_size)
 Decodes a given base64 string and save the result to the given destination.
 

Macro Definition Documentation

◆ BASE64_ERROR_BUFFER_OUT

#define BASE64_ERROR_BUFFER_OUT   (-1)

error value for invalid output buffer pointer

Definition at line 30 of file base64.h.

◆ BASE64_ERROR_BUFFER_OUT_SIZE

#define BASE64_ERROR_BUFFER_OUT_SIZE   (-2)

error value for invalid output buffer size

Definition at line 31 of file base64.h.

◆ BASE64_ERROR_DATA_IN

#define BASE64_ERROR_DATA_IN   (-3)

error value for invalid input buffer

Definition at line 32 of file base64.h.

◆ BASE64_ERROR_DATA_IN_SIZE

#define BASE64_ERROR_DATA_IN_SIZE   (-4)

error value for invalid input buffer size

Definition at line 33 of file base64.h.

◆ BASE64_SUCCESS

#define BASE64_SUCCESS   (0)

return value for success

Definition at line 29 of file base64.h.

Function Documentation

◆ base64_decode()

int base64_decode ( const void *  base64_in,
size_t  base64_in_size,
void *  data_out,
size_t *  data_out_size 
)

Decodes a given base64 string and save the result to the given destination.

Parameters
[out]base64_inpointer to store the encoded base64 string
[in]base64_in_sizepointer to the variable containing the size of base64_out.
[in]data_outpointer to the datum to encode
[in,out]data_out_sizethe size of data_out. This value is overwritten with the estimated size used for the decoded string on BASE64_ERROR_BUFFER_OUT_SIZE. This value is overwritten with the actual used size for the decoded string on BASE64_SUCCESS.
Returns
BASE64_SUCCESS on success, BASE64_ERROR_BUFFER_OUT_SIZE on insufficient size for decoding to data_out, BASE64_ERROR_BUFFER_OUT if data_out equals NULL but the size for data_out_size is sufficient, BASE64_ERROR_DATA_IN if base64_in equals NULL, BASE64_ERROR_DATA_IN_SIZE if base64_in_size is between 1 and 4.

◆ base64_encode()

int base64_encode ( const void *  data_in,
size_t  data_in_size,
void *  base64_out,
size_t *  base64_out_size 
)

Encodes a given datum to base64 and save the result to the given destination.

Parameters
[in]data_inpointer to the datum to encode
[in]data_in_sizethe size of data_in
[out]base64_outpointer to store the encoded base64 string
[in,out]base64_out_sizepointer to the variable containing the size of base64_out. This value is overwritten with the estimated size used for the encoded base64 string on BASE64_ERROR_BUFFER_OUT_SIZE. This value is overwritten with the actual used size for the encoded base64 string on BASE64_SUCCESS.
Returns
BASE64_SUCCESS on success, BASE64_ERROR_BUFFER_OUT_SIZE on insufficient size for encoding to base64_out, BASE64_ERROR_BUFFER_OUT if base64_out equals NULL but the base64_out_size is sufficient, BASE64_ERROR_DATA_IN if data_in equals NULL.

◆ base64_estimate_decode_size()

static size_t base64_estimate_decode_size ( size_t  base64_in_size)
inlinestatic

Estimates the amount of bytes needed for decoding base64_in_size characters from base64.

Parameters
[in]base64_in_sizeSize of the string to be decoded
Returns
Amount of bytes estimated to be used after decoding

Definition at line 42 of file base64.h.

◆ base64_estimate_encode_size()

static size_t base64_estimate_encode_size ( size_t  data_in_size)
inlinestatic

Estimates the length of the resulting string after encoding data_in_size bytes into base64.

Parameters
[in]data_in_sizeAmount of bytes to be encoded
Returns
Amount of characters the output string is estimated to have

Definition at line 54 of file base64.h.

◆ base64url_encode()

int base64url_encode ( const void *  data_in,
size_t  data_in_size,
void *  base64_out,
size_t *  base64_out_size 
)

Encodes a given datum to base64 with URL and Filename Safe Alphabet and save the result to the given destination.

See also
RFC 4648, section 5
Note
Requires the use of the base64url module.
Parameters
[in]data_inpointer to the datum to encode
[in]data_in_sizethe size of data_in
[out]base64_outpointer to store the encoded base64 string
[in,out]base64_out_sizepointer to the variable containing the size of base64_out. This value is overwritten with the estimated size used for the encoded base64 string on BASE64_ERROR_BUFFER_OUT_SIZE. This value is overwritten with the actual used size for the encoded base64 string on BASE64_SUCCESS.
Returns
BASE64_SUCCESS on success, BASE64_ERROR_BUFFER_OUT_SIZE on insufficient size for encoding to base64_out, BASE64_ERROR_BUFFER_OUT if base64_out equals NULL but the base64_out_size is sufficient, BASE64_ERROR_DATA_IN if data_in equals NULL.