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 ¶meters); |
---|
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 ¶meters); |
---|
45 | |
---|
46 | private: |
---|
47 | static const int * CRYPTOPP_API GetDefaultDecodingLookupArray(); |
---|
48 | }; |
---|
49 | |
---|
50 | NAMESPACE_END |
---|
51 | |
---|
52 | #endif |
---|