From 976a3f5152b36129ad478175473bd63345286450 Mon Sep 17 00:00:00 2001 From: kares Date: Fri, 13 Dec 2024 15:57:13 +0100 Subject: [PATCH] [fix] missing OpenSSL::ASN1::ObjectId#== (#311) --- src/main/java/org/jruby/ext/openssl/ASN1.java | 8 ++++++++ src/test/ruby/test_asn1.rb | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/org/jruby/ext/openssl/ASN1.java b/src/main/java/org/jruby/ext/openssl/ASN1.java index 2f15d1ea..3ebd61fe 100644 --- a/src/main/java/org/jruby/ext/openssl/ASN1.java +++ b/src/main/java/org/jruby/ext/openssl/ASN1.java @@ -915,6 +915,14 @@ public static RubyString oid(final ThreadContext context, final IRubyObject self return runtime.newString( getObjectID(runtime, self.callMethod(context, "value").toString()).getId() ); } + @JRubyMethod(name = "==") + public static IRubyObject eq(final ThreadContext context, final IRubyObject self, final IRubyObject other) { + if (!other.getMetaClass().equals(_ASN1(context.runtime).getClass("ObjectId"))) { + return context.runtime.getFalse(); + } + return self.callMethod(context, "value").op_eqq(context, other.callMethod(context, "value")); + } + private static RubyString name(final ThreadContext context, IRubyObject value, final boolean longName) { final Ruby runtime = context.runtime; diff --git a/src/test/ruby/test_asn1.rb b/src/test/ruby/test_asn1.rb index 9867a4b3..1cf62aa3 100644 --- a/src/test/ruby/test_asn1.rb +++ b/src/test/ruby/test_asn1.rb @@ -337,6 +337,10 @@ def test_object_identifier #assert_raise(TypeError) { # OpenSSL::ASN1::ObjectId.new("authorityKeyIdentifier") == nil #} + + oid = OpenSSL::ASN1::ObjectId.new("2.5.29.14") + assert_equal true, oid == OpenSSL::ASN1::ObjectId.new("2.5.29.14") + assert_equal false, oid == OpenSSL::ASN1::ObjectId.new("2.5.29.35") end def test_instantiate