What exactly is the difference between FileSink, StringSink, FileSourcem StringSource.
Sources, Filters and Sinks are part of the Pipeline design in Crypto++. Data flows from a source, is transformed by filters, and then ends at a sink.
All sources are interchangeable. All filters are interchangeable. And all sinks are interchangeable. For example, to switch between a StringSink
and FileSink
, you need to supply a filename with a FileSink
. Otherwise, they operate the same. As another example, you can switch between a HexEncoder
and Base64Encoder
with no changes. As a final example, a SocketSource
or SocketSink
are going to need an IP address and port. What may (or may not) need to be changed depends on the object.
There are a number of sources. From Source Class Reference:
FileSource
StringSource
RandomNumberSource
WindowPipeSource
SocketSource
There are a number of filters. You are using two of them - AuthenticatedEncryptionFilter
and AuthenticatedDecryptionFilter
. From Filter Class Reference and FilterWithBufferedInput Class Reference:
HexEncoder
HexEncoder
Base32Encoder
Base32Decoder
Base64Encoder
Base64Encoder
DefaultEncryptor
DefaultEncryptorWithMAC
DefaultDecryptor
DefaultDecryptorWithMAC
- ...
StreamTransformationFilter
AuthenticatedEncryptionFilter
AuthenticatedDecryptionFilter
There are a number of sinks. From Sink Class Reference:
ArraySink
BitBucket
RandomNumberSink
StringSink
FileSink
SocketSink
- ...
There are some advanced topics, but I don't think they matter at the moment. For example, the role of BufferedTransformation
and what it means if Attachable
returns true
. The answer is both Filters and Sinks are BufferedTransformation
's, and Attachable = true
means its a Filter (otherwise its a Sink).
... in following example, why does cipher need to be set to something...
A StringSource
and StringSink
needs nothing because its just an array of byes in memory. A FileSource
and FileSink
needs a filename, and you are using cipher
for the filename. You have to supply a filename because the objects a file/stream related. If you were using a SocketSource
or SocketSink
, then you would need to supply an IP address and port (more correctly, a socket_t
).
Here are the FileSource
constructors from FileSource Class Reference. You are using the third constructor in your code.
FileSource (BufferedTransformation *attachment=NULL)
FileSource (std::istream &in, bool pumpAll, BufferedTransformation *attachment=NULL)
FileSource (const char *filename, bool pumpAll, BufferedTransformation *attachment=NULL, bool binary=true)
Here are the FileSink
constructors from FileSink Class Reference. You are using the second constructor in your code.
FileSink (std::ostream &out)
FileSink (const char *filename, bool binary=true)