-
Notifications
You must be signed in to change notification settings - Fork 82
[fix] OpenSSL::ASN1::ASN1Data encoding/decoding compatibility #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,6 +251,36 @@ def test_null | |
} | ||
end | ||
|
||
def test_encode_asn1_data | ||
ai = OpenSSL::ASN1::ASN1Data.new(i = "bla", 0, :APPLICATION) | ||
ai2 = OpenSSL::ASN1.decode(ai.to_der) | ||
assert_equal :APPLICATION, ai2.tag_class | ||
assert_equal 0, ai2.tag | ||
assert_equal i, ai2.value | ||
|
||
ai = OpenSSL::ASN1::ASN1Data.new(i = "bla", 4, :UNIVERSAL) | ||
ai2 = OpenSSL::ASN1.decode(ai.to_der) | ||
assert_equal :UNIVERSAL, ai2.tag_class | ||
assert_equal 4, ai2.tag | ||
assert_equal i, ai2.value | ||
|
||
ai = OpenSSL::ASN1::ASN1Data.new(i = ["bla"], 0, :APPLICATION) | ||
ai2 = OpenSSL::ASN1.decode(ai.to_der) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still need to check with OpenSSL 1.x but recent Ruby versions do not support decoding the array:
it's a bit of an edge case and I am happy to leave it as is ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe so (I think I took this example from an SNMP use case, but it's been some time to give you precise details). |
||
assert_equal :APPLICATION, ai2.tag_class | ||
assert_equal 0, ai2.tag | ||
assert_equal "bla", ai2.value | ||
|
||
ai = OpenSSL::ASN1::ASN1Data.new(i = ["bla", "bla"], 0, :APPLICATION) | ||
ai2 = OpenSSL::ASN1.decode(ai.to_der) | ||
assert_equal :APPLICATION, ai2.tag_class | ||
assert_equal 0, ai2.tag | ||
assert_equal "blabla", ai2.value | ||
|
||
assert_raise(ArgumentError) { OpenSSL::ASN1::ASN1Data.new(1).to_der } | ||
assert_raise("no implicit conversion of Integer into String") { OpenSSL::ASN1::ASN1Data.new(1, 0, :APPLICATION).to_der } | ||
assert_raise("no implicit conversion of Integer into String") { OpenSSL::ASN1::ASN1Data.new(1, 0, :CONTEXT_SPECIFIC).to_der } | ||
end | ||
|
||
def test_encode_nil | ||
#Primitives raise TypeError, Constructives NoMethodError | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems a bit unusual, is there a reason why we have to resort to the exception as flow control?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't make the decoding of
"@\x03bla"
work in any other way (see the respective unit test, it fails with " unexpected implicit primitive encoding" without this). Do you know of a better alternative?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, thanks - there does not seem to be a way API to check (e.g.
isParsed()
) isn't public 😞