forked from aseprite/laf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64.cpp
More file actions
38 lines (31 loc) · 895 Bytes
/
base64.cpp
File metadata and controls
38 lines (31 loc) · 895 Bytes
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
// LAF Base Library
// Copyright (c) 2015-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "base/base64.h"
#include "modp_b64.h"
namespace base {
void encode_base64(const buffer& input, std::string& output)
{
size_t size = modp_b64_encode_len(input.size());
output.resize(size);
size = modp_b64_encode(&output[0], (const char*)&input[0], input.size());
if (size != (size_t)-1)
output.erase(size, std::string::npos);
else
output.clear();
}
void decode_base64(const std::string& input, buffer& output)
{
output.resize(modp_b64_decode_len(input.size()));
size_t size = modp_b64_decode((char*)&output[0], input.c_str(), input.size());
if (size != (size_t)-1)
output.resize(size);
else
output.resize(0);
}
} // namespace base