c++ - Transparently manipulating strings inserted into an ostream -
i'd provide std::ostream
may or may not, user's point of view, encrypt contents.
imagine random function uses std::ostream&
:
void write_stuff( std::ostream& stream ) { os << "stuff"; }
whether stuff
output in cleartext or encrypted dependent on how stream
argument initialized.
i'm thinking inheriting std::basic_streambuf
, i'm not sure it's best way go. think ideal scenario sort of filter object run before contents output. way it'd easy chain operations, e.g. encrypting , hex-encoding, benefit making own basic_streambuf
not seem give (not @ least).
any advices?
thanks.
update: followed strategy laid out accepted answer. found article on writing custom streambuf
performs xor obfuscation extremely helpful starting point.
a streambuf
can implemented in terms of arbitrary streambuf
that's either passed in argument constructor or set special member function. , allows stack streambuf
implementations thinking of.
you make manipulator uses ostream
's rdbuf
function current streambuf
, call function on streambuf
sets 'stacked' streambuf
, , calls rdbuf
again replace ostream
's streambuf
own.
aes_ctr_streambuf encrypter(key); zlib_streambuf compressor; ::std::cout << stack_streambuf(encrypter) << stack_streambuf(compressor);
Comments
Post a Comment