1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #10053 from OTAkeys/feat/base64_const

sys/base64: api change (const + void*)
This commit is contained in:
Juan I Carrano 2018-10-23 17:53:58 +02:00 committed by GitHub
commit 12729d62a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -56,9 +56,10 @@ static char getsymbol(unsigned char code)
return (char)BASE64_NOT_DEFINED;
}
int base64_encode(unsigned char *data_in, size_t data_in_size, \
int base64_encode(const void *data_in, size_t data_in_size,
unsigned char *base64_out, size_t *base64_out_size)
{
const unsigned char *in = data_in;
size_t required_size = 4 * ((data_in_size + 2) / 3);
if (data_in == NULL) {
@ -86,7 +87,7 @@ int base64_encode(unsigned char *data_in, size_t data_in_size, \
for (int i = 0; i < (int)(data_in_size); ++i) {
unsigned char tmpval;
njump++;
tmpval = *(data_in + i);
tmpval = *(in + i);
nNum = (tmpval >> (2 * njump));
@ -159,9 +160,10 @@ static int getcode(char symbol)
return BASE64_NOT_DEFINED;
}
int base64_decode(unsigned char *base64_in, size_t base64_in_size, \
unsigned char *data_out, size_t *data_out_size)
int base64_decode(const unsigned char *base64_in, size_t base64_in_size,
void *data_out, size_t *data_out_size)
{
unsigned char *out = data_out;
size_t required_size = ((base64_in_size / 4) * 3);
if (base64_in == NULL) {
@ -200,13 +202,13 @@ int base64_decode(unsigned char *base64_in, size_t base64_in_size, \
nNum = nLst + ((code & (0xFF & nm)) >> (2 * mask));
nLst = (code & (0xFF & ~nm)) << (8 - (2 * mask));
(mask != 3) ? data_out[iterate_data_buffer++] = nNum : nNum;
(mask != 3) ? out[iterate_data_buffer++] = nNum : nNum;
(mask == 0) ? mask = 3 : mask--;
}
if (code == BASE64_EQUALS) {
/* add the last character to the data_out buffer */
data_out[iterate_data_buffer] = nNum;
out[iterate_data_buffer] = nNum;
}
*data_out_size = iterate_data_buffer;

View File

@ -50,7 +50,7 @@ extern "C" {
BASE64_ERROR_DATA_IN if `data_in` equals NULL,
BASE64_ERROR_DATA_IN_SIZE if `data_in_size` is less then 1.
*/
int base64_encode(unsigned char *data_in, size_t data_in_size, \
int base64_encode(const void *data_in, size_t data_in_size,
unsigned char *base64_out, size_t *base64_out_size);
/**
@ -71,8 +71,8 @@ int base64_encode(unsigned char *data_in, size_t data_in_size, \
BASE64_ERROR_DATA_IN if `base64_in` equals NULL,
BASE64_ERROR_DATA_IN_SIZE if `base64_in_size` is less then 4.
*/
int base64_decode(unsigned char *base64_in, size_t base64_in_size, \
unsigned char *data_out, size_t *data_out_size);
int base64_decode(const unsigned char *base64_in, size_t base64_in_size,
void *data_out, size_t *data_out_size);
#ifdef __cplusplus
}