Project

General

Profile

Feature #4116 ยป ossl_x509name.c.comparable.patch

drbrain (Eric Hodel), 12/04/2010 11:45 AM

View differences:

ext/openssl/ossl_x509name.c (working copy)
266 266
    return X509_NAME_cmp(name1, name2);
267 267
}
268 268

  
269
/*
270
 * call-seq:
271
 *    name.cmp other => integer
272
 *    name.<=> other => integer
273
 *
274
 * Compares this Name with +other+ and returns 0 if they are the same and -1 or
275
 * +1 if they are greater or less than each other respectively.
276
 */
269 277
static VALUE
270 278
ossl_x509name_cmp(VALUE self, VALUE other)
271 279
{
......
342 350
    eX509NameError = rb_define_class_under(mX509, "NameError", eOSSLError);
343 351
    cX509Name = rb_define_class_under(mX509, "Name", rb_cObject);
344 352

  
353
    rb_include_module(cX509Name, rb_mComparable);
354

  
345 355
    rb_define_alloc_func(cX509Name, ossl_x509name_alloc);
346 356
    rb_define_method(cX509Name, "initialize", ossl_x509name_initialize, -1);
347 357
    rb_define_method(cX509Name, "add_entry", ossl_x509name_add_entry, -1);
test/openssl/test_x509name.rb (working copy)
261 261
    assert_equal(OpenSSL::ASN1::IA5STRING, ary[3][2])
262 262
    assert_equal(OpenSSL::ASN1::PRINTABLESTRING, ary[4][2])
263 263
  end
264

  
265
  def test_equals2
266
    n1 = OpenSSL::X509::Name.parse 'CN=a'
267
    n2 = OpenSSL::X509::Name.parse 'CN=a'
268

  
269
    assert_equal n1, n2
270
  end
271

  
272
  def test_spaceship
273
    n1 = OpenSSL::X509::Name.parse 'CN=a'
274
    n2 = OpenSSL::X509::Name.parse 'CN=b'
275

  
276
    assert_equal -1, n1 <=> n2
277
  end
264 278
end
265 279

  
266 280
end