Redirector
From Crypto++ Wiki
A Redirector is sink that does not own its attached transformation. A Redirector will end an attachment chain, but still pass received data to another filter. Because the Redirector does not ultimately own the attached transformation, a BufferedTransformation reference is passed to the constructor rather than a pointer.
An application of the Redirector is to facilitate the retrieving of a result from an intermediate object that is participating in a pipeline. Most notable is the result from a HashVerificationFilter or AuthenticatedDecryptionFilter.
[edit] Constructor
There are two constructors available for a Redirector since it is not possible to overload the constructor with a NULL reference.
Redirector()
Initializes the Redirector with a NULL BufferedTransformation. This behavior is some what unique among filters in that most filters, when presented with a NULL attachment, will create a MessageQueue for internal use.
Redirector(BufferedTransformation &target, Behavior behavior=PASS_EVERYTHING)
The first parameter is a BufferedTransformation. The second parameter, Behavior can be a combination of the following:
- DATA_ONLY (0x00)
- PASS_SIGNALS (0x01)
- PASS_WAIT_OBJECTS (0x02)
- PASS_EVERYTHING (PASS_SIGNALS | PASS_WAIT_OBJECTS)
[edit] Sample Program
In the situation below, we do not want the filter to own the object and attempt to destroy it. To accomplish the goal, a Redirector would be used. Below, the Redirector takes a reference to an object, and not a pointer to an object.
const int TAG_SIZE = 12;
CCM< AES, TAG_SIZE >::Decryption d;
d.SetKeyWithIV( key, sizeof(key), iv, sizeof(iv) );
...
AuthenticatedDecryptionFilter df( d,
new StringSink( recovered )
); // AuthenticatedDecryptionFilter
// Cipher text includes the MAC tag
StringSource( cipher, true,
new Redirector( df )
); // StringSource
// If the object does not throw, here's the only
// opportunity to check the data's integrity
bool b = df.GetLastResult();
if( true == b ) {
cout << recovered << endl;
}