Robot
Move a little robot.
base64.h File Reference
#include <stddef.h>
Include dependency graph for base64.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

size_t base64 (const char *signed_data, size_t len_data, char *res, size_t res_len)
 Implementation of base64 algorithm for binaries in general. More...
 
size_t base64_str (const char *s, char *res, size_t res_len)
 Implementation of base64 algorithm for strings. More...
 
char * open_and_read (const char *path, size_t *file_size_out)
 Open and read files. More...
 
char * base64_alloc (const char *data, size_t size, size_t *res_size_out)
 Allocates memory and applies base64 algorithm. More...
 
char * base64_from_path (const char *path, size_t *res_size_out)
 Uses open_and_read() and base64_alloc() to perform base64 algorithm. More...
 

Function Documentation

◆ base64()

size_t base64 ( const char *  signed_data,
size_t  len_data,
char *  res,
size_t  res_len 
)

Implementation of base64 algorithm for binaries in general.

Binary-to-text encoding into a set of 64 unique characters. Dource is taken 6 bits at a time, in this group of 6 is mapped to one of 64 unique characters. See: https://en.wikipedia.org/wiki/Base64

Parameters
dataPointer to the binary to encode.
len_dataLength of binary to encode.
resPointer to the result.
res_lenMax-size of result. Needs to be enough.
Returns
Size of final result. If > to res_len, you have you given enough space to res.

◆ base64_alloc()

char * base64_alloc ( const char *  data,
size_t  size,
size_t *  res_size_out 
)

Allocates memory and applies base64 algorithm.

Parameters
dataPointer to the binary to encode.
sizeLength of binary to encode.
res_size_outPointer to the size of result.
Returns
Pointer to the result. Does malloc()! So you should free later.

◆ base64_from_path()

char * base64_from_path ( const char *  path,
size_t *  res_size_out 
)

Uses open_and_read() and base64_alloc() to perform base64 algorithm.

Parameters
pathPointer to the binary to encode.
res_size_outPointer to the size of result.
Returns
Pointer to the result. Does malloc()! So you should free later.

◆ base64_str()

size_t base64_str ( const char *  s,
char *  res,
size_t  res_len 
)

Implementation of base64 algorithm for strings.

Just gets the data length by using strlen().

Parameters
dataPointer to the binary to encode.
resPointer to the result.
res_lenMax-size of result. Needs to be enough.
Returns
Size of final result. If > to res_len, you have you given enough space to res.

◆ open_and_read()

char * open_and_read ( const char *  path,
size_t *  file_size_out 
)

Open and read files.

Deals with errors and allocates required size.

Parameters
pathPointer to the file name.
file_size_outPointer to the size of result.
Returns
Pointer to the result. Does malloc()! So you should free later.