Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.5 KiB

  1. #ifndef CRYPTOPP_BASECODE_H
  2. #define CRYPTOPP_BASECODE_H
  3. #include "filters.h"
  4. #include "algparam.h"
  5. #include "argnames.h"
  6. NAMESPACE_BEGIN(CryptoPP)
  7. //! base n encoder, where n is a power of 2
  8. class CRYPTOPP_DLL BaseN_Encoder : public Unflushable<Filter>
  9. {
  10. public:
  11. BaseN_Encoder(BufferedTransformation *attachment=NULL)
  12. {Detach(attachment);}
  13. BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULL, int padding=-1)
  14. {
  15. Detach(attachment);
  16. IsolatedInitialize(MakeParameters(Name::EncodingLookupArray(), alphabet)
  17. (Name::Log2Base(), log2base)
  18. (Name::Pad(), padding != -1)
  19. (Name::PaddingByte(), byte(padding)));
  20. }
  21. void IsolatedInitialize(const NameValuePairs &parameters);
  22. size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
  23. private:
  24. const byte *m_alphabet;
  25. int m_padding, m_bitsPerChar, m_outputBlockSize;
  26. int m_bytePos, m_bitPos;
  27. SecByteBlock m_outBuf;
  28. };
  29. //! base n decoder, where n is a power of 2
  30. class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
  31. {
  32. public:
  33. BaseN_Decoder(BufferedTransformation *attachment=NULL)
  34. {Detach(attachment);}
  35. BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULL)
  36. {
  37. Detach(attachment);
  38. IsolatedInitialize(MakeParameters(Name::DecodingLookupArray(), lookup)(Name::Log2Base(), log2base));
  39. }
  40. void IsolatedInitialize(const NameValuePairs &parameters);
  41. size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
  42. static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
  43. private:
  44. const int *m_lookup;
  45. int m_padding, m_bitsPerChar, m_outputBlockSize;
  46. int m_bytePos, m_bitPos;
  47. SecByteBlock m_outBuf;
  48. };
  49. //! filter that breaks input stream into groups of fixed size
  50. class CRYPTOPP_DLL Grouper : public Bufferless<Filter>
  51. {
  52. public:
  53. Grouper(BufferedTransformation *attachment=NULL)
  54. {Detach(attachment);}
  55. Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULL)
  56. {
  57. Detach(attachment);
  58. IsolatedInitialize(MakeParameters(Name::GroupSize(), groupSize)
  59. (Name::Separator(), ConstByteArrayParameter(separator))
  60. (Name::Terminator(), ConstByteArrayParameter(terminator)));
  61. }
  62. void IsolatedInitialize(const NameValuePairs &parameters);
  63. size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
  64. private:
  65. SecByteBlock m_separator, m_terminator;
  66. size_t m_groupSize, m_counter;
  67. };
  68. NAMESPACE_END
  69. #endif