|There's more than one way to do things|
My Stupid Head, or why you should never stop thinkingby btrott (Parson)
|on Jul 27, 2001 at 09:51 UTC||Need Help??|
It's been said before and before again, but here is another example of why you should never let yourself get locked into a particular way of thinking about a problem.
I'm working on a pure-Perl OpenPGP implementation (will be on CPAN in the next couple of days, Crypt::OpenPGP; the link will work when it's up :). And so on this particular day today I am working on the compression code, using Compress::Zlib.
Decompression worked fine, but I had a problem with compression: every time I would compress a data packet, GnuPG and PGP5 would have strange and mysterious errors when decompressing it. The errors usually didn't prevent the programs from decompressing the data, but they would die ugly deaths soon afterwards.
It turns out that the reason I was having the problem is because I am very, very stupid.
For the compression code I am using the relatively low-level Compress::Zlib interface (deflateInit, etc.) and after deflating, I am calling flush. And I was giving flush the Z_PARTIAL_FLUSH parameter, and then I tried Z_SYNC_FLUSH, etc. etc. The reason I did this is because when I was writing the compression code for Net::SSH::Perl, it took me a while to realize that I needed to use Z_PARTIAL_FLUSH. So I figured, why not save myself some time and just start using the "correct" flush type in the beginning.
This is a problem when the "correct" flush type is not so correct.
So I spent hours debugging the code, printing out hex dumps of the compressed and decompressed data, etc.
All the time not realizing that *the default*, Z_FINISH (which you get if you don't supply any args at all--hence default), is what works for PGP.