Skip to content

OpenSSL::ASN1.decode yields OpenSSL::ASN1::Integer instances with a "value" attribute type of OpenSSL::BN #176

@CBonnell

Description

@CBonnell

In OpenSSL gem 2.0.6 (using Ruby 2.4.2) and as far back as Ruby 2.2.1 (if not earlier), creating OpenSSL::ASN1::Integer instances using OpenSSL::ASN1.decode produces instances whose value attribute is of type OpenSSL::BN, not Number (which should probably be documented as Integer) as documented on the docs page for OpenSSL::ASN1::Primitive (http://ruby-doc.org/stdlib-2.4.2/libdoc/openssl/rdoc/OpenSSL/ASN1/Primitive.html).

Either OpenSSL::ASN1.decode should be modified to return OpenSSL::ASN1::Integer instances whose value attribute is of type Integer, not OpenSSL::BN. If this is not palatable from a backwards compatibility standpoint, this discrepancy should at least be documented.

Code to reproduce:

require 'openssl'
puts OpenSSL::ASN1.decode("\x02\x01\x05").value.inspect
puts OpenSSL::ASN1::Integer.new(5).value.inspect

Expected output:

5
5

Actual output:

#OpenSSL::BN:0x007fe7818061f8
5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions