Botan 2.19.5 Crypto and TLS for C&

hex.h
Go to the documentation of this file.
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 <string>
13
14 namespace Botan {
15
16/**
17* Perform hex encoding
18* @param output an array of at least input_length*2 bytes
19* @param input is some binary data
20* @param input_length length of input in bytes
21* @param uppercase should output be upper or lower case?
22*/
23 void BOTAN_PUBLIC_API(2,0) hex_encode(char output[],
24 const uint8_t input[],
25 size_t input_length,
26 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[],
36 size_t input_length,
37 bool uppercase = true);
38
39/**
40* Perform hex encoding
41* @param input some input
42* @param uppercase should output be upper or lower case?
43* @return hexadecimal representation of input
44*/
45template<typename Alloc>
46 std::string hex_encode(const std::vector<uint8_t, Alloc>& input,
47 bool uppercase = true)
48 {
49 return hex_encode(input.data(), input.size(), uppercase);
50 }
51
52/**
53* Perform hex decoding
54* @param output an array of at least input_length/2 bytes
55* @param input some hex input
56* @param input_length length of input in bytes
57* @param input_consumed is an output parameter which says how many
58* bytes of input were actually consumed. If less than
59* input_length, then the range input[consumed:length]
60* should be passed in later along with more input.
61* @param ignore_ws ignore whitespace on input; if false, throw an
62 exception if whitespace is encountered
63* @return number of bytes written to output
64*/
65 size_t BOTAN_PUBLIC_API(2,0) hex_decode(uint8_t output[],
66 const char input[],
67 size_t input_length,
68 size_t& input_consumed,
69 bool ignore_ws = true);
70
71/**
72* Perform hex decoding
73* @param output an array of at least input_length/2 bytes
74* @param input some hex input
75* @param input_length length of input in bytes
76* @param ignore_ws ignore whitespace on input; if false, throw an
77 exception if whitespace is encountered
78* @return number of bytes written to output
79*/
80 size_t BOTAN_PUBLIC_API(2,0) hex_decode(uint8_t output[],
81 const char input[],
82 size_t input_length,
83 bool ignore_ws = true);
84
85/**
86* Perform hex decoding
87* @param output an array of at least input_length/2 bytes
88* @param input some hex input
89* @param ignore_ws ignore whitespace on input; if false, throw an
90 exception if whitespace is encountered
91* @return number of bytes written to output
92*/
93 size_t BOTAN_PUBLIC_API(2,0) hex_decode(uint8_t output[],
94 const std::string& input,
95 bool ignore_ws = true);
96
97/**
98* Perform hex decoding
99* @param input some hex input
100* @param input_length the length of input in bytes
101* @param ignore_ws ignore whitespace on input; if false, throw an
102 exception if whitespace is encountered
103* @return decoded hex output
104*/
105 std::vector<uint8_t> BOTAN_PUBLIC_API(2,0)
106 hex_decode(const char input[],
107 size_t input_length,
108 bool ignore_ws = true);
109
110/**
111* Perform hex decoding
112* @param input some hex input
113* @param ignore_ws ignore whitespace on input; if false, throw an
114 exception if whitespace is encountered
115* @return decoded hex output
116*/
117 std::vector<uint8_t> BOTAN_PUBLIC_API(2,0)
118 hex_decode(const std::string& input,
119 bool ignore_ws = true);
120
121
122/**
123* Perform hex decoding
124* @param input some hex input
125* @param input_length the length of input in bytes
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(2,0)
131 hex_decode_locked(const char input[],
132 size_t input_length,
133 bool ignore_ws = true);
134
135/**
136* Perform hex decoding
137* @param input some hex input
138* @param ignore_ws ignore whitespace on input; if false, throw an
139 exception if whitespace is encountered
140* @return decoded hex output
141*/
142 secure_vector<uint8_t> BOTAN_PUBLIC_API(2,0)
143 hex_decode_locked(const std::string& input,
144 bool ignore_ws = true);
145
146}
147
148#endif
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan
Definition: alg_id.cpp:13
Botan::hex_decode_locked
secure_vector< uint8_t > hex_decode_locked(const char input[], size_t input_length, bool ignore_ws)
Definition: hex.cpp:168
Botan::hex_encode
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:31
Botan::hex_decode
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition: hex.cpp:89
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
std
Definition: bigint.h:1155