Coverage Report

Created: 2026-03-25 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libtorrent/include/libtorrent/hex.hpp
Line
Count
Source
1
/*
2
3
Copyright (c) 2004, 2009, 2013, 2015-2020, Arvid Norberg
4
Copyright (c) 2020, Alden Torres
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions
9
are met:
10
11
    * Redistributions of source code must retain the above copyright
12
      notice, this list of conditions and the following disclaimer.
13
    * Redistributions in binary form must reproduce the above copyright
14
      notice, this list of conditions and the following disclaimer in
15
      the documentation and/or other materials provided with the distribution.
16
    * Neither the name of the author nor the names of its
17
      contributors may be used to endorse or promote products derived
18
      from this software without specific prior written permission.
19
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
POSSIBILITY OF SUCH DAMAGE.
31
32
*/
33
34
#ifndef TORRENT_HEX_HPP_INCLUDED
35
#define TORRENT_HEX_HPP_INCLUDED
36
37
#include "libtorrent/config.hpp"
38
#include "libtorrent/error_code.hpp"
39
#include "libtorrent/span.hpp"
40
41
#include <string>
42
43
namespace libtorrent {
44
45
namespace aux {
46
47
  TORRENT_EXTRA_EXPORT int hex_to_int(char in);
48
  TORRENT_EXTRA_EXPORT bool is_hex(span<char const> in);
49
50
#if TORRENT_ABI_VERSION == 1
51
#define TORRENT_CONDITIONAL_EXPORT TORRENT_EXPORT
52
#else
53
#define TORRENT_CONDITIONAL_EXPORT TORRENT_EXTRA_EXPORT
54
#endif
55
56
  // The overload taking a ``std::string`` converts (binary) the string ``s``
57
  // to hexadecimal representation and returns it.
58
  // The overload taking a ``char const*`` and a length converts the binary
59
  // buffer [``in``, ``in`` + len) to hexadecimal and prints it to the buffer
60
  // ``out``. The caller is responsible for making sure the buffer pointed to
61
  // by ``out`` is large enough, i.e. has at least len * 2 bytes of space.
62
  TORRENT_CONDITIONAL_EXPORT std::string to_hex(span<char const> s);
63
  TORRENT_CONDITIONAL_EXPORT void to_hex(span<char const> in, char* out);
64
  TORRENT_CONDITIONAL_EXPORT void to_hex(char const* in, int len, char* out);
65
66
  // converts the buffer [``in``, ``in`` + len) from hexadecimal to
67
  // binary. The binary output is written to the buffer pointed to
68
  // by ``out``. The caller is responsible for making sure the buffer
69
  // at ``out`` has enough space for the result to be written to, i.e.
70
  // (len + 1) / 2 bytes.
71
  TORRENT_CONDITIONAL_EXPORT bool from_hex(span<char const> in, char* out);
72
73
#undef TORRENT_CONDITIONAL_EXPORT
74
75
} // namespace aux
76
77
#if TORRENT_ABI_VERSION == 1
78
79
#include "libtorrent/aux_/disable_deprecation_warnings_push.hpp"
80
81
  // deprecated in 1.2
82
  TORRENT_DEPRECATED
83
  inline void to_hex(char const* in, int len, char* out)
84
0
  { aux::to_hex({in, len}, out); }
85
  TORRENT_DEPRECATED
86
  inline std::string to_hex(std::string const& s)
87
0
  { return aux::to_hex(s); }
88
  TORRENT_DEPRECATED
89
  inline bool from_hex(char const *in, int len, char* out)
90
0
  { return aux::from_hex({in, len}, out); }
91
92
#include "libtorrent/aux_/disable_warnings_pop.hpp"
93
94
#endif
95
} // namespace libtorrent
96
97
#endif // TORRENT_HEX_HPP_INCLUDED