Skip to content

Commit e0c6f9b

Browse files
committed
[feat] implement #oid method for PKey classes (#281)
1 parent ab355ca commit e0c6f9b

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,11 @@ public IRubyObject sysverify(IRubyObject data, IRubyObject sign) {
441441
}
442442
}
443443

444+
@JRubyMethod
445+
public IRubyObject oid() {
446+
return getRuntime().newString("DSA");
447+
}
448+
444449
private DSAKey getDsaKey() {
445450
DSAKey result;
446451
return (result = publicKey) != null ? result : privateKey;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,11 @@ public IRubyObject dh_compute_key(final ThreadContext context, final IRubyObject
542542
}
543543
}
544544

545+
@JRubyMethod
546+
public IRubyObject oid() {
547+
return getRuntime().newString("id-ecPublicKey");
548+
}
549+
545550
private Group getGroup(boolean required) {
546551
if (group == null) {
547552
if (publicKey != null) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ private RubyString doCipherRSA(final Ruby runtime,
541541
}
542542
}
543543

544+
@JRubyMethod
545+
public IRubyObject oid() {
546+
return getRuntime().newString("rsaEncryption");
547+
}
548+
544549
@JRubyMethod(name="d=")
545550
public synchronized IRubyObject set_d(final ThreadContext context, IRubyObject value) {
546551
if ( privateKey != null ) {

src/test/ruby/ec/test_ec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
class TestEC < TestCase
55

6+
def test_oid
7+
key = OpenSSL::PKey::EC.new
8+
assert_equal 'id-ecPublicKey', key.oid
9+
end
10+
611
def test_read_pem
712
key_file = File.join(File.dirname(__FILE__), 'private_key.pem')
813

src/test/ruby/rsa/test_rsa.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ def setup
99
require 'base64'
1010
end
1111

12+
def test_oid
13+
key = OpenSSL::PKey::RSA.new
14+
assert_equal 'rsaEncryption', key.oid
15+
end
16+
1217
def test_rsa_private_decrypt
1318
key_file = File.join(File.dirname(__FILE__), 'private_key.pem')
1419
base64_cipher = "oj1VB1Lnh6j5Ahoq4dllIXkStZHaT9RvizB0x+yIUDtzi6grSh9vXoCchb+U\nkyLOcMmIXopv1Oe7h2te+XS63AG0EAfUhKTFVDYkm7VmcXue25MPr+P+0w+7\nWjZci4VRBLq3T2qZa3IJhQPsNAtEE1DYXnEjNe0jcFa2bu8TPNscoogo5aAw\nQGT+3cKe7A053czG47Sip7aIo+4NlJHE9kFMOTLaWi3fvv/M9/VKo3Bmm/88\n8Ai09LncNTpq787CRHw/wfjuPlQJOiLt+i7AZHBl6x0jK9bqkhPK5YwP0vmc\nuL52QLzgPxj9E78crg47iJDOgNwU/ux1/VuKnlQ9PQ==\n"

0 commit comments

Comments
 (0)