Crypto++  5.6.3
Free C++ class library of cryptographic schemes
hex.h
Go to the documentation of this file.
1 // hex.h - written and placed in the public domain by Wei Dai
2 
3 //! \file hex.h
4 //! \brief Classes for HexEncoder and HexDecoder
5 
6 #ifndef CRYPTOPP_HEX_H
7 #define CRYPTOPP_HEX_H
8 
9 #include "cryptlib.h"
10 #include "basecode.h"
11 
12 NAMESPACE_BEGIN(CryptoPP)
13 
14 //! \class HexEncoder
15 //! \brief Converts given data to base 16
16 class CRYPTOPP_DLL HexEncoder : public SimpleProxyFilter
17 {
18 public:
19  //! \brief Construct a HexEncoder
20  //! \param attachment a BufferedTrasformation to attach to this object
21  //! \param uppercase a flag indicating uppercase output
22  //! \param groupSize the size of the output grouping
23  //! \param separator the separator to use between groups
24  //! \param terminator the terminator append after processing
25  HexEncoder(BufferedTransformation *attachment = NULL, bool uppercase = true, int groupSize = 0, const std::string &separator = ":", const std::string &terminator = "")
26  : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
27  {
28  IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), groupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator)));
29  }
30 
31  void IsolatedInitialize(const NameValuePairs &parameters);
32 };
33 
34 //! \class HexDecoder
35 //! \brief Decode base 16 data back to bytes
36 class CRYPTOPP_DLL HexDecoder : public BaseN_Decoder
37 {
38 public:
39  //! \brief Construct a HexDecoder
40  //! \param attachment a BufferedTrasformation to attach to this object
41  HexDecoder(BufferedTransformation *attachment = NULL)
42  : BaseN_Decoder(GetDefaultDecodingLookupArray(), 4, attachment) {}
43 
44  void IsolatedInitialize(const NameValuePairs &parameters);
45 
46 private:
47  static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
48 };
49 
50 NAMESPACE_END
51 
52 #endif
Used to pass byte array input as part of a NameValuePairs object.
Definition: algparam.h:29
Converts given data to base 16.
Definition: hex.h:16
Decode base 16 data back to bytes.
Definition: hex.h:36
Abstract base classes that provide a uniform interface to this library.
Interface for buffered transformations.
Definition: cryptlib.h:1352
HexEncoder(BufferedTransformation *attachment=NULL, bool uppercase=true, int groupSize=0, const std::string &separator=":", const std::string &terminator="")
Construct a HexEncoder.
Definition: hex.h:25
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: basecode.cpp:115
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:554
Proxy filter that doesn't modify the underlying filter's input or output.
Definition: filters.h:893
HexDecoder(BufferedTransformation *attachment=NULL)
Construct a HexDecoder.
Definition: hex.h:41
Filter that breaks input stream into groups of fixed size.
Definition: basecode.h:110
Crypto++ library namespace.
Encoder for bases that are a power of 2.
Definition: basecode.h:18
Base classes for working with encoders and decoders.
Decoder for bases that are a power of 2.
Definition: basecode.h:58
Interface for retrieving values given their names.
Definition: cryptlib.h:277