emboss/krypt-core — Issue #15: Parse Asn.1 integers as BigNums
Author: emboss
Created: 2012-01-23 17:50:58+00:00
State: open

Hi @nahi,

maybe you can help me with this: I'm having a problem to create a BigNum from the raw byte encoding of Asn.1 integers.

The problem is two-fold:
1. There is no public API that would allow me to create a Bignum using unsigned char*, long as parameters.
2. The constructors on the Ruby level assume a String that is a textual representation of a Bignum. I could use these, but it would feel kinda weird to first create a decimal or hex string of the bytes to pass it to the constructor, only that there the code will again transform the text into its initial raw byte representation. Not very efficient :)

My problem would go away if there is a constructor that would take a Ruby string that is *not* a textual representation, but represents the raw bytes of the BigNum. Maybe I overlooked it.
Did I miss some functionality that already solves my problem? If you don't know, who could I ask - mrkn, nagachika or nobu maybe? If there is no elegant solution, should I write a patch for CRuby that offers this functionality?

PS: Currently I only allow integers that are covered by 'long' range, that should be fine for starters. I guess I solved this already in krypt-core-jruby (https://github.com/emboss/krypt-core-jruby/blob/master/src/org/jruby/ext/krypt/asn1/Asn1Codecs.java#L105), but I would feel better if someone cross-checked that code. I don't really know what MarshalStream does... I should have written tests for this already, but didn't have the time yet :(