Add VectorSource (GH #730)

pull/733/head
orangefour 2018-11-01 11:49:04 +01:00 committed by Jeffrey Walton
parent 7c5da3e1ca
commit 20f82c067e
4 changed files with 29 additions and 5 deletions

View File

@ -44,8 +44,8 @@ public:
}
/// \brief Construct a ConstByteArrayParameter
/// \tparam T a std::basic_string<char> class
/// \param string 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> or std::vector<byte> object
/// \param deepCopy flag indicating whether the data should be copied
/// \details The deepCopy option is used when the NameValuePairs object can't
/// keep a copy of the data available

View File

@ -48,7 +48,7 @@
<dt>Compression<dd>
Deflator, Inflator, Gzip, Gunzip, ZlibCompressor, ZlibDecompressor
<dt>Input Source Classes<dd>
StringSource, ArraySource, FileSource, RandomNumberSource
StringSource, ArraySource, VectorSource, FileSource, RandomNumberSource
<dt>Output Sink Classes<dd>
StringSinkTemplate, StringSink, VectorSink, ArraySink, FileSink, RandomNumberSink
<dt>Filter Wrappers<dd>

View File

@ -1067,7 +1067,7 @@ public:
virtual ~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)
: m_output(&output) {CRYPTOPP_ASSERT(sizeof(value_type)==1);}
@ -1426,6 +1426,24 @@ public:
/// \since Crypto++ 5.6.0
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
/// \since Crypto++ 4.0
class CRYPTOPP_DLL RandomNumberSource : public SourceTemplate<RandomNumberStore>

View File

@ -1513,7 +1513,13 @@ bool TestStringSink()
std::vector<byte> 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&)
{