emboss/krypt-core — comment on commit 685443010fdc31cf2b21ff62bebcc559ce2a97c9
File:  line 0
By emboss:

@nahi: Boy, that took longer than expected. But I love it the way it is now!

- You can do ASN1.decode with DER or PEM interchangeably.
- If the underlying stream does not support a "rewind", it will still work by constructing a "SequenceInputStream" that consists of the lookahead plus the original stream.
- Of course this means a slight performance penalty (but much less than I thought) - those users that know with which format they are dealing may use ASN1.decode_der/decode_pem instead.
- Now the thing I'm most proud of: Krypt::PEM.decode returns an array of all the values it may find in a file (think of CA bundle file). You can also feed it a block, where the DER value itself, the "name" (such as "X.509 CERTIFICATE") and the current index is yielded.

You can see it in action via https://github.com/emboss/krypt-core/blob/685443010fdc31cf2b21ff62bebcc559ce2a97c9/test/scratch.rb.

What do you think of it? In my opinion that's as flexible as we can get. And it still performs way better than the old OpenSSL code. PS: The opportunity to read additional "header data" from within a -----BEGIN .... END----- block (sometimes there's some data just before the Base64-encoded stuff) is currently missing, but once needed it can be easily added. That would be another parameter in the block arguments of Krypt::PEM.decode.