Skip to content

Commit 21c93d8

Browse files
committed
[fix] raise TypeError when arg isn't a Group
1 parent 029a779 commit 21c93d8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/main/java/org/jruby/ext/openssl/PKeyEC.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,10 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
946946

947947
if ( arg instanceof Group ) {
948948
this.group = (Group) arg;
949+
} else {
950+
throw runtime.newTypeError(arg, _EC(runtime).getClass("Group"));
949951
}
952+
950953
if ( argc == 2 ) { // (group, bn)
951954
final byte[] encoded;
952955
if (args[1] instanceof BN) {

src/test/ruby/ec/test_ec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ def test_point
9494
# assert_equal hybrid, point.to_octet_string(:hybrid)
9595
end
9696

97+
def test_point_error
98+
assert_raise(ArgumentError) { OpenSSL::PKey::EC::Point.new }
99+
assert_raise(TypeError) { OpenSSL::PKey::EC::Point.new(nil) }
100+
assert_raise(TypeError) { OpenSSL::PKey::EC::Point.new(nil, '') }
101+
assert_raise(TypeError) { OpenSSL::PKey::EC::Point.new(100, '') }
102+
end
103+
97104
def test_random_point
98105
group = OpenSSL::PKey::EC::Group.new("prime256v1")
99106
key = OpenSSL::PKey::EC.generate(group)

0 commit comments

Comments
 (0)