-
Notifications
You must be signed in to change notification settings - Fork 82
to_der on ASN1Data should convert ruby strings into java strings before encoding #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
Open
HoneyryderChuck
wants to merge
3
commits into
jruby:master
Choose a base branch
from
HoneyryderChuck:fix-asn1data
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( |
||
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 | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?