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