struct encrypt_stream : public std::stringbuf
{
int sync() { encrypt_buffer(); flush_to_device(); }
...
private:
void encrypt_buffer();
void flush_to_device();
};
I want to write this class to encrypt text data. Every time this stringbuf
object is flushed, sync
is called and an encrypted version of the buffer is sent to the device. The encrypted text strongly depends on the moment when flush
is called. Are there tricky cases where flush
can be called on this object without the user asking for it?
I know that flush
is called when std::endl
is received, but are there any other cases I am unaware of?