Botan 1.10.17

hex_filt.h
Go to the documentation of this file.
1 /*
2 * Hex Encoder/Decoder
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_HEX_FILTER_H__
9 #define BOTAN_HEX_FILTER_H__
10
11 #include <botan/filter.h>
12
13 namespace Botan {
14
15 /**
16 * Converts arbitrary binary data to hex strings, optionally with
17 * newlines inserted
18 */
19 class BOTAN_DLL Hex_Encoder : public Filter
20 {
21 public:
22 /**
23 * Whether to use uppercase or lowercase letters for the encoded string.
24 */
25 enum Case { Uppercase, Lowercase };
26
27 std::string name() const { return "Hex_Encoder"; }
28
29 void write(const byte in[], size_t length);
30 void end_msg();
31
32 /**
33 * Create a hex encoder.
34 * @param the_case the case to use in the encoded strings.
35 */
36 Hex_Encoder(Case the_case);
37
38 /**
39 * Create a hex encoder.
40 * @param newlines should newlines be used
41 * @param line_length if newlines are used, how long are lines
42 * @param the_case the case to use in the encoded strings
43 */
44 Hex_Encoder(bool newlines = false,
45 size_t line_length = 72,
46 Case the_case = Uppercase);
47 private:
48 void encode_and_send(const byte[], size_t);
49
50 const Case casing;
51 const size_t line_length;
52 MemoryVector<byte> in, out;
53 size_t position, counter;
54 };
55
56 /**
57 * Converts hex strings to bytes
58 */
59 class BOTAN_DLL Hex_Decoder : public Filter
60 {
61 public:
62 std::string name() const { return "Hex_Decoder"; }
63
64 void write(const byte[], size_t);
65 void end_msg();
66
67 /**
68 * Construct a Hex Decoder using the specified
69 * character checking.
70 * @param checking the checking to use during decoding.
71 */
72 Hex_Decoder(Decoder_Checking checking = NONE);
73 private:
74 const Decoder_Checking checking;
75 MemoryVector<byte> in, out;
76 size_t position;
77 };
78
79 }
80
81 #endif
Botan::Hex_Encoder::Uppercase
Definition: hex_filt.h:25
Botan::Hex_Decoder
Definition: hex_filt.h:59
Botan::Hex_Encoder
Definition: hex_filt.h:19
Botan::Hex_Encoder::Case
Case
Definition: hex_filt.h:25
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Filter
Definition: filter.h:19
Botan
Definition: algo_base.h:14
Botan::MemoryVector< byte >
Botan::NONE
Definition: filter.h:155
Botan::Hex_Decoder::name
std::string name() const
Definition: hex_filt.h:62
Botan::Hex_Encoder::name
std::string name() const
Definition: hex_filt.h:27
Botan::Decoder_Checking
Decoder_Checking
Definition: filter.h:155