Botan  2.4.0
Crypto and TLS for C++11
hex_filt.h
Go to the documentation of this file.
1 /*
2 * Hex Encoder/Decoder
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
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_PUBLIC_API(2,0) Hex_Encoder final : 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 override { return "Hex_Encoder"; }
28 
29  void write(const uint8_t in[], size_t length) override;
30  void end_msg() override;
31 
32  /**
33  * Create a hex encoder.
34  * @param the_case the case to use in the encoded strings.
35  */
36  explicit 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 uint8_t[], size_t);
49 
50  const Case m_casing;
51  const size_t m_line_length;
52  std::vector<uint8_t> m_in, m_out;
53  size_t m_position, m_counter;
54  };
55 
56 /**
57 * Converts hex strings to bytes
58 */
59 class BOTAN_PUBLIC_API(2,0) Hex_Decoder final : public Filter
60  {
61  public:
62  std::string name() const override { return "Hex_Decoder"; }
63 
64  void write(const uint8_t[], size_t) override;
65  void end_msg() override;
66 
67  /**
68  * Construct a Hex Decoder using the specified
69  * character checking.
70  * @param checking the checking to use during decoding.
71  */
72  explicit Hex_Decoder(Decoder_Checking checking = NONE);
73  private:
74  const Decoder_Checking m_checking;
75  std::vector<uint8_t> m_in, m_out;
76  size_t m_position;
77  };
78 
79 }
80 
81 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
std::string name() const override
Definition: hex_filt.h:62
Definition: alg_id.cpp:13
std::string name() const override
Definition: hex_filt.h:27
Decoder_Checking
Definition: filter.h:179