In the Pipelining paradigm, a Sink is the destination of transformed data. They accept transformed data from Filters, and they are the last member of a chain. Sinks serve the opposite role of Sources.
Private keys and other sensitive material should not be save to a
string using a
StringSink. Many sample code uses a and snippets use StringSink and
string to hold the sensitive material. Though convenient, the practice is not a very good idea - see Keys and Formats for details.
The following example demonstrates the creation of a
string s; StringSink sink( s );
The following example demonstrates reading a file, and placing the contents of the file in a string. This is known as pipelining.
string s; FileSource file( filename, new StringSink( s ) ); cout << s << endl;
The following example performs the same operation as above, but without the variable
string s; FileSource( filename, true, new StringSink( s ) ); cout << s << endl;
string s; FileSource( filename, new HexEncoder( new StringSink( s ) ) ); cout << s << endl;
Note that the
StringSink created with
new do not require explicit destruction - the
FileSource will call
delete on the
HexEncoder, which in turns calls
delete on the StringSink when it (the
FileSource) is destroyed.
Finally, the example below places 4 random bytes of data into a
StringSink after hex encoding using a random number source. As the chain gets longer, nesting the chaining structure as with
if statements offers better readability.
string s; AutoSeededRandomPool rng; RandomNumberSource( rng, 4, true, new HexEncoder( new CryptoPP::StringSink( s ) ) // HexEncoder ); // RandomNumberSource
No downloads available.