Skip to content

Commit

Permalink
[compat] make sure PKey::EC#generate_key! exists
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Jan 19, 2025
1 parent 80e6df0 commit e104b59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/jruby/ext/openssl/PKeyEC.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public IRubyObject check_key(final ThreadContext context) {
return context.runtime.getTrue(); // TODO not implemented stub
}

@JRubyMethod(name = "generate_key")
@JRubyMethod(name = "generate_key!", alias = "generate_key")
public PKeyEC generate_key(final ThreadContext context) {
try {
ECGenParameterSpec genSpec = new ECGenParameterSpec(getCurveName());
Expand Down
16 changes: 16 additions & 0 deletions src/test/ruby/ec/test_ec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@

class TestEC < TestCase

def test_generate
assert_raise(OpenSSL::PKey::ECError) { OpenSSL::PKey::EC.generate("non-existent") }
g = OpenSSL::PKey::EC::Group.new("prime256v1")
ec = OpenSSL::PKey::EC.generate(g)
assert_equal(true, ec.private?)
ec = OpenSSL::PKey::EC.generate("prime256v1")
assert_equal(true, ec.private?)
end

def test_generate_key
ec = OpenSSL::PKey::EC.new("prime256v1")
assert_equal false, ec.private?
ec.generate_key!
assert_equal true, ec.private?
end #if !openssl?(3, 0, 0)

def test_PUBKEY
p256 = Fixtures.pkey("p256")
p256pub = OpenSSL::PKey::EC.new(p256.public_to_der)
Expand Down

0 comments on commit e104b59

Please sign in to comment.