hex.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // hex.h - originally written and placed in the public domain by Wei Dai
  2. /// \file hex.h
  3. /// \brief Classes for HexEncoder and HexDecoder
  4. #ifndef CRYPTOPP_HEX_H
  5. #define CRYPTOPP_HEX_H
  6. #include "cryptlib.h"
  7. #include "basecode.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. /// \brief Converts given data to base 16
  10. class CRYPTOPP_DLL HexEncoder : public SimpleProxyFilter
  11. {
  12. public:
  13. /// \brief Construct a HexEncoder
  14. /// \param attachment a BufferedTrasformation to attach to this object
  15. /// \param uppercase a flag indicating uppercase output
  16. /// \param groupSize the size of the output grouping
  17. /// \param separator the separator to use between groups
  18. /// \param terminator the terminator append after processing
  19. HexEncoder(BufferedTransformation *attachment = NULLPTR, bool uppercase = true, int groupSize = 0, const std::string &separator = ":", const std::string &terminator = "")
  20. : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
  21. {
  22. IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), groupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator)));
  23. }
  24. void IsolatedInitialize(const NameValuePairs &parameters);
  25. };
  26. /// \brief Decode base 16 data back to bytes
  27. class CRYPTOPP_DLL HexDecoder : public BaseN_Decoder
  28. {
  29. public:
  30. /// \brief Construct a HexDecoder
  31. /// \param attachment a BufferedTrasformation to attach to this object
  32. HexDecoder(BufferedTransformation *attachment = NULLPTR)
  33. : BaseN_Decoder(GetDefaultDecodingLookupArray(), 4, attachment) {}
  34. void IsolatedInitialize(const NameValuePairs &parameters);
  35. private:
  36. static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
  37. };
  38. NAMESPACE_END
  39. #endif