LCOV - code coverage report
Current view: top level - usr/include/yaml-cpp - binary.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 2 17 11.8 %
Date: 2025-08-24 09:11:10 Functions: 1 6 16.7 %

          Line data    Source code
       1             : #ifndef BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
       2             : #define BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66
       3             : 
       4             : #if defined(_MSC_VER) ||                                            \
       5             :     (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
       6             :      (__GNUC__ >= 4))  // GCC supports "pragma once" correctly since 3.4
       7             : #pragma once
       8             : #endif
       9             : 
      10             : #include <string>
      11             : #include <vector>
      12             : 
      13             : #include "yaml-cpp/dll.h"
      14             : 
      15             : namespace YAML {
      16             : YAML_CPP_API std::string EncodeBase64(const unsigned char *data,
      17             :                                       std::size_t size);
      18             : YAML_CPP_API std::vector<unsigned char> DecodeBase64(const std::string &input);
      19             : 
      20             : class YAML_CPP_API Binary {
      21             :  public:
      22         706 :   Binary(const unsigned char *data_, std::size_t size_)
      23         706 :       : m_data{}, m_unownedData(data_), m_unownedSize(size_) {}
      24           0 :   Binary() : Binary(nullptr, 0) {}
      25             :   Binary(const Binary &) = default;
      26             :   Binary(Binary &&) = default;
      27             :   Binary &operator=(const Binary &) = default;
      28             :   Binary &operator=(Binary &&) = default;
      29             : 
      30           0 :   bool owned() const { return !m_unownedData; }
      31           0 :   std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; }
      32           0 :   const unsigned char *data() const {
      33           0 :     return owned() ? &m_data[0] : m_unownedData;
      34             :   }
      35             : 
      36           0 :   void swap(std::vector<unsigned char> &rhs) {
      37           0 :     if (m_unownedData) {
      38           0 :       m_data.swap(rhs);
      39           0 :       rhs.clear();
      40           0 :       rhs.resize(m_unownedSize);
      41           0 :       std::copy(m_unownedData, m_unownedData + m_unownedSize, rhs.begin());
      42           0 :       m_unownedData = nullptr;
      43           0 :       m_unownedSize = 0;
      44             :     } else {
      45           0 :       m_data.swap(rhs);
      46             :     }
      47           0 :   }
      48             : 
      49             :   bool operator==(const Binary &rhs) const {
      50             :     const std::size_t s = size();
      51             :     if (s != rhs.size())
      52             :       return false;
      53             :     const unsigned char *d1 = data();
      54             :     const unsigned char *d2 = rhs.data();
      55             :     for (std::size_t i = 0; i < s; i++) {
      56             :       if (*d1++ != *d2++)
      57             :         return false;
      58             :     }
      59             :     return true;
      60             :   }
      61             : 
      62             :   bool operator!=(const Binary &rhs) const { return !(*this == rhs); }
      63             : 
      64             :  private:
      65             :   std::vector<unsigned char> m_data;
      66             :   const unsigned char *m_unownedData;
      67             :   std::size_t m_unownedSize;
      68             : };
      69             : }  // namespace YAML
      70             : 
      71             : #endif  // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66

Generated by: LCOV version 1.14