Team Fortress 2 Source Code as on 22/4/2020
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.

70 lines
3.1 KiB

  1. // base32.h - written and placed in the public domain by Wei Dai
  2. //! \file
  3. //! \brief Classes for Base32Encoder and Base32Decoder
  4. #ifndef CRYPTOPP_BASE32_H
  5. #define CRYPTOPP_BASE32_H
  6. #include "cryptlib.h"
  7. #include "basecode.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. //! \class Base32Encoder
  10. //! \brief Base32 encodes data
  11. //! \details Converts data to base32. The default code is based on draft-ietf-idn-dude-02.txt.
  12. //! \details To specify alternative alpahabet or code, call Initialize() with EncodingLookupArray parameter.
  13. class Base32Encoder : public SimpleProxyFilter
  14. {
  15. public:
  16. //! \brief Construct a Base32Encoder
  17. //! \param attachment a BufferedTrasformation to attach to this object
  18. //! \param uppercase a flag indicating uppercase output
  19. //! \param groupSize the size of the grouping
  20. //! \param separator the separator to use between groups
  21. //! \param terminator the terminator appeand after processing
  22. //! \details Base32Encoder() constructs a default encoder. The constructor lacks fields for padding and
  23. //! line breaks. You must use IsolatedInitialize() to change the default padding character or suppress it.
  24. //! \sa IsolatedInitialize() for an example of modifying a Base32Encoder after construction.
  25. Base32Encoder(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. //! \brief Initialize or reinitialize this object, without signal propagation
  31. //! \param parameters a set of NameValuePairs used to initialize this object
  32. //! \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
  33. //! number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
  34. //! transformations. If initialization should be propagated, then use the Initialize() function.
  35. //! \details The following code modifies the padding and line break parameters for an encoder:
  36. //! <pre>
  37. //! Base32Encoder encoder;
  38. //! AlgorithmParameters params = MakeParameters(Pad(), false)(InsertLineBreaks(), false);
  39. //! encoder.IsolatedInitialize(params);
  40. //! </pre>
  41. void IsolatedInitialize(const NameValuePairs &parameters);
  42. };
  43. //! \class Base32Decoder
  44. //! \brief Base32 decodes data
  45. //! \details Decode base32 data. The default code is based on draft-ietf-idn-dude-02.txt
  46. //! \details To specify alternative alpahabet or code, call Initialize() with EncodingLookupArray parameter.
  47. class Base32Decoder : public BaseN_Decoder
  48. {
  49. public:
  50. //! \brief Construct a Base32Decoder
  51. //! \param attachment a BufferedTrasformation to attach to this object
  52. Base32Decoder(BufferedTransformation *attachment = NULL)
  53. : BaseN_Decoder(GetDefaultDecodingLookupArray(), 5, attachment) {}
  54. void IsolatedInitialize(const NameValuePairs &parameters);
  55. private:
  56. static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
  57. };
  58. NAMESPACE_END
  59. #endif