-
Notifications
You must be signed in to change notification settings - Fork 4
/
EncodeBase64Impl.cpp
58 lines (45 loc) · 1.37 KB
/
EncodeBase64Impl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// EncodeBase64Impl.cpp: implementation of the CEncodeBase64Impl class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "EncodeBase64Impl.h"
#include "appcommon.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CEncodeBase64Impl::CEncodeBase64Impl()
{
}
CEncodeBase64Impl::~CEncodeBase64Impl()
{
}
int CEncodeBase64Impl::encode(const char* src, const void* param, char* value)
{
int inlen = (int)strlen((const char*)src);
for (; inlen >= 3; inlen -= 3)
{
*value++ = base64digits[src[0] >> 2];
*value++ = base64digits[((src[0] << 4) & 0x30) | (src[1] >> 4)];
*value++ = base64digits[((src[1] << 2) & 0x3c) | (src[2] >> 6)];
*value++ = base64digits[src[2] & 0x3f];
src += 3;
}
if (inlen > 0)
{
unsigned char fragment;
*value++ = base64digits[src[0] >> 2];
fragment = (src[0] << 4) & 0x30;
if (inlen > 1)
fragment |= src[1] >> 4;
*value++ = base64digits[fragment];
*value++ = (inlen < 2) ? '=' : base64digits[(src[1] << 2) & 0x3c];
*value++ = '=';
}
*value = '\0';
return RET_CODE_SUCCESS;
}