base64 conversion class
More...
#include <Base64.h>
|
| static int | encode (void *src, const unsigned int srcLength, char *dest, const unsigned int destLength) |
| | encodes source buffer into the destination buffer More...
|
| |
| static int | decode (char *src, const unsigned int srcLength, void *dest, const unsigned int destLength) |
| | decodes source buffer into the destination buffer More...
|
| |
base64 conversion class
Definition at line 23 of file Base64.h.
| static int kome::core::Base64::decode |
( |
char * |
src, |
|
|
const unsigned int |
srcLength, |
|
|
void * |
dest, |
|
|
const unsigned int |
destLength |
|
) |
| |
|
static |
decodes source buffer into the destination buffer
- Parameters
-
| [in] | src | source buffer |
| [in] | srcLength | byte length of the source buffer |
| [out] | dest | destination buffer |
| [in] | destLength | byte length of the destination buffer |
- Returns
- If negative value, destination buffer size is to small, otherwise returns the size of decoded data
Definition at line 128 of file Base64.cpp.
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 Base64 & getInstance()
gets base64 object
| static unsigned int kome::core::Base64::encode |
( |
void * |
src, |
|
|
const unsigned int |
srcLength, |
|
|
char * |
dest, |
|
|
const unsigned int |
destLength |
|
) |
| |
|
static |
encodes source buffer into the destination buffer
- Parameters
-
| [in] | src | source buffer |
| [in] | srcLength | byte length of the source buffer |
| [out] | dest | destination buffer |
| [in] | destLength | byte length of the destination buffer |
- Returns
- If negative value, destination buffer size is too small, otherwise returns the size of encoded data
Definition at line 66 of file Base64.cpp.
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 ];
static Base64 & getInstance()
gets base64 object
void fillzero(void *p, size_t n)
This function fills a block of memory zeros.
| static Base64 & kome::core::Base64::getInstance |
( |
| ) |
|
|
staticprotected |
gets base64 object
- Returns
- base64 object (This is the only object.)
Definition at line 192 of file Base64.cpp.
| int kome::core::Base64::m_decodeMap[256] |
|
protected |
decode map
Definition at line 42 of file Base64.h.
| char kome::core::Base64::m_encodeMap[64] |
|
protected |
encode map
Definition at line 39 of file Base64.h.
The documentation for this class was generated from the following files: