-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase64.cpp
More file actions
49 lines (38 loc) · 1.35 KB
/
Copy pathBase64.cpp
File metadata and controls
49 lines (38 loc) · 1.35 KB
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
#include "stdafx.h"
#include "Base64.h"
#define BUFFER_SIZE 100
Base64::Base64()
{
}
utility::string_t Base64::constructBase64HeaderValue(const wchar_t* appendToBegin = 0, const wchar_t* dataToConvert = 0)
{
if (dataToConvert == NULL)
throw std::invalid_argument{ "Empty \"dataToConvert\" value of \"constructBase64HeaderValue\"" };
size_t mByteCounter;
char *pMBBuffer = (char*)malloc(BUFFER_SIZE);
if (pMBBuffer == NULL)
throw std::bad_alloc();
// Convertin a sequence of wide characters to a corresponding sequence of multibyte characters for Unicode support
_wcstombs_s_l(&mByteCounter, pMBBuffer, (size_t)BUFFER_SIZE, dataToConvert, (size_t)BUFFER_SIZE, _create_locale(LC_ALL, ".1251"));
// Converting sequence of multibyte characters to vector of unsigned chars for using in conversions::to_base64
std::string pString{ pMBBuffer };
std::vector<unsigned char> vCred(mByteCounter - 1);
std::transform(pString.begin(), pString.end(), vCred.begin(),
[](wchar_t c)
{
return static_cast<wchar_t>(c);
});
// Data prepared, converting it to base64
const auto b64cred{ conversions::to_base64(vCred) };
if (appendToBegin == 0)
return b64cred;
else {
// If something needs to be added before: composign header "Authorization" value
utility::string_t valBegin{ appendToBegin };
return valBegin.append(b64cred);
}
return 0;
}
Base64::~Base64()
{
}