mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
base64: use void* to pass byte buffers
This commit is contained in:
parent
2cc1ac4fa8
commit
394c3ecd6d
@ -56,9 +56,10 @@ static char getsymbol(unsigned char code)
|
||||
return (char)BASE64_NOT_DEFINED;
|
||||
}
|
||||
|
||||
int base64_encode(const 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(const 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));
|
||||
|
||||
@ -160,8 +161,9 @@ static int getcode(char symbol)
|
||||
}
|
||||
|
||||
int base64_decode(const unsigned char *base64_in, size_t base64_in_size,
|
||||
unsigned char *data_out, size_t *data_out_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(const 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;
|
||||
|
@ -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(const 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);
|
||||
|
||||
/**
|
||||
@ -72,7 +72,7 @@ int base64_encode(const unsigned char *data_in, size_t data_in_size,
|
||||
BASE64_ERROR_DATA_IN_SIZE if `base64_in_size` is less then 4.
|
||||
*/
|
||||
int base64_decode(const unsigned char *base64_in, size_t base64_in_size,
|
||||
unsigned char *data_out, size_t *data_out_size);
|
||||
void *data_out, size_t *data_out_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user