summaryrefslogtreecommitdiff
path: root/protocols/Quotes/src/Base64.cpp
blob: 1854fb42fdcc3b6eebf42f88ca0e572d64801d30 (plain)
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
#include "StdAfx.h"
#include "Base64.h"

bool base64::encode(const BYTE* in, size_t inlen,std::vector<char>& out)
{
	int nOutLength = Base64EncodeGetRequiredLength((int)inlen);
	out.resize(nOutLength);
	char* p = &*out.begin();
	bool bResult = (TRUE == Base64Encode(in,(int)inlen,p,&nOutLength));
	if(false == bResult)
	{
		out.resize(nOutLength);
		p = &*out.begin();
		bResult = (TRUE == Base64Encode(in,(int)inlen,p,&nOutLength));
	}
	if(bResult)
	{
		out.resize(nOutLength);
	}

	return bResult;
}


bool base64::decode(const char* in, size_t inlen,std::vector<BYTE>& out)
{
	int nOutLength = (int)inlen;
	out.resize(nOutLength);
	BYTE* p = &*out.begin();
	bool bResult = TRUE == Base64Decode(in,(int)inlen,p,&nOutLength);
	if(false == bResult)
	{
		out.resize(nOutLength);
		p = &*out.begin();
		bResult = TRUE == Base64Decode(in,(int)inlen,p,&nOutLength);
	}
	if(bResult)
	{
		out.resize(nOutLength);
	}

	return true;
}