Crypto++  5.6.3
Free C++ class library of cryptographic schemes
base32.h
Go to the documentation of this file.
1 // base32.h - written and placed in the public domain by Wei Dai
2 
3 //! \file
4 //! \brief Classes for Base32Encoder and Base32Decoder
5 
6 #ifndef CRYPTOPP_BASE32_H
7 #define CRYPTOPP_BASE32_H
8 
9 #include "cryptlib.h"
10 #include "basecode.h"
11 
12 NAMESPACE_BEGIN(CryptoPP)
13 
14 //! \class Base32Encoder
15 //! \brief Base32 encodes data
16 //! \details Converts data to base32. The default code is based on draft-ietf-idn-dude-02.txt.
17 //! \details To specify alternative alpahabet or code, call Initialize() with EncodingLookupArray parameter.
19 {
20 public:
21  //! \brief Construct a Base32Encoder
22  //! \param attachment a BufferedTrasformation to attach to this object
23  //! \param uppercase a flag indicating uppercase output
24  //! \param groupSize the size of the grouping
25  //! \param separator the separator to use between groups
26  //! \param terminator the terminator appeand after processing
27  //! \details Base32Encoder() constructs a default encoder. The constructor lacks fields for padding and
28  //! line breaks. You must use IsolatedInitialize() to change the default padding character or suppress it.
29  //! \sa IsolatedInitialize() for an example of modifying a Base32Encoder after construction.
30  Base32Encoder(BufferedTransformation *attachment = NULL, bool uppercase = true, int groupSize = 0, const std::string &separator = ":", const std::string &terminator = "")
31  : SimpleProxyFilter(new BaseN_Encoder(new Grouper), attachment)
32  {
33  IsolatedInitialize(MakeParameters(Name::Uppercase(), uppercase)(Name::GroupSize(), groupSize)(Name::Separator(), ConstByteArrayParameter(separator))(Name::Terminator(), ConstByteArrayParameter(terminator)));
34  }
35 
36  //! \brief Initialize or reinitialize this object, without signal propagation
37  //! \param parameters a set of NameValuePairs used to initialize this object
38  //! \details IsolatedInitialize() is used to initialize or reinitialize an object using a variable
39  //! number of arbitrarily typed arguments. IsolatedInitialize() does not call Initialize() on attached
40  //! transformations. If initialization should be propagated, then use the Initialize() function.
41  //! \details The following code modifies the padding and line break parameters for an encoder:
42  //! <pre>
43  //! Base32Encoder encoder;
44  //! AlgorithmParameters params = MakeParameters(Pad(), false)(InsertLineBreaks(), false);
45  //! encoder.IsolatedInitialize(params);
46  //! </pre>
47  void IsolatedInitialize(const NameValuePairs &parameters);
48 };
49 
50 //! \class Base32Decoder
51 //! \brief Base32 decodes data
52 //! \details Decode base32 data. The default code is based on draft-ietf-idn-dude-02.txt
53 //! \details To specify alternative alpahabet or code, call Initialize() with EncodingLookupArray parameter.
55 {
56 public:
57  //! \brief Construct a Base32Decoder
58  //! \param attachment a BufferedTrasformation to attach to this object
60  : BaseN_Decoder(GetDefaultDecodingLookupArray(), 5, attachment) {}
61 
62  void IsolatedInitialize(const NameValuePairs &parameters);
63 
64 private:
65  static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
66 };
67 
68 NAMESPACE_END
69 
70 #endif
used to pass byte array input as part of a NameValuePairs object
Definition: algparam.h:30
Base32 encodes data.
Definition: base32.h:18
Abstract base classes that provide a uniform interface to this library.
Interface for buffered transformations.
Definition: cryptlib.h:1247
Base32Encoder(BufferedTransformation *attachment=NULL, bool uppercase=true, int groupSize=0, const std::string &separator=":", const std::string &terminator="")
Construct a Base32Encoder.
Definition: base32.h:30
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:487
simple proxy filter that doesn&#39;t modify the underlying filter&#39;s input or output
Definition: filters.h:694
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: base32.cpp:19
Base32Decoder(BufferedTransformation *attachment=NULL)
Construct a Base32Decoder.
Definition: base32.h:59
Filter that breaks input stream into groups of fixed size.
Definition: basecode.h:110
Base32 decodes data.
Definition: base32.h:54
Crypto++ library namespace.
Encoder for bases that are a power of 2.
Definition: basecode.h:18
Base classes for working with encoders and decoders.
Decoder for bases that are a power of 2.
Definition: basecode.h:58
Interface for retrieving values given their names.
Definition: cryptlib.h:261