NetBurner 3.1
base64.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
5 #ifndef _BASE64_H_
6 #define _BASE64_H_
7 
8 #include <basictypes.h>
9 #include <ctype.h>
10 #include <iointernal.h>
11 
28 int Base64Decode(const char *input, uint8_t *outputbuf, const char *pEndMarker = NULL);
29 
46 int Base64UrlDecode(const char *input, uint8_t *outputbuf, const char *pEndMarker = NULL);
47 
48 
49 
66 int Base64Encode(uint8_t *input, int inlen, char *outputbuf);
67 
84 int Base64UrlEncode(uint8_t *input, int inlen, char *outputbuf);
85 
103 int Base64StreamEncode(int fd, uint8_t *input, int inlen, char *outBuf, int maxOutLen);
104 
122 int Base64UrlStreamEncode(int fd, uint8_t *input, int inlen, char *outBuf, int maxOutLen);
123 
124 class b64ctx
125 {
126  private:
127  int bits;
128  uint32_t accum;
129  char *outBuf;
130  const char *encodestr;
131  int maxOutLen;
132  int m_myFd;
133  int m_baseFd;
134 
135  int write(const char *in, int inlen);
136  int close();
137  friend int b64io_write(int fd, const char *in, int nbytes);
138  friend int b64io_close(int fd);
139 
140  public:
141  b64ctx(char *_outBuf, int _maxOutLen, bool UrlEncode = false);
142  void init(char *_outBuf, int _maxOutLen);
143  int flush();
144 
145  int GetFD(IoExpandStruct &io, int baseFd);
146 };
147 
148 #ifdef TEST_BASE64
149 /* Test string */
150 const char *base64msg =
151  "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFz\
152 b24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCB\
153 pcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbi\
154 B0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBle\
155 GNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=";
156 #endif /* #ifdef TEST_BASE64 */
157 
158 #endif /* #ifndef _BASE64_H_ */
void init()
System initialization. Normally called at the beginning of all applications.
Definition: init.cpp:22
int write(int fd, const char *buf, int nbytes)
This function writes data to the stream associated with a file descriptor (fd).
Definition: fileio.cpp:152
int close(int fd)
This function closes the resources associated with a file descriptor (fd). This can be a TCP socket o...
Definition: fileio.cpp:99
NetBurner File Descriptor Library API.
#define NULL
Definition: nm_bsp.h:76