• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdint.h>
2 #include <stddef.h>
3 
4 #include "../include/libbase64.h"
5 #include "config.h"
6 
7 // Function parameters for encoding functions:
8 #define BASE64_ENC_PARAMS			\
9 	( struct base64_state	*state		\
10 	, const char		*src		\
11 	, size_t		 srclen		\
12 	, char			*out		\
13 	, size_t		*outlen		\
14 	)
15 
16 // Function parameters for decoding functions:
17 #define BASE64_DEC_PARAMS			\
18 	( struct base64_state	*state		\
19 	, const char		*src		\
20 	, size_t		 srclen		\
21 	, char			*out		\
22 	, size_t		*outlen		\
23 	)
24 
25 // Function signature for encoding functions:
26 #define BASE64_ENC_FUNCTION(arch)		\
27 	void					\
28 	base64_stream_encode_ ## arch		\
29 	BASE64_ENC_PARAMS
30 
31 // Function signature for decoding functions:
32 #define BASE64_DEC_FUNCTION(arch)		\
33 	int					\
34 	base64_stream_decode_ ## arch		\
35 	BASE64_DEC_PARAMS
36 
37 // Cast away unused variable, silence compiler:
38 #define UNUSED(x)		((void)(x))
39 
40 // Stub function when encoder arch unsupported:
41 #define BASE64_ENC_STUB				\
42 	UNUSED(state);				\
43 	UNUSED(src);				\
44 	UNUSED(srclen);				\
45 	UNUSED(out);				\
46 						\
47 	*outlen = 0;
48 
49 // Stub function when decoder arch unsupported:
50 #define BASE64_DEC_STUB				\
51 	UNUSED(state);				\
52 	UNUSED(src);				\
53 	UNUSED(srclen);				\
54 	UNUSED(out);				\
55 	UNUSED(outlen);				\
56 						\
57 	return -1;
58 
59 struct codec
60 {
61 	void (* enc) BASE64_ENC_PARAMS;
62 	int  (* dec) BASE64_DEC_PARAMS;
63 };
64 
65 extern void codec_choose (struct codec *, int flags);
66