16 using namespace kome::core;
21 #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
22 #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
57 for(
unsigned int i = 0; i < 256; i++ ) {
60 for(
unsigned int i = 0; i < 64; i++ ) {
68 const unsigned int srcLength,
70 const unsigned int destLength
76 char* cSrc = (
char*)src;
79 unsigned char dataBuff[ 3 ];
80 unsigned char base64Buff[ 4 ];
83 unsigned int srcPos = 0;
84 unsigned int destPos = 0;
85 unsigned int encodeSize = 0;
86 while( srcPos < srcLength ) {
88 fillzero( dataBuff,
sizeof( dataBuff ) );
91 unsigned int count = 0;
92 for(
unsigned int i = 0; i < 3; i++ ) {
93 if( srcPos < srcLength ) {
94 dataBuff[ i ] = cSrc[ srcPos++ ];
100 base64Buff[ 0 ] = base64.
m_encodeMap[ ( dataBuff[ 0 ] >> 2 ) & 0x3f ];
101 base64Buff[ 1 ] = base64.
m_encodeMap[ ( ( dataBuff[ 0 ] << 4 ) | ( dataBuff[ 1 ] >> 4 ) ) & 0x3f ];
102 base64Buff[ 2 ] = base64.
m_encodeMap[ ( ( dataBuff[ 1 ] << 2 ) | ( dataBuff[ 2 ] >> 6 ) ) & 0x3f ];
103 base64Buff[ 3 ] = base64.
m_encodeMap[ ( dataBuff[ 2 ] ) & 0x3f ];
106 for(
unsigned int i = 0; i < 4; i++ ) {
108 if( destPos >= destLength ) {
114 dest[ destPos++ ] =
'=';
117 dest[ destPos++ ] = base64Buff[ i ];
130 const unsigned int srcLength,
132 const unsigned int destLength
138 char* cDest = (
char*)dest;
142 unsigned char base64Buff[ 4 ];
145 unsigned int srcPos = 0;
146 unsigned int destPos = 0;
147 unsigned int length = 0;
149 while( srcPos < srcLength ) {
151 unsigned char c = (
unsigned char)src[ srcPos++ ];
157 if( length == 4 || c ==
'=' ) {
160 dataBuff[ 2 ] = ( base64Buff[ 2 ] << 6 ) | ( base64Buff[ 3 ] );
162 dataBuff[ 1 ] = ( base64Buff[ 1 ] << 4 ) | ( base64Buff[ 2 ] >> 2 );
164 dataBuff[ 0 ] = ( base64Buff[ 0 ] << 2 ) | ( base64Buff[ 1 ] >> 4 );
172 for(
unsigned int i = 0; i < length; i++ ) {
173 if( destPos >= destLength ) {
176 cDest[ destPos++ ] = dataBuff[ i ];
static int decode(char *src, const unsigned int srcLength, void *dest, const unsigned int destLength)
decodes source buffer into the destination buffer
void createMap()
creates encode and decode map
static int encode(void *src, const unsigned int srcLength, char *dest, const unsigned int destLength)
encodes source buffer into the destination buffer
static Base64 & getInstance()
gets base64 object
void fillzero(void *p, size_t n)
This function fills a block of memory zeros.
virtual ~Base64()
destructor
interfarces of Base64 class