oRTP 0.23.0
b64.h
1/* /////////////////////////////////////////////////////////////////////////////
2 * File: b64/b64.h
3 *
4 * Purpose: Header file for the b64 library
5 *
6 * Created: 18th October 2004
7 * Updated: 24th August 2008
8 *
9 * Thanks: To Adam McLaurin, for ideas regarding the b64_decode2() and
10 * b64_encode2().
11 *
12 * Home: http://synesis.com.au/software/
13 *
14 * Copyright (c) 2004-2008, Matthew Wilson and Synesis Software
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are met:
19 *
20 * - Redistributions of source code must retain the above copyright notice, this
21 * list of conditions and the following disclaimer.
22 * - Redistributions in binary form must reproduce the above copyright notice,
23 * this list of conditions and the following disclaimer in the documentation
24 * and/or other materials provided with the distribution.
25 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
26 * any contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 *
41 * ////////////////////////////////////////////////////////////////////////// */
42
43
49#ifndef B64_INCL_B64_H_B64
50#define B64_INCL_B64_H_B64
51
52/* /////////////////////////////////////////////////////////////////////////////
53 * Version information
54 */
55
56#ifndef B64_DOCUMENTATION_SKIP_SECTION
57# define B64_VER_B64_H_B64_MAJOR 1
58# define B64_VER_B64_H_B64_MINOR 5
59# define B64_VER_B64_H_B64_REVISION 4
60# define B64_VER_B64_H_B64_EDIT 28
61#endif /* !B64_DOCUMENTATION_SKIP_SECTION */
62
79#ifndef B64_DOCUMENTATION_SKIP_SECTION
80# define B64_VER_1_0_1 0x01000100
81# define B64_VER_1_0_2 0x01000200
82# define B64_VER_1_0_3 0x01000300
83# define B64_VER_1_1_1 0x01010100
84# define B64_VER_1_1_2 0x01010200
85# define B64_VER_1_1_3 0x01010300
86# define B64_VER_1_2_1 0x01020100
87# define B64_VER_1_2_2 0x01020200
88# define B64_VER_1_2_3 0x01020300
89# define B64_VER_1_2_4 0x01020400
90# define B64_VER_1_2_5 0x01020500
91# define B64_VER_1_2_6 0x01020600
92# define B64_VER_1_2_7 0x01020700
93# define B64_VER_1_3_1 0x010301ff
94# define B64_VER_1_3_2 0x010302ff
95# define B64_VER_1_3_3 0x010303ff
96# define B64_VER_1_3_4 0x010304ff
97
98# define B64_VER B64_VER_1_3_4
99#else /* ? B64_DOCUMENTATION_SKIP_SECTION */
100# define B64_VER 0x010304ff
101#endif /* !B64_DOCUMENTATION_SKIP_SECTION */
102
103#define B64_VER_MAJOR 1
104#define B64_VER_MINOR 3
105#define B64_VER_REVISION 4
106
107/* /////////////////////////////////////////////////////////////////////////////
108 * Includes
109 */
110
111#include <stddef.h>
112
113/* /////////////////////////////////////////////////////////////////////////////
114 * Namespace
115 */
116
117#if !defined(B64_NO_NAMESPACE) && \
118 !defined(__cplusplus)
119# define B64_NO_NAMESPACE
120#endif /* !B64_NO_NAMESPACE && !__cplusplus */
121
122#ifdef B64_NAMESPACE
123# undef B64_NAMESPACE
124#endif /* B64_NAMESPACE */
125
126#ifdef B64_NAMESPACE_QUALIFIER
127# undef B64_NAMESPACE_QUALIFIER
128#endif /* B64_NAMESPACE_QUALIFIER */
129
130
131#ifndef B64_NO_NAMESPACE
132
133# ifdef B64_CUSTOM_NAMESPACE
134# define B64_NAMESPACE B64_CUSTOM_NAMESPACE
135# else /* ? B64_CUSTOM_NAMESPACE */
136# define B64_NAMESPACE b64
137# endif /* B64_CUSTOM_NAMESPACE */
138
139# if defined(B64_CUSTOM_NAMESPACE) && \
140 defined(B64_CUSTOM_NAMESPACE_QUALIFIER)
141# define B64_NAMESPACE_QUALIFIER B64_CUSTOM_NAMESPACE_QUALIFIER
142# else /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
143# define B64_NAMESPACE_QUALIFIER ::B64_NAMESPACE
144# endif /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
145
146
155namespace B64_NAMESPACE
156{
157#endif /* !B64_NO_NAMESPACE */
158
159/* /////////////////////////////////////////////////////////////////////////////
160 * Enumerations
161 */
162
165enum B64_RC
166{
167 B64_RC_OK = 0
168 , B64_RC_INSUFFICIENT_BUFFER = 1
169 , B64_RC_TRUNCATED_INPUT = 2
170 , B64_RC_DATA_ERROR = 3
171#ifndef B64_DOCUMENTATION_SKIP_SECTION
172 , B64_max_RC_value
173#endif /* !B64_DOCUMENTATION_SKIP_SECTION */
174};
175
176#ifndef __cplusplus
177typedef enum B64_RC B64_RC;
178#endif /* !__cplusplus */
179
182enum B64_FLAGS
183{
184 B64_F_LINE_LEN_USE_PARAM = 0x0000
185 , B64_F_LINE_LEN_INFINITE = 0x0001
186 , B64_F_LINE_LEN_64 = 0x0002
187 , B64_F_LINE_LEN_76 = 0x0003
188 , B64_F_LINE_LEN_MASK = 0x000f
189 , B64_F_STOP_ON_NOTHING = 0x0000
190 , B64_F_STOP_ON_UNKNOWN_CHAR = 0x0100
191 , B64_F_STOP_ON_UNEXPECTED_WS = 0x0200
192 , B64_F_STOP_ON_BAD_CHAR = 0x0300
193};
194
195#ifndef __cplusplus
196typedef enum B64_FLAGS B64_FLAGS;
197#endif /* !__cplusplus */
198
199/* /////////////////////////////////////////////////////////////////////////////
200 * Functions
201 */
202
203#ifdef __cplusplus
204extern "C" {
205#endif /* __cplusplus */
206
230ORTP_PUBLIC size_t b64_encode(void const *src, size_t srcSize, char *dest, size_t destLen);
231
260size_t b64_encode2( void const *src
261 , size_t srcSize
262 , char *dest
263 , size_t destLen
264 , unsigned flags
265 , int lineLen /* = 0 */
266 , B64_RC *rc /* = NULL */);
267
301ORTP_PUBLIC size_t b64_decode(char const *src, size_t srcLen, void *dest, size_t destSize);
302
343size_t b64_decode2( char const *src
344 , size_t srcLen
345 , void *dest
346 , size_t destSize
347 , unsigned flags
348 , char const **badChar /* = NULL */
349 , B64_RC *rc /* = NULL */);
350
351
356char const *b64_getErrorString(B64_RC code);
357
364size_t b64_getErrorStringLength(B64_RC code);
365
366
367#ifdef __cplusplus
368} /* extern "C" */
369#endif /* __cplusplus */
370
371/* /////////////////////////////////////////////////////////////////////////////
372 * Namespace
373 */
374
375#ifndef B64_NO_NAMESPACE
376} /* namespace B64_NAMESPACE */
377
378# ifndef B64_DOCUMENTATION_SKIP_SECTION
379
380namespace stlsoft
381{
382
383 inline char const *c_str_data_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
384 {
386 }
387 inline char const *c_str_data( B64_NAMESPACE_QUALIFIER::B64_RC code)
388 {
390 }
391
392 inline size_t c_str_len_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
393 {
395 }
396 inline size_t c_str_len( B64_NAMESPACE_QUALIFIER::B64_RC code)
397 {
399 }
400
401 inline char const *c_str_ptr_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
402 {
404 }
405 inline char const *c_str_ptr( B64_NAMESPACE_QUALIFIER::B64_RC code)
406 {
408 }
409
410} /* namespace stlsoft */
411
412# endif /* !B64_DOCUMENTATION_SKIP_SECTION */
413
414#endif /* !B64_NO_NAMESPACE */
415
416/* ////////////////////////////////////////////////////////////////////////// */
417
418#endif /* B64_INCL_B64_H_B64 */
419
420/* ////////////////////////////////////////////////////////////////////////// */
char const * b64_getErrorString(B64_RC code)
Returns the textual description of the error.
Definition: b64.c:595
size_t b64_getErrorStringLength(B64_RC code)
Returns the length of the textual description of the error.
Definition: b64.c:600
size_t b64_decode2(char const *src, size_t srcLen, void *dest, size_t destSize, unsigned flags, char const **badChar, B64_RC *rc)
Decodes a sequence of Base-64 into a block of binary data.
Definition: b64.c:488
size_t b64_encode(void const *src, size_t srcSize, char *dest, size_t destLen)
Encodes a block of binary data into Base-64.
Definition: b64.c:423
size_t b64_encode2(void const *src, size_t srcSize, char *dest, size_t destLen, unsigned flags, int lineLen, B64_RC *rc)
Encodes a block of binary data into Base-64.
Definition: b64.c:433
size_t b64_decode(char const *src, size_t srcLen, void *dest, size_t destSize)
Decodes a sequence of Base-64 into a block of binary data.
Definition: b64.c:477