1 #ifndef BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 13 #include "yaml-cpp/dll.h" 16 YAML_CPP_API std::string EncodeBase64(
const unsigned char *data,
18 YAML_CPP_API std::vector<unsigned char> DecodeBase64(
const std::string &input);
20 class YAML_CPP_API Binary {
22 Binary(
const unsigned char *data_, std::size_t size_)
23 : m_data{}, m_unownedData(data_), m_unownedSize(size_) {}
24 Binary() : Binary(nullptr, 0) {}
25 Binary(
const Binary &) =
default;
26 Binary(Binary &&) =
default;
27 Binary &operator=(
const Binary &) =
default;
28 Binary &operator=(Binary &&) =
default;
30 bool owned()
const {
return !m_unownedData; }
31 std::size_t size()
const {
return owned() ? m_data.size() : m_unownedSize; }
32 const unsigned char *data()
const {
33 return owned() ? &m_data[0] : m_unownedData;
36 void swap(std::vector<unsigned char> &rhs) {
40 rhs.resize(m_unownedSize);
41 std::copy(m_unownedData, m_unownedData + m_unownedSize, rhs.begin());
42 m_unownedData =
nullptr;
49 bool operator==(
const Binary &rhs)
const {
50 const std::size_t s = size();
53 const unsigned char *d1 = data();
54 const unsigned char *d2 = rhs.data();
55 for (std::size_t i = 0; i < s; i++) {
62 bool operator!=(
const Binary &rhs)
const {
return !(*
this == rhs); }
65 std::vector<unsigned char> m_data;
66 const unsigned char *m_unownedData;
67 std::size_t m_unownedSize;
71 #endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66