-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi,
first off, I'm very new to Crypto++, so please excuse me if I'm missing something obvious here.
I was using a construct like this (publicKey is a DSA::PublicKey):
std::string s; publicKey.DEREncode( Base64Encoder( new StringSink( s ) ).Ref() ) );
and noticed that the base 64 encoded result is missing trailing characters if the binary DER encoding isn't a multiple of 3 bytes long. An explicit call of the Base64Encoder's MessageEnd() function fixed this. However, that makes it impossible to use a temporary like above. So I wrote this little helper:
class AutoEnd
{
public:
~ AutoEnd( CryptoPP::BufferedTransformation& bt ) : m_bt( bt ) {}
~ ~AutoEnd() { m_bt.MessageEnd(); }
~ operator CryptoPP::BufferedTransformation& () const { return m_bt; }
private:
~ CryptoPP::BufferedTransformation& m_bt;
};and changed the above code to use it:
std::string s; publicKey.DEREncode( AutoEnd( Base64Encoder( new StringSink( s ) ).Ref() ) ) );
It's clear to me that DEREncode() cannot call MessageEnd() without reducing flexibility. But wouldn't it make sense to have BufferedTransformation do the above? To make the virtual calls work and ensure MessageEnd() is only called once, maybe every subclass's dtor could call a new member function of BT that calls MessageEnd() when called the first time per instance.
Cheers, Malte -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFAaD7HVDF3RdLzx4cRAnDHAKDBXEVO0fvSoDBrGCw00pYhIEQD4gCfQfN8 wRxP11xSdvNloqmpm4v1lkQ= =Q8NC -----END PGP SIGNATURE-----
