Coverage Report

Created: 2023-06-07 07:00

/src/botan/build/include/botan/hex.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Hex Encoding and Decoding
3
* (C) 2010 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_HEX_CODEC_H_
9
#define BOTAN_HEX_CODEC_H_
10
11
#include <botan/secmem.h>
12
#include <span>
13
#include <string>
14
#include <string_view>
15
16
namespace Botan {
17
18
/**
19
* Perform hex encoding
20
* @param output an array of at least input_length*2 bytes
21
* @param input is some binary data
22
* @param input_length length of input in bytes
23
* @param uppercase should output be upper or lower case?
24
*/
25
void BOTAN_PUBLIC_API(2, 0)
26
   hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase = true);
27
28
/**
29
* Perform hex encoding
30
* @param input some input
31
* @param input_length length of input in bytes
32
* @param uppercase should output be upper or lower case?
33
* @return hexadecimal representation of input
34
*/
35
std::string BOTAN_PUBLIC_API(2, 0) hex_encode(const uint8_t input[], size_t input_length, bool uppercase = true);
36
37
/**
38
* Perform hex encoding
39
* @param input some input
40
* @param uppercase should output be upper or lower case?
41
* @return hexadecimal representation of input
42
*/
43
0
inline std::string hex_encode(std::span<const uint8_t> input, bool uppercase = true) {
44
0
   return hex_encode(input.data(), input.size(), uppercase);
45
0
}
46
47
/**
48
* Perform hex decoding
49
* @param output an array of at least input_length/2 bytes
50
* @param input some hex input
51
* @param input_length length of input in bytes
52
* @param input_consumed is an output parameter which says how many
53
*        bytes of input were actually consumed. If less than
54
*        input_length, then the range input[consumed:length]
55
*        should be passed in later along with more input.
56
* @param ignore_ws ignore whitespace on input; if false, throw an
57
                   exception if whitespace is encountered
58
* @return number of bytes written to output
59
*/
60
size_t BOTAN_PUBLIC_API(2, 0)
61
   hex_decode(uint8_t output[], const char input[], size_t input_length, size_t& input_consumed, bool ignore_ws = true);
62
63
/**
64
* Perform hex decoding
65
* @param output an array of at least input_length/2 bytes
66
* @param input some hex input
67
* @param input_length length of input in bytes
68
* @param ignore_ws ignore whitespace on input; if false, throw an
69
                   exception if whitespace is encountered
70
* @return number of bytes written to output
71
*/
72
size_t BOTAN_PUBLIC_API(2, 0)
73
   hex_decode(uint8_t output[], const char input[], size_t input_length, bool ignore_ws = true);
74
75
/**
76
* Perform hex decoding
77
* @param output an array of at least input_length/2 bytes
78
* @param input some hex input
79
* @param ignore_ws ignore whitespace on input; if false, throw an
80
                   exception if whitespace is encountered
81
* @return number of bytes written to output
82
*/
83
size_t BOTAN_PUBLIC_API(3, 0) hex_decode(uint8_t output[], std::string_view input, bool ignore_ws = true);
84
85
/**
86
* Perform hex decoding
87
* @param output a contiguous byte buffer of at least input_length/2 bytes
88
* @param input some hex input
89
* @return number of bytes written to output
90
*/
91
size_t BOTAN_PUBLIC_API(3, 0) hex_decode(std::span<uint8_t> output, std::string_view input, bool ignore_ws = true);
92
93
/**
94
* Perform hex decoding
95
* @param input some hex input
96
* @param input_length the length of input in bytes
97
* @param ignore_ws ignore whitespace on input; if false, throw an
98
                   exception if whitespace is encountered
99
* @return decoded hex output
100
*/
101
std::vector<uint8_t> BOTAN_PUBLIC_API(2, 0) hex_decode(const char input[], size_t input_length, bool ignore_ws = true);
102
103
/**
104
* Perform hex decoding
105
* @param input some hex input
106
* @param ignore_ws ignore whitespace on input; if false, throw an
107
                   exception if whitespace is encountered
108
* @return decoded hex output
109
*/
110
std::vector<uint8_t> BOTAN_PUBLIC_API(3, 0) hex_decode(std::string_view input, bool ignore_ws = true);
111
112
/**
113
* Perform hex decoding
114
* @param input some hex input
115
* @param input_length the length of input in bytes
116
* @param ignore_ws ignore whitespace on input; if false, throw an
117
                   exception if whitespace is encountered
118
* @return decoded hex output
119
*/
120
secure_vector<uint8_t> BOTAN_PUBLIC_API(2, 0)
121
   hex_decode_locked(const char input[], size_t input_length, bool ignore_ws = true);
122
123
/**
124
* Perform hex decoding
125
* @param input some hex input
126
* @param ignore_ws ignore whitespace on input; if false, throw an
127
                   exception if whitespace is encountered
128
* @return decoded hex output
129
*/
130
secure_vector<uint8_t> BOTAN_PUBLIC_API(3, 0) hex_decode_locked(std::string_view input, bool ignore_ws = true);
131
132
}  // namespace Botan
133
134
#endif