diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-10 21:26:23 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-10 21:26:23 +0000 |
commit | 62e2f9052be5a2cfb02169cd41edd28443006df2 (patch) | |
tree | 0ea24d5f5cfaa5d4f1da03cb335962d853b53c67 | |
parent | 1bd8a97eb5c7ca5f37c2a531d9540babaa7df319 (diff) | |
download | ruby-62e2f9052be5a2cfb02169cd41edd28443006df2.tar.gz |
Include Comparable in OpenSSL::X509::Name, document #<=>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/openssl/ossl_x509name.c | 13 | ||||
-rw-r--r-- | test/openssl/test_x509name.rb | 14 |
3 files changed, 32 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Sat Dec 11 06:23:41 2010 Eric Hodel <drbrain@segment7.net> + + * 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@ai.kyutech.ac.jp> * ext/tk/lib/multi-tk.rb: infinite loop on method_missing at loading. diff --git a/ext/openssl/ossl_x509name.c b/ext/openssl/ossl_x509name.c index e716f100c7..417d042740 100644 --- a/ext/openssl/ossl_x509name.c +++ b/ext/openssl/ossl_x509name.c @@ -266,6 +266,14 @@ ossl_x509name_cmp0(VALUE self, VALUE other) 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 @@ ossl_x509name_eql(VALUE self, VALUE other) /* * 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 @@ Init_ossl_x509name() 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); diff --git a/test/openssl/test_x509name.rb b/test/openssl/test_x509name.rb index 292a59f612..951c36c425 100644 --- a/test/openssl/test_x509name.rb +++ b/test/openssl/test_x509name.rb @@ -261,6 +261,20 @@ class OpenSSL::TestX509Name < Test::Unit::TestCase 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 |