Hi there,

Consider the following code:

std::string sOut;
StringSource("This is some string", true,
                                new MyFilter(
                                        new StringSink(sOut)
                                )
                        );

With the following class:

class MyFilter : public Bufferless< Filter >
{
public:
        MyFilter(BufferedTransformation* attachment)
                { Detach(attachment); Init(); }

        void Init()
        {
                StringSource( "Header #1", true, AttachedTransformation() );
                StringSource( "Header #2", true, AttachedTransformation() );
        }

        size_t Put2(const byte *input, size_t length, int messageEnd, bool
blocking)
                { return AttachedTransformation()->Put2(input, length, 
messageEnd,
blocking); }
};

I was planning on placing two prefix headers into the attached output
upon Init().
The output should look like this:
"Header #1Header #2This is some string"

However, the result is a painful crash..
The first StringSource line will DELETE AttachedTransformation() upon
StringSource's destructor...
Note: this is an extremely simplified version of what I was dealing
with for many many hours.

So I'm wondering how can that be accomplished?
How can I pass initial data onto to the output stream and survive the
crash?


Well, I actually have a solution.

class NoDeleteSink : public CryptoPP::Bufferless< CryptoPP::Sink >
{
        BufferedTransformation* m_attachment;

public:
        NoDeleteSink(BufferedTransformation* attachment)
        : m_attachment( attachment ) {} // Not calling Detach()

        size_t Put2(const byte *input, size_t length, int messageEnd, bool
blocking)
        {
                return m_attachment->Put2(input, length, messageEnd, blocking);
        }
};

And replace the relevant lines with:

StringSource( "Header #1", true,
        new NoDeleteSink( AttachedTransformation() ) );

StringSource( "Header #2", true,
        new NoDeleteSink( AttachedTransformation() ) );

The question left to ask is if there's a Crypto++ build-in solution
for this issue?

Thanks,

    Avi.
--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to