aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ext/openssl/ossl_asn1.c8
-rw-r--r--test/test_asn1.rb6
2 files changed, 12 insertions, 2 deletions
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c
index 03822b5c..cbedd59e 100644
--- a/ext/openssl/ossl_asn1.c
+++ b/ext/openssl/ossl_asn1.c
@@ -125,9 +125,13 @@ asn1integer_to_num(ASN1_INTEGER *ai)
if (!ai) {
ossl_raise(rb_eTypeError, "ASN1_INTEGER is NULL!");
}
- if (!(bn = ASN1_INTEGER_to_BN(ai, NULL))) {
+ if (ai->type == V_ASN1_ENUMERATED)
+ bn = ASN1_ENUMERATED_to_BN(ai, NULL);
+ else
+ bn = ASN1_INTEGER_to_BN(ai, NULL);
+
+ if (!bn)
ossl_raise(eOSSLError, NULL);
- }
#if DO_IT_VIA_RUBY
if (!(txt = BN_bn2dec(bn))) {
BN_free(bn);
diff --git a/test/test_asn1.rb b/test/test_asn1.rb
index 96c0859c..f226da5c 100644
--- a/test/test_asn1.rb
+++ b/test/test_asn1.rb
@@ -280,6 +280,12 @@ rEzBQ0F9dUyqQ9gyRg8KHhDfv9HzT1d/rnUZMkoombwYBRIUChGCYV0GnJcan2Zm
assert_equal 2 ** 31, OpenSSL::ASN1.decode(encoded).value.to_i
end
+ def test_decode_enumerated
+ encoded = OpenSSL::ASN1.Enumerated(0).to_der
+ assert_equal "\x0a\x01\x00".b, encoded
+ assert_equal encoded, OpenSSL::ASN1.decode(encoded).to_der
+ end
+
def test_create_inf_length_primitive
expected = %w{ 24 80 04 01 61 00 00 }
raw = [expected.join('')].pack('H*')