Skip to content

Commit

Permalink
[fix] raise TypeError when arg isn't a Group
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Apr 11, 2024
1 parent 029a779 commit 21c93d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/jruby/ext/openssl/PKeyEC.java
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,10 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a

if ( arg instanceof Group ) {
this.group = (Group) arg;
} else {
throw runtime.newTypeError(arg, _EC(runtime).getClass("Group"));
}

if ( argc == 2 ) { // (group, bn)
final byte[] encoded;
if (args[1] instanceof BN) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/ruby/ec/test_ec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def test_point
# assert_equal hybrid, point.to_octet_string(:hybrid)
end

def test_point_error
assert_raise(ArgumentError) { OpenSSL::PKey::EC::Point.new }
assert_raise(TypeError) { OpenSSL::PKey::EC::Point.new(nil) }
assert_raise(TypeError) { OpenSSL::PKey::EC::Point.new(nil, '') }
assert_raise(TypeError) { OpenSSL::PKey::EC::Point.new(100, '') }
end

def test_random_point
group = OpenSSL::PKey::EC::Group.new("prime256v1")
key = OpenSSL::PKey::EC.generate(group)
Expand Down

0 comments on commit 21c93d8

Please sign in to comment.