Project

General

Profile

Feature #5787 ยป name-fix.diff

reaperhulk (Paul Kehrer), 12/22/2011 03:30 AM

View differences:

ext/openssl/ossl_x509name.c
229 229
    X509_NAME_ENTRY *entry;
230 230
    int i,entries;
231 231
    char long_name[512];
232
    const char *short_name;
232
    const char *return_name;
233 233
    VALUE ary, ret;
234 234

  
235 235
    GetX509Name(self, name);
......
246 246
	if (!i2t_ASN1_OBJECT(long_name, sizeof(long_name), entry->object)) {
247 247
	    ossl_raise(eX509NameError, NULL);
248 248
	}
249
	short_name = OBJ_nid2sn(OBJ_ln2nid(long_name));
250
	ary = rb_ary_new3(3, rb_str_new2(short_name),
249
	return_name = OBJ_nid2sn(OBJ_ln2nid(long_name));
250
    if (strcmp(return_name,"UNDEF") == 0) {
251
        return_name = &long_name;
252
    }
253
	ary = rb_ary_new3(3, rb_str_new2(return_name),
251 254
        		  rb_str_new((const char *)entry->value->data, entry->value->length),
252 255
        		  INT2FIX(entry->value->type));
253 256
	rb_ary_push(ret, ary);
test/openssl/test_x509name.rb
98 98
    assert_equal(name_from_der.to_s, name.to_s)
99 99
    assert_equal(name_from_der.to_a, name.to_a)
100 100
    assert_equal(name_from_der.to_der, name.to_der)
101

  
102
    dn = [
103
      ["1.2.3.4.5.6.7.8.9.7.5.3.1", "Unknown OID 1"],
104
      ["1.1.2.3.5.8.13.21.34", "Unknown OID 2"],
105
      ["C", "US"],
106
      ["postalCode", "60602"],
107
      ["ST", "Illinois"],
108
      ["L", "Chicago"],
109
      ["street", "123 Fake St"],
110
      ["O", "Some Company, LLC"],
111
      ["CN", "mydomain.com"]
112
    ]
113
    name = OpenSSL::X509::Name.new(dn)
114
    ary = name.to_a
115
    assert_equal("/1.2.3.4.5.6.7.8.9.7.5.3.1=Unknown OID 1/1.1.2.3.5.8.13.21.34=Unknown OID 2/C=US/postalCode=60602/ST=Illinois/L=Chicago/street=123 Fake St/O=Some Company, LLC/CN=mydomain.com", name.to_s)
116
    assert_equal("1.2.3.4.5.6.7.8.9.7.5.3.1", ary[0][0])
117
    assert_equal("1.1.2.3.5.8.13.21.34", ary[1][0])
118
    assert_equal("C", ary[2][0])
119
    assert_equal("postalCode", ary[3][0])
120
    assert_equal("ST", ary[4][0])
121
    assert_equal("L", ary[5][0])
122
    assert_equal("street", ary[6][0])
123
    assert_equal("O", ary[7][0])
124
    assert_equal("CN", ary[8][0])
125
    assert_equal("Unknown OID 1", ary[0][1])
126
    assert_equal("Unknown OID 2", ary[1][1])
127
    assert_equal("US", ary[2][1])
128
    assert_equal("60602", ary[3][1])
129
    assert_equal("Illinois", ary[4][1])
130
    assert_equal("Chicago", ary[5][1])
131
    assert_equal("123 Fake St", ary[6][1])
132
    assert_equal("Some Company, LLC", ary[7][1])
133
    assert_equal("mydomain.com", ary[8][1])
101 134
  end
102 135

  
103 136
  def test_s_parse