Security Scol plugin
basecode.h
Go to the documentation of this file.
1// basecode.h - originally written and placed in the public domain by Wei Dai
2
5
6#ifndef CRYPTOPP_BASECODE_H
7#define CRYPTOPP_BASECODE_H
8
9#include "cryptlib.h"
10#include "filters.h"
11#include "algparam.h"
12#include "argnames.h"
13
14NAMESPACE_BEGIN(CryptoPP)
15
16
17class CRYPTOPP_DLL BaseN_Encoder : public Unflushable<Filter>
18{
19public:
23 : m_alphabet(NULLPTR), m_padding(0), m_bitsPerChar(0)
24 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
25 {Detach(attachment);}
26
34 BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULLPTR, int padding=-1)
35 : m_alphabet(NULLPTR), m_padding(0), m_bitsPerChar(0)
36 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
37 {
38 Detach(attachment);
41 (Name::EncodingLookupArray(), alphabet)
42 (Name::Log2Base(), log2base)
43 (Name::Pad(), padding != -1)
44 (Name::PaddingByte(), byte(padding)));
45 }
46
47 void IsolatedInitialize(const NameValuePairs &parameters);
48 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
49
50private:
51 const byte *m_alphabet;
52 int m_padding, m_bitsPerChar, m_outputBlockSize;
53 int m_bytePos, m_bitPos;
54 SecByteBlock m_outBuf;
55};
56
58class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
59{
60public:
66 : m_lookup(NULLPTR), m_bitsPerChar(0)
67 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
68 {Detach(attachment);}
69
78 BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULLPTR)
79 : m_lookup(NULLPTR), m_bitsPerChar(0)
80 , m_outputBlockSize(0), m_bytePos(0), m_bitPos(0)
81 {
82 Detach(attachment);
85 (Name::DecodingLookupArray(), lookup)
86 (Name::Log2Base(), log2base));
87 }
88
89 void IsolatedInitialize(const NameValuePairs &parameters);
90 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
91
102 static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
103
104private:
105 const int *m_lookup;
106 int m_bitsPerChar, m_outputBlockSize;
107 int m_bytePos, m_bitPos;
108 SecByteBlock m_outBuf;
109};
110
112class CRYPTOPP_DLL Grouper : public Bufferless<Filter>
113{
114public:
117 Grouper(BufferedTransformation *attachment=NULLPTR)
118 : m_groupSize(0), m_counter(0) {Detach(attachment);}
119
125 Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULLPTR)
126 : m_groupSize(0), m_counter(0)
127 {
128 Detach(attachment);
131 (Name::GroupSize(), groupSize)
132 (Name::Separator(), ConstByteArrayParameter(separator))
133 (Name::Terminator(), ConstByteArrayParameter(terminator)));
134 }
135
136 void IsolatedInitialize(const NameValuePairs &parameters);
137 size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
138
139private:
140 SecByteBlock m_separator, m_terminator;
141 size_t m_groupSize, m_counter;
142};
143
144NAMESPACE_END
145
146#endif
Classes for working with NameValuePairs.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition algparam.h:508
Standard names for retrieving values by name when working with NameValuePairs.
Decoder for bases that are a power of 2.
Definition basecode.h:59
BaseN_Decoder(BufferedTransformation *attachment=NULLPTR)
Construct a BaseN_Decoder.
Definition basecode.h:65
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition basecode.cpp:115
BaseN_Decoder(const int *lookup, int log2base, BufferedTransformation *attachment=NULLPTR)
Construct a BaseN_Decoder.
Definition basecode.h:78
Encoder for bases that are a power of 2.
Definition basecode.h:18
BaseN_Encoder(BufferedTransformation *attachment=NULLPTR)
Construct a BaseN_Encoder.
Definition basecode.h:22
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition basecode.cpp:22
BaseN_Encoder(const byte *alphabet, int log2base, BufferedTransformation *attachment=NULLPTR, int padding=-1)
Construct a BaseN_Encoder.
Definition basecode.h:34
Interface for buffered transformations.
Definition cryptlib.h:1652
Base class for bufferless filters.
Definition simple.h:120
Used to pass byte array input as part of a NameValuePairs object.
Definition algparam.h:25
Implementation of BufferedTransformation's attachment interface.
Definition filters.h:36
Filter that breaks input stream into groups of fixed size.
Definition basecode.h:113
Grouper(BufferedTransformation *attachment=NULLPTR)
Construct a Grouper.
Definition basecode.h:117
Grouper(int groupSize, const std::string &separator, const std::string &terminator, BufferedTransformation *attachment=NULLPTR)
Construct a Grouper.
Definition basecode.h:125
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition basecode.cpp:199
Interface for retrieving values given their names.
Definition cryptlib.h:322
Base class for unflushable filters.
Definition simple.h:134
Abstract base classes that provide a uniform interface to this library.
Implementation of BufferedTransformation's attachment interface.