Skip to content

Commit

Permalink
[feat] implement #oid method for PKey classes (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Apr 8, 2024
1 parent ab355ca commit e0c6f9b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/jruby/ext/openssl/PKeyDSA.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ public IRubyObject sysverify(IRubyObject data, IRubyObject sign) {
}
}

@JRubyMethod
public IRubyObject oid() {
return getRuntime().newString("DSA");
}

private DSAKey getDsaKey() {
DSAKey result;
return (result = publicKey) != null ? result : privateKey;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jruby/ext/openssl/PKeyEC.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ public IRubyObject dh_compute_key(final ThreadContext context, final IRubyObject
}
}

@JRubyMethod
public IRubyObject oid() {
return getRuntime().newString("id-ecPublicKey");
}

private Group getGroup(boolean required) {
if (group == null) {
if (publicKey != null) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jruby/ext/openssl/PKeyRSA.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ private RubyString doCipherRSA(final Ruby runtime,
}
}

@JRubyMethod
public IRubyObject oid() {
return getRuntime().newString("rsaEncryption");
}

@JRubyMethod(name="d=")
public synchronized IRubyObject set_d(final ThreadContext context, IRubyObject value) {
if ( privateKey != null ) {
Expand Down
5 changes: 5 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,11 @@

class TestEC < TestCase

def test_oid
key = OpenSSL::PKey::EC.new
assert_equal 'id-ecPublicKey', key.oid
end

def test_read_pem
key_file = File.join(File.dirname(__FILE__), 'private_key.pem')

Expand Down
5 changes: 5 additions & 0 deletions src/test/ruby/rsa/test_rsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def setup
require 'base64'
end

def test_oid
key = OpenSSL::PKey::RSA.new
assert_equal 'rsaEncryption', key.oid
end

def test_rsa_private_decrypt
key_file = File.join(File.dirname(__FILE__), 'private_key.pem')
base64_cipher = "oj1VB1Lnh6j5Ahoq4dllIXkStZHaT9RvizB0x+yIUDtzi6grSh9vXoCchb+U\nkyLOcMmIXopv1Oe7h2te+XS63AG0EAfUhKTFVDYkm7VmcXue25MPr+P+0w+7\nWjZci4VRBLq3T2qZa3IJhQPsNAtEE1DYXnEjNe0jcFa2bu8TPNscoogo5aAw\nQGT+3cKe7A053czG47Sip7aIo+4NlJHE9kFMOTLaWi3fvv/M9/VKo3Bmm/88\n8Ai09LncNTpq787CRHw/wfjuPlQJOiLt+i7AZHBl6x0jK9bqkhPK5YwP0vmc\nuL52QLzgPxj9E78crg47iJDOgNwU/ux1/VuKnlQ9PQ==\n"
Expand Down

0 comments on commit e0c6f9b

Please sign in to comment.