b64.h
/* /////////////////////////////////////////////////////////////////////////////
* File: b64/b64.h
*
* Purpose: Header file for the b64 library
*
* Created: 18th October 2004
* Updated: 24th August 2008
*
* Thanks: To Adam McLaurin, for ideas regarding the b64_decode2() and
* b64_encode2().
*
* Home: http://synesis.com.au/software/
*
* Copyright (c) 2004-2008, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
* any contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////////// */
#ifndef B64_INCL_B64_H_B64
#define B64_INCL_B64_H_B64
/* /////////////////////////////////////////////////////////////////////////////
* Version information
*/
#ifndef B64_DOCUMENTATION_SKIP_SECTION
# define B64_VER_B64_H_B64_MAJOR 1
# define B64_VER_B64_H_B64_MINOR 5
# define B64_VER_B64_H_B64_REVISION 4
# define B64_VER_B64_H_B64_EDIT 28
#endif /* !B64_DOCUMENTATION_SKIP_SECTION */
#ifndef B64_DOCUMENTATION_SKIP_SECTION
# define B64_VER_1_0_1 0x01000100
# define B64_VER_1_0_2 0x01000200
# define B64_VER_1_0_3 0x01000300
# define B64_VER_1_1_1 0x01010100
# define B64_VER_1_1_2 0x01010200
# define B64_VER_1_1_3 0x01010300
# define B64_VER_1_2_1 0x01020100
# define B64_VER_1_2_2 0x01020200
# define B64_VER_1_2_3 0x01020300
# define B64_VER_1_2_4 0x01020400
# define B64_VER_1_2_5 0x01020500
# define B64_VER_1_2_6 0x01020600
# define B64_VER_1_2_7 0x01020700
# define B64_VER_1_3_1 0x010301ff
# define B64_VER_1_3_2 0x010302ff
# define B64_VER_1_3_3 0x010303ff
# define B64_VER_1_3_4 0x010304ff
# define B64_VER B64_VER_1_3_4
#else /* ? B64_DOCUMENTATION_SKIP_SECTION */
# define B64_VER 0x010304ff
#endif /* !B64_DOCUMENTATION_SKIP_SECTION */
#define B64_VER_MAJOR 1
#define B64_VER_MINOR 3
#define B64_VER_REVISION 4
/* /////////////////////////////////////////////////////////////////////////////
* Includes
*/
#include <stddef.h>
/* /////////////////////////////////////////////////////////////////////////////
* Namespace
*/
#if !defined(B64_NO_NAMESPACE) && \
!defined(__cplusplus)
# define B64_NO_NAMESPACE
#endif /* !B64_NO_NAMESPACE && !__cplusplus */
#ifdef B64_NAMESPACE
# undef B64_NAMESPACE
#endif /* B64_NAMESPACE */
#ifdef B64_NAMESPACE_QUALIFIER
# undef B64_NAMESPACE_QUALIFIER
#endif /* B64_NAMESPACE_QUALIFIER */
#ifndef B64_NO_NAMESPACE
# ifdef B64_CUSTOM_NAMESPACE
# define B64_NAMESPACE B64_CUSTOM_NAMESPACE
# else /* ? B64_CUSTOM_NAMESPACE */
# define B64_NAMESPACE b64
# endif /* B64_CUSTOM_NAMESPACE */
# if defined(B64_CUSTOM_NAMESPACE) && \
defined(B64_CUSTOM_NAMESPACE_QUALIFIER)
# define B64_NAMESPACE_QUALIFIER B64_CUSTOM_NAMESPACE_QUALIFIER
# else /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
# define B64_NAMESPACE_QUALIFIER ::B64_NAMESPACE
# endif /* B64_CUSTOM_NAMESPACE && B64_CUSTOM_NAMESPACE_QUALIFIER */
namespace B64_NAMESPACE
{
#endif /* !B64_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////////
* Enumerations
*/
enum B64_RC
{
B64_RC_OK = 0
, B64_RC_INSUFFICIENT_BUFFER = 1
, B64_RC_TRUNCATED_INPUT = 2
, B64_RC_DATA_ERROR = 3
#ifndef B64_DOCUMENTATION_SKIP_SECTION
, B64_max_RC_value
#endif /* !B64_DOCUMENTATION_SKIP_SECTION */
};
#ifndef __cplusplus
typedef enum B64_RC B64_RC;
#endif /* !__cplusplus */
enum B64_FLAGS
{
B64_F_LINE_LEN_USE_PARAM = 0x0000
, B64_F_LINE_LEN_INFINITE = 0x0001
, B64_F_LINE_LEN_64 = 0x0002
, B64_F_LINE_LEN_76 = 0x0003
, B64_F_LINE_LEN_MASK = 0x000f
, B64_F_STOP_ON_NOTHING = 0x0000
, B64_F_STOP_ON_UNKNOWN_CHAR = 0x0100
, B64_F_STOP_ON_UNEXPECTED_WS = 0x0200
, B64_F_STOP_ON_BAD_CHAR = 0x0300
};
#ifndef __cplusplus
typedef enum B64_FLAGS B64_FLAGS;
#endif /* !__cplusplus */
/* /////////////////////////////////////////////////////////////////////////////
* Functions
*/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
size_t b64_encode(void const *src, size_t srcSize, char *dest, size_t destLen);
size_t b64_encode2( void const *src
, size_t srcSize
, char *dest
, size_t destLen
, unsigned flags
, int lineLen /* = 0 */
, B64_RC *rc /* = NULL */);
size_t b64_decode(char const *src, size_t srcLen, void *dest, size_t destSize);
size_t b64_decode2( char const *src
, size_t srcLen
, void *dest
, size_t destSize
, unsigned flags
, char const **badChar /* = NULL */
, B64_RC *rc /* = NULL */);
char const *b64_getErrorString(B64_RC code);
size_t b64_getErrorStringLength(B64_RC code);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
/* /////////////////////////////////////////////////////////////////////////////
* Namespace
*/
#ifndef B64_NO_NAMESPACE
} /* namespace B64_NAMESPACE */
# ifndef B64_DOCUMENTATION_SKIP_SECTION
namespace stlsoft
{
inline char const *c_str_data_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
{
return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
}
inline char const *c_str_data( B64_NAMESPACE_QUALIFIER::B64_RC code)
{
return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
}
inline size_t c_str_len_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
{
return B64_NAMESPACE_QUALIFIER::b64_getErrorStringLength(code);
}
inline size_t c_str_len( B64_NAMESPACE_QUALIFIER::B64_RC code)
{
return B64_NAMESPACE_QUALIFIER::b64_getErrorStringLength(code);
}
inline char const *c_str_ptr_a( B64_NAMESPACE_QUALIFIER::B64_RC code)
{
return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
}
inline char const *c_str_ptr( B64_NAMESPACE_QUALIFIER::B64_RC code)
{
return B64_NAMESPACE_QUALIFIER::b64_getErrorString(code);
}
} /* namespace stlsoft */
# endif /* !B64_DOCUMENTATION_SKIP_SECTION */
#endif /* !B64_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////////// */
#endif /* B64_INCL_B64_H_B64 */
/* ////////////////////////////////////////////////////////////////////////// */
b64_encode2
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
b64_getErrorStringLength
size_t b64_getErrorStringLength(B64_RC code)
Returns the length of the textual description of the error.
Definition: b64.c:600
b64_encode
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
b64_getErrorString
char const * b64_getErrorString(B64_RC code)
Returns the textual description of the error.
Definition: b64.c:595
b64_decode
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
b64_decode2
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