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
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 //! Converts given data to base 16
15 class CRYPTOPP_DLL HexEncoder : public SimpleProxyFilter
16 {
17 public:
18  HexEncoder(BufferedTransformation *attachment = NULL, bool uppercase = true, int outputGroupSize = 0, const std::string &separator = ":", const std::string &terminator = "")
19  : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
20  {
21  IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), outputGroupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator)));
22  }
23 
24  void IsolatedInitialize(const NameValuePairs &parameters);
25 };
26 
27 //! Decode base 16 data back to bytes
28 class CRYPTOPP_DLL HexDecoder : public BaseN_Decoder
29 {
30 public:
31  HexDecoder(BufferedTransformation *attachment = NULL)
32  : BaseN_Decoder(GetDefaultDecodingLookupArray(), 4, attachment) {}
33 
34  void IsolatedInitialize(const NameValuePairs &parameters);
35 
36 private:
37  static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
38 };
39 
40 NAMESPACE_END
41 
42 #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:15
Decode base 16 data back to bytes.
Definition: hex.h:28
Abstract base classes that provide a uniform interface to this library.
Interface for buffered transformations.
Definition: cryptlib.h:1342
BaseN_Decoder(BufferedTransformation *attachment=NULL)
Construct a BaseN_Decoder.
Definition: basecode.h:65
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:894
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