| 1 |
#include "libbase64.h" |
| 2 |
|
| 3 |
// Function parameters for encoding functions: |
| 4 |
#define BASE64_ENC_PARAMS \ |
| 5 |
( struct base64_state *state \ |
| 6 |
, const char *src \ |
| 7 |
, size_t srclen \ |
| 8 |
, char *out \ |
| 9 |
, size_t *outlen \ |
| 10 |
) |
| 11 |
|
| 12 |
// Function parameters for decoding functions: |
| 13 |
#define BASE64_DEC_PARAMS \ |
| 14 |
( struct base64_state *state \ |
| 15 |
, const char *src \ |
| 16 |
, size_t srclen \ |
| 17 |
, char *out \ |
| 18 |
, size_t *outlen \ |
| 19 |
) |
| 20 |
|
| 21 |
// This function is used as a stub when a certain encoder is not compiled in. |
| 22 |
// It discards the inputs and returns zero output bytes. |
| 23 |
static inline void |
| 24 |
base64_enc_stub BASE64_ENC_PARAMS |
| 25 |
{ |
| 26 |
(void) state; |
| 27 |
(void) src; |
| 28 |
(void) srclen; |
| 29 |
(void) out; |
| 30 |
|
| 31 |
*outlen = 0; |
| 32 |
} |
| 33 |
|
| 34 |
// This function is used as a stub when a certain decoder is not compiled in. |
| 35 |
// It discards the inputs and returns an invalid decoding result. |
| 36 |
static inline int |
| 37 |
base64_dec_stub BASE64_DEC_PARAMS |
| 38 |
{ |
| 39 |
(void) state; |
| 40 |
(void) src; |
| 41 |
(void) srclen; |
| 42 |
(void) out; |
| 43 |
(void) outlen; |
| 44 |
|
| 45 |
return -1; |
| 46 |
} |
| 47 |
|
| 48 |
typedef void (* base64_enc_fn) BASE64_ENC_PARAMS; |
| 49 |
typedef int (* base64_dec_fn) BASE64_DEC_PARAMS; |
| 50 |
|
| 51 |
struct codec |
| 52 |
{ |
| 53 |
base64_enc_fn enc; |
| 54 |
base64_dec_fn dec; |
| 55 |
}; |
| 56 |
|
| 57 |
extern void codec_choose (struct codec *, int flags); |