On Wednesday, May 7, 2014 7:00:46 AM UTC-4, Jo Win wrote:
>
> Hello,
>
> I would like to encrypt multiple files and put them all together in one 
> file. So I create an Object of type FileSink and I would like to use a code 
> like
>
>     CryptoPP::FileSink *file = new CryptoPP::FileSink("/path/to/my/file");
>
>     std::string str1;
>     std::string str2;
>     str1.append("hi ");
>     str2.append("how are you");
>
>     CryptoPP::StringSource(str1,true, file);
>     CryptoPP::StringSource(str2,true, file); //crash
>
'file' is deleted after the the first StringSource's destructor runs. When 
the second StringSink attempts to use 'file', its no longer a valid object.

Try:

     CryptoPP::FileSink file("/path/to/my/file");

    std::string str1;
    std::string str2;
    str1.append("hi ");
    str2.append("how are you");

    CryptoPP::StringSource ss1(str1,true, new CryptoPP::Redirector(file));
    CryptoPP::StringSource ss2(str2,true, new CryptoPP::Redirector(file));

With the code above, the Redirector stops the ownership chain, so the 
StringSource will *not* delete the attached transformation (in this case, 
the FileSink). The FileSink will be cleaned up when the function exits 
since its an automatic (stack) variable.

Jeff

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to