[前][次][番号順一覧][スレッド一覧]

ruby-changes:18152

From: drbrain <ko1@a...>
Date: Sat, 11 Dec 2010 06:26:45 +0900 (JST)
Subject: [ruby-changes:18152] Ruby:r30173 (trunk): Include Comparable in OpenSSL::X509::Name, document #<=>

drbrain	2010-12-11 06:26:23 +0900 (Sat, 11 Dec 2010)

  New Revision: 30173

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30173

  Log:
    Include Comparable in OpenSSL::X509::Name, document #<=>

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_x509name.c
    trunk/test/openssl/test_x509name.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30172)
+++ ChangeLog	(revision 30173)
@@ -1,3 +1,8 @@
+Sat Dec 11 06:23:41 2010  Eric Hodel  <drbrain@s...>
+
+	* ext/openssl/ossl_x509name.c: include Comparable to provide #==.
+	  Document OpenSSL::X509::Name#<=>.  [Ruby 1.9-Feature#4116]
+
 Sat Dec 11 05:48:28 2010  Hidetoshi NAGAI  <nagai@a...>
 
 	* ext/tk/lib/multi-tk.rb: infinite loop on method_missing at loading.
Index: ext/openssl/ossl_x509name.c
===================================================================
--- ext/openssl/ossl_x509name.c	(revision 30172)
+++ ext/openssl/ossl_x509name.c	(revision 30173)
@@ -266,6 +266,14 @@
     return X509_NAME_cmp(name1, name2);
 }
 
+/*
+ * call-seq:
+ *    name.cmp other => integer
+ *    name.<=> other => integer
+ *
+ * Compares this Name with +other+ and returns 0 if they are the same and -1 or
+ * +1 if they are greater or less than each other respectively.
+ */
 static VALUE
 ossl_x509name_cmp(VALUE self, VALUE other)
 {
@@ -292,6 +300,9 @@
 /*
  * call-seq:
  *    name.hash => integer
+ *
+ * The hash value returned is suitable for use as a certificate's filename in
+ * a CA path.
  */
 static VALUE
 ossl_x509name_hash(VALUE self)
@@ -342,6 +353,8 @@
     eX509NameError = rb_define_class_under(mX509, "NameError", eOSSLError);
     cX509Name = rb_define_class_under(mX509, "Name", rb_cObject);
 
+    rb_include_module(cX509Name, rb_mComparable);
+
     rb_define_alloc_func(cX509Name, ossl_x509name_alloc);
     rb_define_method(cX509Name, "initialize", ossl_x509name_initialize, -1);
     rb_define_method(cX509Name, "add_entry", ossl_x509name_add_entry, -1);
Index: test/openssl/test_x509name.rb
===================================================================
--- test/openssl/test_x509name.rb	(revision 30172)
+++ test/openssl/test_x509name.rb	(revision 30173)
@@ -261,6 +261,20 @@
     assert_equal(OpenSSL::ASN1::IA5STRING, ary[3][2])
     assert_equal(OpenSSL::ASN1::PRINTABLESTRING, ary[4][2])
   end
+
+  def test_equals2
+    n1 = OpenSSL::X509::Name.parse 'CN=a'
+    n2 = OpenSSL::X509::Name.parse 'CN=a'
+
+    assert_equal n1, n2
+  end
+
+  def test_spaceship
+    n1 = OpenSSL::X509::Name.parse 'CN=a'
+    n2 = OpenSSL::X509::Name.parse 'CN=b'
+
+    assert_equal -1, n1 <=> n2
+  end
 end
 
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]