~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/openssl/ossl_x509name.c

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: ossl_x509name.c 31792 2011-05-29 22:48:34Z yugui $
 
2
 * $Id: ossl_x509name.c 32213 2011-06-23 13:51:55Z nahi $
3
3
 * 'OpenSSL for Ruby' project
4
4
 * Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz>
5
5
 * All rights reserved.
11
11
#include "ossl.h"
12
12
 
13
13
#define WrapX509Name(klass, obj, name) do { \
14
 
    if (!name) { \
 
14
    if (!(name)) { \
15
15
        ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
16
16
    } \
17
 
    obj = Data_Wrap_Struct(klass, 0, X509_NAME_free, name); \
 
17
    (obj) = Data_Wrap_Struct((klass), 0, X509_NAME_free, (name)); \
18
18
} while (0)
19
19
#define GetX509Name(obj, name) do { \
20
 
    Data_Get_Struct(obj, X509_NAME, name); \
21
 
    if (!name) { \
 
20
    Data_Get_Struct((obj), X509_NAME, (name)); \
 
21
    if (!(name)) { \
22
22
        ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
23
23
    } \
24
24
} while (0)
25
25
#define SafeGetX509Name(obj, name) do { \
26
 
    OSSL_Check_Kind(obj, cX509Name); \
27
 
    GetX509Name(obj, name); \
 
26
    OSSL_Check_Kind((obj), cX509Name); \
 
27
    GetX509Name((obj), (name)); \
28
28
} while (0)
29
29
 
30
30
#define OBJECT_TYPE_TEMPLATE \
89
89
 
90
90
static ID id_aref;
91
91
static VALUE ossl_x509name_add_entry(int, VALUE*, VALUE);
92
 
#define rb_aref(obj, key) rb_funcall(obj, id_aref, 1, key)
 
92
#define rb_aref(obj, key) rb_funcall((obj), id_aref, 1, (key))
93
93
 
94
94
static VALUE
95
95
ossl_x509name_init_i(VALUE i, VALUE args)
167
167
    if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
168
168
    GetX509Name(self, name);
169
169
    if (!X509_NAME_add_entry_by_txt(name, RSTRING_PTR(oid), NUM2INT(type),
170
 
                (const unsigned char *)RSTRING_PTR(value), RSTRING_LEN(value), -1, 0)) {
 
170
                (const unsigned char *)RSTRING_PTR(value), RSTRING_LENINT(value), -1, 0)) {
171
171
        ossl_raise(eX509NameError, NULL);
172
172
    }
173
173
 
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
{
292
300
/*
293
301
 * call-seq:
294
302
 *    name.hash => integer
 
303
 *
 
304
 * The hash value returned is suitable for use as a certificate's filename in
 
305
 * a CA path.
295
306
 */
296
307
static VALUE
297
308
ossl_x509name_hash(VALUE self)
306
317
    return ULONG2NUM(hash);
307
318
}
308
319
 
 
320
#ifdef HAVE_X509_NAME_HASH_OLD
 
321
/*
 
322
 * call-seq:
 
323
 *    name.hash_old => integer
 
324
 *
 
325
 * hash_old returns MD5 based hash used in OpenSSL 0.9.X.
 
326
 */
 
327
static VALUE
 
328
ossl_x509name_hash_old(VALUE self)
 
329
{
 
330
    X509_NAME *name;
 
331
    unsigned long hash;
 
332
 
 
333
    GetX509Name(self, name);
 
334
 
 
335
    hash = X509_NAME_hash_old(name);
 
336
 
 
337
    return ULONG2NUM(hash);
 
338
}
 
339
#endif
 
340
 
309
341
/*
310
342
 * call-seq:
311
343
 *    name.to_der => string
342
374
    eX509NameError = rb_define_class_under(mX509, "NameError", eOSSLError);
343
375
    cX509Name = rb_define_class_under(mX509, "Name", rb_cObject);
344
376
 
 
377
    rb_include_module(cX509Name, rb_mComparable);
 
378
 
345
379
    rb_define_alloc_func(cX509Name, ossl_x509name_alloc);
346
380
    rb_define_method(cX509Name, "initialize", ossl_x509name_initialize, -1);
347
381
    rb_define_method(cX509Name, "add_entry", ossl_x509name_add_entry, -1);
351
385
    rb_define_alias(cX509Name, "<=>", "cmp");
352
386
    rb_define_method(cX509Name, "eql?", ossl_x509name_eql, 1);
353
387
    rb_define_method(cX509Name, "hash", ossl_x509name_hash, 0);
 
388
#ifdef HAVE_X509_NAME_HASH_OLD
 
389
    rb_define_method(cX509Name, "hash_old", ossl_x509name_hash_old, 0);
 
390
#endif
354
391
    rb_define_method(cX509Name, "to_der", ossl_x509name_to_der, 0);
355
392
 
356
393
    utf8str = INT2NUM(V_ASN1_UTF8STRING);