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

« back to all changes in this revision

Viewing changes to ext/openssl/ossl_x509ext.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_x509ext.c 30320 2010-12-23 12:45:44Z yugui $
 
2
 * $Id: ossl_x509ext.c 31166 2011-03-24 07:29:21Z naruse $
3
3
 * 'OpenSSL for Ruby' project
4
4
 * Copyright (C) 2001-2002  Michal Rokos <m.rokos@sh.cvut.cz>
5
5
 * All rights reserved.
11
11
#include "ossl.h"
12
12
 
13
13
#define WrapX509Ext(klass, obj, ext) do { \
14
 
    if (!ext) { \
 
14
    if (!(ext)) { \
15
15
        ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
16
16
    } \
17
 
    obj = Data_Wrap_Struct(klass, 0, X509_EXTENSION_free, ext); \
 
17
    (obj) = Data_Wrap_Struct((klass), 0, X509_EXTENSION_free, (ext)); \
18
18
} while (0)
19
19
#define GetX509Ext(obj, ext) do { \
20
 
    Data_Get_Struct(obj, X509_EXTENSION, ext); \
21
 
    if (!ext) { \
 
20
    Data_Get_Struct((obj), X509_EXTENSION, (ext)); \
 
21
    if (!(ext)) { \
22
22
        ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
23
23
    } \
24
24
} while (0)
25
25
#define SafeGetX509Ext(obj, ext) do { \
26
 
    OSSL_Check_Kind(obj, cX509Ext); \
27
 
    GetX509Ext(obj, ext); \
 
26
    OSSL_Check_Kind((obj), cX509Ext); \
 
27
    GetX509Ext((obj), (ext)); \
28
28
} while (0)
29
29
#define MakeX509ExtFactory(klass, obj, ctx) do { \
30
 
    if (!(ctx = OPENSSL_malloc(sizeof(X509V3_CTX)))) \
 
30
    if (!((ctx) = OPENSSL_malloc(sizeof(X509V3_CTX)))) \
31
31
        ossl_raise(rb_eRuntimeError, "CTX wasn't allocated!"); \
32
 
    X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, 0); \
33
 
    obj = Data_Wrap_Struct(klass, 0, ossl_x509extfactory_free, ctx); \
 
32
    X509V3_set_ctx((ctx), NULL, NULL, NULL, NULL, 0); \
 
33
    (obj) = Data_Wrap_Struct((klass), 0, ossl_x509extfactory_free, (ctx)); \
34
34
} while (0)
35
35
#define GetX509ExtFactory(obj, ctx) do { \
36
 
    Data_Get_Struct(obj, X509V3_CTX, ctx); \
37
 
    if (!ctx) { \
 
36
    Data_Get_Struct((obj), X509V3_CTX, (ctx)); \
 
37
    if (!(ctx)) { \
38
38
        ossl_raise(rb_eRuntimeError, "CTX wasn't initialized!"); \
39
39
    } \
40
40
} while (0)
270
270
    return obj;
271
271
}
272
272
 
 
273
/*
 
274
 * call-seq:
 
275
 *    OpenSSL::X509::Extension.new asn1
 
276
 *    OpenSSL::X509::Extension.new name, value
 
277
 *    OpenSSL::X509::Extension.new name, value, critical
 
278
 *
 
279
 * Creates an X509 extension.
 
280
 *
 
281
 * The extension may be created from +asn1+ data or from an extension +name+
 
282
 * and +value+.  The +name+ may be either an OID or an extension name.  If
 
283
 * +critical+ is true the extension is marked critical.
 
284
 */
273
285
static VALUE
274
286
ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
275
287
{
328
340
        OPENSSL_free(s);
329
341
        ossl_raise(eX509ExtError, NULL);
330
342
    }
331
 
    if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING_LEN(data))){
 
343
    if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING_LENINT(data))){
332
344
        OPENSSL_free(s);
333
345
        ASN1_OCTET_STRING_free(asn1s);
334
346
        ossl_raise(eX509ExtError, NULL);