1517b79978d86135e6c2b7c91a9beb60c49d550d
[platform/core/appfw/app-installers.git] / src / common / utils / base64.cc
1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "common/utils/base64.h"
6
7 #include <boost/archive/iterators/base64_from_binary.hpp>
8 #include <boost/archive/iterators/transform_width.hpp>
9
10 #include <algorithm>
11 #include <sstream>
12 #include <string>
13
14 namespace bai = boost::archive::iterators;
15
16 namespace {
17
18 typedef bai::base64_from_binary<bai::transform_width<const char*, 6, 8>>
19     base64_encode;
20
21 }  // namespace
22
23 namespace common_installer {
24
25 std::string EncodeBase64(unsigned char* val, size_t len) {
26   std::stringstream os;
27   std::copy(base64_encode(val), base64_encode(val + len),
28       std::ostream_iterator<char>(os));
29   return os.str();
30 }
31
32 }  // namespace common_installer