Add VectorSink
parent
44cd7eb1ed
commit
9b81a545fc
|
|
@ -50,7 +50,7 @@
|
||||||
<dt>Input Source Classes<dd>
|
<dt>Input Source Classes<dd>
|
||||||
StringSource, ArraySource, FileSource, RandomNumberSource
|
StringSource, ArraySource, FileSource, RandomNumberSource
|
||||||
<dt>Output Sink Classes<dd>
|
<dt>Output Sink Classes<dd>
|
||||||
StringSinkTemplate, StringSink, ArraySink, FileSink, RandomNumberSink
|
StringSinkTemplate, StringSink, VectorSink, ArraySink, FileSink, RandomNumberSink
|
||||||
<dt>Filter Wrappers<dd>
|
<dt>Filter Wrappers<dd>
|
||||||
StreamTransformationFilter, AuthenticatedEncryptionFilter, AuthenticatedDecryptionFilter, HashFilter,
|
StreamTransformationFilter, AuthenticatedEncryptionFilter, AuthenticatedDecryptionFilter, HashFilter,
|
||||||
HashVerificationFilter, SignerFilter, SignatureVerificationFilter
|
HashVerificationFilter, SignerFilter, SignatureVerificationFilter
|
||||||
|
|
|
||||||
12
filters.h
12
filters.h
|
|
@ -1063,12 +1063,13 @@ template <class T>
|
||||||
class StringSinkTemplate : public Bufferless<Sink>
|
class StringSinkTemplate : public Bufferless<Sink>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef typename T::value_type value_type;
|
||||||
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> type
|
||||||
StringSinkTemplate(T &output)
|
StringSinkTemplate(T &output)
|
||||||
: m_output(&output) {CRYPTOPP_ASSERT(sizeof(output[0])==1);}
|
: m_output(&output) {CRYPTOPP_ASSERT(sizeof(value_type)==1);}
|
||||||
|
|
||||||
void IsolatedInitialize(const NameValuePairs ¶meters)
|
void IsolatedInitialize(const NameValuePairs ¶meters)
|
||||||
{if (!parameters.GetValue("OutputStringPointer", m_output)) throw InvalidArgument("StringSink: OutputStringPointer not specified");}
|
{if (!parameters.GetValue("OutputStringPointer", m_output)) throw InvalidArgument("StringSink: OutputStringPointer not specified");}
|
||||||
|
|
@ -1076,14 +1077,12 @@ public:
|
||||||
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
|
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
|
||||||
{
|
{
|
||||||
CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking);
|
CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking);
|
||||||
typedef typename T::traits_type::char_type char_type;
|
|
||||||
|
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
typename T::size_type size = m_output->size();
|
typename T::size_type size = m_output->size();
|
||||||
if (length < size && size + length > m_output->capacity())
|
if (length < size && size + length > m_output->capacity())
|
||||||
m_output->reserve(2*size);
|
m_output->reserve(2*size);
|
||||||
m_output->append((const char_type *)inString, (const char_type *)inString+length);
|
m_output->insert(m_output->end(), (const value_type *)inString, (const value_type *)inString+length);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1099,6 +1098,11 @@ private:
|
||||||
DOCUMENTED_TYPEDEF(StringSinkTemplate<std::string>, StringSink)
|
DOCUMENTED_TYPEDEF(StringSinkTemplate<std::string>, StringSink)
|
||||||
CRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate<std::string>;
|
CRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate<std::string>;
|
||||||
|
|
||||||
|
/// \brief Append input to a std::vector<byte> object
|
||||||
|
/// \details VectorSink is a typedef for StringSinkTemplate<std::vector<byte> >.
|
||||||
|
DOCUMENTED_TYPEDEF(StringSinkTemplate<std::vector<byte> >, VectorSink);
|
||||||
|
CRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate<std::vector<byte> >;
|
||||||
|
|
||||||
/// \brief Incorporates input into RNG as additional entropy
|
/// \brief Incorporates input into RNG as additional entropy
|
||||||
/// \since Crypto++ 4.0
|
/// \since Crypto++ 4.0
|
||||||
class RandomNumberSink : public Bufferless<Sink>
|
class RandomNumberSink : public Bufferless<Sink>
|
||||||
|
|
|
||||||
21
validat3.cpp
21
validat3.cpp
|
|
@ -41,6 +41,7 @@ bool ValidateAll(bool thorough)
|
||||||
{
|
{
|
||||||
bool pass=TestSettings();
|
bool pass=TestSettings();
|
||||||
pass=TestOS_RNG() && pass;
|
pass=TestOS_RNG() && pass;
|
||||||
|
pass=TestStringSink() && pass;
|
||||||
pass=TestRandomPool() && pass;
|
pass=TestRandomPool() && pass;
|
||||||
#if !defined(NO_OS_DEPENDENCE) && defined(OS_RNG_AVAILABLE)
|
#if !defined(NO_OS_DEPENDENCE) && defined(OS_RNG_AVAILABLE)
|
||||||
pass=TestAutoSeededX917() && pass;
|
pass=TestAutoSeededX917() && pass;
|
||||||
|
|
@ -561,6 +562,26 @@ bool TestOS_RNG()
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TestStringSink()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string in = "The quick brown fox jumps over the lazy dog";
|
||||||
|
|
||||||
|
std::string str;
|
||||||
|
StringSource s1(in, true, new StringSink(str));
|
||||||
|
|
||||||
|
std::vector<byte> vec;
|
||||||
|
StringSource s2(in, true, new VectorSink(vec));
|
||||||
|
|
||||||
|
return str.size() == vec.size() && std::equal(str.begin(), str.end(), vec.begin());
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool TestRandomPool()
|
bool TestRandomPool()
|
||||||
{
|
{
|
||||||
std::cout << "\nTesting RandomPool generator...\n\n";
|
std::cout << "\nTesting RandomPool generator...\n\n";
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ NAMESPACE_BEGIN(Test)
|
||||||
bool ValidateAll(bool thorough);
|
bool ValidateAll(bool thorough);
|
||||||
bool TestSettings();
|
bool TestSettings();
|
||||||
bool TestOS_RNG();
|
bool TestOS_RNG();
|
||||||
|
bool TestStringSink();
|
||||||
// bool TestSecRandom();
|
// bool TestSecRandom();
|
||||||
bool TestRandomPool();
|
bool TestRandomPool();
|
||||||
#if !defined(NO_OS_DEPENDENCE)
|
#if !defined(NO_OS_DEPENDENCE)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue