Add VectorSource (GH #730)
parent
7c5da3e1ca
commit
20f82c067e
|
|
@ -44,8 +44,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Construct a ConstByteArrayParameter
|
/// \brief Construct a ConstByteArrayParameter
|
||||||
/// \tparam T a std::basic_string<char> class
|
/// \tparam T a std::basic_string<char> or std::vector<byte> class
|
||||||
/// \param string a std::basic_string<char> class
|
/// \param string a std::basic_string<char> or std::vector<byte> object
|
||||||
/// \param deepCopy flag indicating whether the data should be copied
|
/// \param deepCopy flag indicating whether the data should be copied
|
||||||
/// \details The deepCopy option is used when the NameValuePairs object can't
|
/// \details The deepCopy option is used when the NameValuePairs object can't
|
||||||
/// keep a copy of the data available
|
/// keep a copy of the data available
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
<dt>Compression<dd>
|
<dt>Compression<dd>
|
||||||
Deflator, Inflator, Gzip, Gunzip, ZlibCompressor, ZlibDecompressor
|
Deflator, Inflator, Gzip, Gunzip, ZlibCompressor, ZlibDecompressor
|
||||||
<dt>Input Source Classes<dd>
|
<dt>Input Source Classes<dd>
|
||||||
StringSource, ArraySource, FileSource, RandomNumberSource
|
StringSource, ArraySource, VectorSource, FileSource, RandomNumberSource
|
||||||
<dt>Output Sink Classes<dd>
|
<dt>Output Sink Classes<dd>
|
||||||
StringSinkTemplate, StringSink, VectorSink, ArraySink, FileSink, RandomNumberSink
|
StringSinkTemplate, StringSink, VectorSink, ArraySink, FileSink, RandomNumberSink
|
||||||
<dt>Filter Wrappers<dd>
|
<dt>Filter Wrappers<dd>
|
||||||
|
|
|
||||||
20
filters.h
20
filters.h
|
|
@ -1067,7 +1067,7 @@ public:
|
||||||
virtual ~StringSinkTemplate() {}
|
virtual ~StringSinkTemplate() {}
|
||||||
|
|
||||||
/// \brief Construct a StringSinkTemplate
|
/// \brief Construct a StringSinkTemplate
|
||||||
/// \param output std::basic_string<char> type
|
/// \param output std::basic_string<char> or std::vector<byte> type
|
||||||
StringSinkTemplate(T &output)
|
StringSinkTemplate(T &output)
|
||||||
: m_output(&output) {CRYPTOPP_ASSERT(sizeof(value_type)==1);}
|
: m_output(&output) {CRYPTOPP_ASSERT(sizeof(value_type)==1);}
|
||||||
|
|
||||||
|
|
@ -1426,6 +1426,24 @@ public:
|
||||||
/// \since Crypto++ 5.6.0
|
/// \since Crypto++ 5.6.0
|
||||||
DOCUMENTED_TYPEDEF(StringSource, ArraySource)
|
DOCUMENTED_TYPEDEF(StringSource, ArraySource)
|
||||||
|
|
||||||
|
/// \brief std::vector-based implementation of the Source interface
|
||||||
|
/// \since Crypto++ 8.0
|
||||||
|
class CRYPTOPP_DLL VectorSource : public SourceTemplate<StringStore>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// \brief Construct a VectorSource
|
||||||
|
/// \param attachment an optional attached transformation
|
||||||
|
VectorSource(BufferedTransformation *attachment = NULLPTR)
|
||||||
|
: SourceTemplate<StringStore>(attachment) {}
|
||||||
|
|
||||||
|
/// \brief Construct a VectorSource
|
||||||
|
/// \param vec vector of bytes
|
||||||
|
/// \param pumpAll flag indicating if source data should be pumped to its attached transformation
|
||||||
|
/// \param attachment an optional attached transformation
|
||||||
|
VectorSource(const std::vector<byte> &vec, bool pumpAll, BufferedTransformation *attachment = NULLPTR)
|
||||||
|
: SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(vec)));}
|
||||||
|
};
|
||||||
|
|
||||||
/// \brief RNG-based implementation of Source interface
|
/// \brief RNG-based implementation of Source interface
|
||||||
/// \since Crypto++ 4.0
|
/// \since Crypto++ 4.0
|
||||||
class CRYPTOPP_DLL RandomNumberSource : public SourceTemplate<RandomNumberStore>
|
class CRYPTOPP_DLL RandomNumberSource : public SourceTemplate<RandomNumberStore>
|
||||||
|
|
|
||||||
|
|
@ -1513,7 +1513,13 @@ bool TestStringSink()
|
||||||
std::vector<byte> vec;
|
std::vector<byte> vec;
|
||||||
StringSource s2(in, true, new VectorSink(vec));
|
StringSource s2(in, true, new VectorSink(vec));
|
||||||
|
|
||||||
return str.size() == vec.size() && std::equal(str.begin(), str.end(), vec.begin());
|
std::vector<byte> vec2;
|
||||||
|
VectorSource s3(vec, true, new VectorSink(vec2));
|
||||||
|
|
||||||
|
return str.size() == vec.size() &&
|
||||||
|
std::equal(str.begin(), str.end(), vec.begin()) &&
|
||||||
|
vec.size() == vec2.size() &&
|
||||||
|
std::equal(vec.begin(), vec.end(), vec2.begin());
|
||||||
}
|
}
|
||||||
catch(const std::exception&)
|
catch(const std::exception&)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue