LCOV - code coverage report
Current view: top level - foo/src - base64.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 12 12 100.0 %
Date: 2025-12-18 10:07:43 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2025 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  This program is free software: you can redistribute it and/or modify
       5             :  *  it under the terms of the GNU General Public License as published by
       6             :  *  the Free Software Foundation, either version 3 of the License, or
       7             :  *  (at your option) any later version.
       8             :  *
       9             :  *  This program is distributed in the hope that it will be useful,
      10             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12             :  *  GNU General Public License for more details.
      13             :  *
      14             :  *  You should have received a copy of the GNU General Public License
      15             :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "base64.h"
      19             : #include "connectivity/sip_utils.h"
      20             : 
      21             : #include <simdutf.h>
      22             : 
      23             : namespace jami {
      24             : namespace base64 {
      25             : 
      26             : std::string
      27        5366 : encode(std::string_view str)
      28             : {
      29        5366 :     std::string buffer(simdutf::base64_length_from_binary(str.size()), '\0');
      30        5366 :     simdutf::binary_to_base64((const char*) str.data(), str.size(), buffer.data());
      31        5366 :     return buffer;
      32             : }
      33             : 
      34             : std::vector<unsigned char>
      35       25831 : decode(std::string_view str)
      36             : {
      37       25831 :     std::vector<unsigned char> buffer(simdutf::maximal_binary_length_from_base64(str.data(), str.size()));
      38       25824 :     const simdutf::result r = simdutf::base64_to_binary(str.data(), str.size(), (char*) buffer.data());
      39       25830 :     if (r.error)
      40           1 :         throw base64_exception();
      41       25829 :     buffer.resize(r.count); // resize the buffer according to actual number of bytes
      42       51658 :     return buffer;
      43           1 : }
      44             : 
      45             : } // namespace base64
      46             : } // namespace jami

Generated by: LCOV version 1.14