diff --git a/algparam.h b/algparam.h index 23a5f43f..40c5f46e 100644 --- a/algparam.h +++ b/algparam.h @@ -44,8 +44,8 @@ public: } /// \brief Construct a ConstByteArrayParameter - /// \tparam T a std::basic_string class - /// \param string a std::basic_string class + /// \tparam T a std::basic_string or std::vector class + /// \param string a std::basic_string or std::vector 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 diff --git a/cryptlib.h b/cryptlib.h index c90ffd2a..78bb6d68 100644 --- a/cryptlib.h +++ b/cryptlib.h @@ -48,7 +48,7 @@
Compression
Deflator, Inflator, Gzip, Gunzip, ZlibCompressor, ZlibDecompressor
Input Source Classes
- StringSource, ArraySource, FileSource, RandomNumberSource + StringSource, ArraySource, VectorSource, FileSource, RandomNumberSource
Output Sink Classes
StringSinkTemplate, StringSink, VectorSink, ArraySink, FileSink, RandomNumberSink
Filter Wrappers
diff --git a/filters.h b/filters.h index 696459a3..72e2550c 100644 --- a/filters.h +++ b/filters.h @@ -1067,7 +1067,7 @@ public: virtual ~StringSinkTemplate() {} /// \brief Construct a StringSinkTemplate - /// \param output std::basic_string type + /// \param output std::basic_string or std::vector 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 +{ +public: + /// \brief Construct a VectorSource + /// \param attachment an optional attached transformation + VectorSource(BufferedTransformation *attachment = NULLPTR) + : SourceTemplate(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 &vec, bool pumpAll, BufferedTransformation *attachment = NULLPTR) + : SourceTemplate(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(vec)));} +}; + /// \brief RNG-based implementation of Source interface /// \since Crypto++ 4.0 class CRYPTOPP_DLL RandomNumberSource : public SourceTemplate diff --git a/validat0.cpp b/validat0.cpp index d9c445f1..1e2fc9b5 100644 --- a/validat0.cpp +++ b/validat0.cpp @@ -1513,7 +1513,13 @@ bool TestStringSink() std::vector vec; StringSource s2(in, true, new VectorSink(vec)); - return str.size() == vec.size() && std::equal(str.begin(), str.end(), vec.begin()); + std::vector 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&) {