00001 // base32.h - written and placed in the public domain by Wei Dai 00002 00003 //! \file 00004 //! \brief Classes for Base32Encoder and Base32Decoder 00005 00006 #ifndef CRYPTOPP_BASE32_H 00007 #define CRYPTOPP_BASE32_H 00008 00009 #include "cryptlib.h" 00010 #include "basecode.h" 00011 00012 NAMESPACE_BEGIN(CryptoPP) 00013 00014 //! \class Base32Encoder 00015 //! \brief Base32 encodes data 00016 //! \details Converts data to base32. The default code is based on draft-ietf-idn-dude-02.txt. 00017 //! \details To specify alternative alpahabet or code, call Initialize() with EncodingLookupArray parameter. 00018 class Base32Encoder : public SimpleProxyFilter 00019 { 00020 public: 00021 //! \brief Construct a Base32Encoder 00022 //! \param attachment a BufferedTrasformation to attach to this object 00023 //! \param uppercase a flag indicating uppercase output 00024 //! \param groupSize the size of the grouping 00025 //! \param separator the separator to use between groups 00026 //! \param terminator the terminator appeand after processing 00027 //! \details Base32Encoder() constructs a default encoder. The constructor lacks fields for padding and 00028 //! line breaks. You must use IsolatedInitialize() to change the default padding character or suppress it. 00029 //! \sa IsolatedInitialize() for an example of modifying a Base32Encoder after construction. 00030 Base32Encoder(BufferedTransformation *attachment = NULL, bool uppercase = true, int groupSize = 0, const std::string &separator = ":", const std::string &terminator = "") 00031 : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment) 00032 { 00033 IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), groupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator))); 00034 } 00035 00036 //! \brief Initialize or reinitialize this object, without signal propagation 00037 //! \param parameters a set of NameValuePairs used to initialize this object 00038 //! \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable 00039 //! number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached 00040 //! transformations. If initialization should be propagated, then use the Initialize() function. 00041 //! \details The following code modifies the padding and line break parameters for an encoder: 00042 //! <pre> 00043 //! Base32Encoder encoder; 00044 //! AlgorithmParameters params = MakeParameters(Pad(), false)(InsertLineBreaks(), false); 00045 //! encoder.IsolatedInitialize(params); 00046 //! </pre> 00047 void IsolatedInitialize(const NameValuePairs ¶meters); 00048 }; 00049 00050 //! \class Base32Decoder 00051 //! \brief Base32 decodes data 00052 //! \details Decode base32 data. The default code is based on draft-ietf-idn-dude-02.txt 00053 //! \details To specify alternative alpahabet or code, call Initialize() with EncodingLookupArray parameter. 00054 class Base32Decoder : public BaseN_Decoder 00055 { 00056 public: 00057 //! \brief Construct a Base32Decoder 00058 //! \param attachment a BufferedTrasformation to attach to this object 00059 Base32Decoder(BufferedTransformation *attachment = NULL) 00060 : BaseN_Decoder(GetDefaultDecodingLookupArray(), 5, attachment) {} 00061 00062 void IsolatedInitialize(const NameValuePairs ¶meters); 00063 00064 private: 00065 static const int * CRYPTOPP_API GetDefaultDecodingLookupArray(); 00066 }; 00067 00068 NAMESPACE_END 00069 00070 #endif