Skip to content

Commit 976a3f5

Browse files
committed
[fix] missing OpenSSL::ASN1::ObjectId#== (#311)
1 parent d692376 commit 976a3f5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,14 @@ public static RubyString oid(final ThreadContext context, final IRubyObject self
915915
return runtime.newString( getObjectID(runtime, self.callMethod(context, "value").toString()).getId() );
916916
}
917917

918+
@JRubyMethod(name = "==")
919+
public static IRubyObject eq(final ThreadContext context, final IRubyObject self, final IRubyObject other) {
920+
if (!other.getMetaClass().equals(_ASN1(context.runtime).getClass("ObjectId"))) {
921+
return context.runtime.getFalse();
922+
}
923+
return self.callMethod(context, "value").op_eqq(context, other.callMethod(context, "value"));
924+
}
925+
918926
private static RubyString name(final ThreadContext context, IRubyObject value,
919927
final boolean longName) {
920928
final Ruby runtime = context.runtime;

src/test/ruby/test_asn1.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ def test_object_identifier
337337
#assert_raise(TypeError) {
338338
# OpenSSL::ASN1::ObjectId.new("authorityKeyIdentifier") == nil
339339
#}
340+
341+
oid = OpenSSL::ASN1::ObjectId.new("2.5.29.14")
342+
assert_equal true, oid == OpenSSL::ASN1::ObjectId.new("2.5.29.14")
343+
assert_equal false, oid == OpenSSL::ASN1::ObjectId.new("2.5.29.35")
340344
end
341345

342346
def test_instantiate

0 commit comments

Comments
 (0)