summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-09-06 08:56:09 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-09-06 08:56:09 +0000
commitcf66d4941a075d81d651638d69100dea458bd81b (patch)
tree5fc395099c17ce9fbf3a7f4f95b283c898c7858a /ext
parentc02da8ed26ea04cc5a054267b662f899a7df9411 (diff)
downloadruby-cf66d4941a075d81d651638d69100dea458bd81b.tar.gz
ruby-cf66d4941a075d81d651638d69100dea458bd81b.tar.xz
ruby-cf66d4941a075d81d651638d69100dea458bd81b.zip
* ext/openssl/ruby_missing.c: rid of unnecessary backward
compatibility stuff. and remove DEFINE_ALLOC_WRAPPER from all sources. * ext/openssl/ossl_x509ext.c (X509::Extension.new): new method. * ext/openssl/ossl_x509ext.c (X509::Extension#oid=): new method. * ext/openssl/ossl_x509ext.c (X509::Extension#value=): new method. * ext/openssl/ossl_x509ext.c (X509::Extension#critical=): new method. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/openssl/ossl_bn.c1
-rw-r--r--ext/openssl/ossl_cipher.c1
-rw-r--r--ext/openssl/ossl_digest.c15
-rw-r--r--ext/openssl/ossl_hmac.c1
-rw-r--r--ext/openssl/ossl_ns_spki.c1
-rw-r--r--ext/openssl/ossl_ocsp.c4
-rw-r--r--ext/openssl/ossl_pkcs7.c2
-rw-r--r--ext/openssl/ossl_pkey.c1
-rw-r--r--ext/openssl/ossl_ssl.c2
-rw-r--r--ext/openssl/ossl_x509cert.c1
-rw-r--r--ext/openssl/ossl_x509crl.c1
-rw-r--r--ext/openssl/ossl_x509ext.c90
-rw-r--r--ext/openssl/ossl_x509name.c1
-rw-r--r--ext/openssl/ossl_x509req.c1
-rw-r--r--ext/openssl/ossl_x509revoked.c1
-rw-r--r--ext/openssl/ossl_x509store.c2
16 files changed, 88 insertions, 37 deletions
diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c
index c59d809ba..d81533461 100644
--- a/ext/openssl/ossl_bn.c
+++ b/ext/openssl/ossl_bn.c
@@ -99,7 +99,6 @@ ossl_bn_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_bn_alloc)
static VALUE
ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
diff --git a/ext/openssl/ossl_cipher.c b/ext/openssl/ossl_cipher.c
index 02e3dcd48..b639af203 100644
--- a/ext/openssl/ossl_cipher.c
+++ b/ext/openssl/ossl_cipher.c
@@ -82,7 +82,6 @@ ossl_cipher_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_cipher_alloc)
static VALUE
ossl_cipher_initialize(VALUE self, VALUE str)
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index 8511eccf4..74a7e1b34 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -73,7 +73,6 @@ ossl_digest_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_digest_alloc)
VALUE ossl_digest_update(VALUE, VALUE);
@@ -197,12 +196,7 @@ ossl_digest_hexdigest(VALUE self)
static VALUE
ossl_digest_s_digest(VALUE klass, VALUE str, VALUE data)
{
- VALUE obj =
-#if HAVE_RB_DEFINE_ALLOC_FUNC
- rb_class_new_instance(1, &str, klass);
-#else
- ossl_digest_alloc_wrapper(1, &str, klass);
-#endif
+ VALUE obj = rb_class_new_instance(1, &str, klass);
ossl_digest_update(obj, data);
@@ -212,12 +206,7 @@ ossl_digest_s_digest(VALUE klass, VALUE str, VALUE data)
static VALUE
ossl_digest_s_hexdigest(VALUE klass, VALUE str, VALUE data)
{
- VALUE obj =
-#if HAVE_RB_DEFINE_ALLOC_FUNC
- rb_class_new_instance(1, &str, klass);
-#else
- ossl_digest_alloc_wrapper(1, &str, klass);
-#endif
+ VALUE obj = rb_class_new_instance(1, &str, klass);
ossl_digest_update(obj, data);
diff --git a/ext/openssl/ossl_hmac.c b/ext/openssl/ossl_hmac.c
index 05b6e8120..ffd5ec384 100644
--- a/ext/openssl/ossl_hmac.c
+++ b/ext/openssl/ossl_hmac.c
@@ -55,7 +55,6 @@ ossl_hmac_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_hmac_alloc)
static VALUE
ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
diff --git a/ext/openssl/ossl_ns_spki.c b/ext/openssl/ossl_ns_spki.c
index bcefcbdfd..3932f3e97 100644
--- a/ext/openssl/ossl_ns_spki.c
+++ b/ext/openssl/ossl_ns_spki.c
@@ -50,7 +50,6 @@ ossl_spki_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_spki_alloc)
static VALUE
ossl_spki_initialize(int argc, VALUE *argv, VALUE self)
diff --git a/ext/openssl/ossl_ocsp.c b/ext/openssl/ossl_ocsp.c
index 3ec5c3947..57d9cbee1 100644
--- a/ext/openssl/ossl_ocsp.c
+++ b/ext/openssl/ossl_ocsp.c
@@ -98,7 +98,6 @@ ossl_ocspreq_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_ocspreq_alloc)
static VALUE
ossl_ocspreq_initialize(int argc, VALUE *argv, VALUE self)
@@ -304,7 +303,6 @@ ossl_ocspres_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_ocspreq_alloc)
static VALUE
ossl_ocspres_initialize(int argc, VALUE *argv, VALUE self)
@@ -395,7 +393,6 @@ ossl_ocspbres_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_ocspbres_alloc)
static VALUE
ossl_ocspbres_initialize(int argc, VALUE *argv, VALUE self)
@@ -617,7 +614,6 @@ ossl_ocspcid_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_ocspcid_alloc)
static VALUE
ossl_ocspcid_initialize(VALUE self, VALUE subject, VALUE issuer)
diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c
index c612eb43f..2ebf6d4a7 100644
--- a/ext/openssl/ossl_pkcs7.c
+++ b/ext/openssl/ossl_pkcs7.c
@@ -252,7 +252,6 @@ ossl_pkcs7_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_pkcs7_alloc)
static VALUE
ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
@@ -651,7 +650,6 @@ ossl_pkcs7si_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_pkcs7si_alloc)
static VALUE
ossl_pkcs7si_initialize(VALUE self, VALUE cert, VALUE key, VALUE digest)
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c
index cd73355d6..3121cdbb6 100644
--- a/ext/openssl/ossl_pkey.c
+++ b/ext/openssl/ossl_pkey.c
@@ -119,7 +119,6 @@ ossl_pkey_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_pkey_alloc)
static VALUE
ossl_pkey_initialize(VALUE self)
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 5611f4367..6305e4c99 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -107,7 +107,6 @@ ossl_sslctx_s_alloc(VALUE klass)
SSL_CTX_set_options(ctx, SSL_OP_ALL);
return Data_Wrap_Struct(klass, 0, ossl_sslctx_free, ctx);
}
-DEFINE_ALLOC_WRAPPER(ossl_sslctx_s_alloc)
static VALUE
ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self)
@@ -365,7 +364,6 @@ ossl_ssl_s_alloc(VALUE klass)
{
return Data_Wrap_Struct(klass, 0, ossl_ssl_free, NULL);
}
-DEFINE_ALLOC_WRAPPER(ossl_ssl_s_alloc)
static VALUE
ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
diff --git a/ext/openssl/ossl_x509cert.c b/ext/openssl/ossl_x509cert.c
index b6ed438e0..b689f578d 100644
--- a/ext/openssl/ossl_x509cert.c
+++ b/ext/openssl/ossl_x509cert.c
@@ -124,7 +124,6 @@ ossl_x509_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_x509_alloc)
static VALUE
ossl_x509_initialize(int argc, VALUE *argv, VALUE self)
diff --git a/ext/openssl/ossl_x509crl.c b/ext/openssl/ossl_x509crl.c
index 2c1f9e0cd..517080b32 100644
--- a/ext/openssl/ossl_x509crl.c
+++ b/ext/openssl/ossl_x509crl.c
@@ -86,7 +86,6 @@ ossl_x509crl_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_x509crl_alloc)
static VALUE
ossl_x509crl_initialize(int argc, VALUE *argv, VALUE self)
diff --git a/ext/openssl/ossl_x509ext.c b/ext/openssl/ossl_x509ext.c
index 4d981ed93..d65320311 100644
--- a/ext/openssl/ossl_x509ext.c
+++ b/ext/openssl/ossl_x509ext.c
@@ -116,7 +116,6 @@ ossl_x509extfactory_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_x509extfactory_alloc)
static VALUE
ossl_x509extfactory_set_issuer_cert(VALUE self, VALUE cert)
@@ -244,6 +243,87 @@ ossl_x509extfactory_create_ext_from_array(VALUE self, VALUE ary)
/*
* Ext
*/
+static VALUE
+ossl_x509ext_alloc(VALUE klass)
+{
+ X509_EXTENSION *ext;
+ VALUE obj;
+
+ if(!(ext = X509_EXTENSION_new())){
+ ossl_raise(eX509ExtError, NULL);
+ }
+ WrapX509Ext(klass, obj, ext);
+
+ return obj;
+}
+
+static VALUE
+ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
+{
+ VALUE oid, value, critical;
+
+ rb_scan_args(argc, argv, "21", &oid, &value, &critical);
+ rb_funcall(self, rb_intern("oid="), 1, oid);
+ rb_funcall(self, rb_intern("value="), 1, value);
+ if(argc > 2) rb_funcall(self, rb_intern("critical="), 1, critical);
+
+ return self;
+}
+
+static VALUE
+ossl_x509ext_set_oid(VALUE self, VALUE oid)
+{
+ X509_EXTENSION *ext;
+ ASN1_OBJECT *obj;
+ char *s;
+
+ GetX509Ext(self, ext);
+ s = StringValuePtr(oid);
+ obj = OBJ_txt2obj(s, 0);
+ if(!obj) obj = OBJ_txt2obj(s, 1);
+ if(!obj) ossl_raise(eX509ExtError, NULL);
+ X509_EXTENSION_set_object(ext, obj);
+
+ return oid;
+}
+
+static VALUE
+ossl_x509ext_set_value(VALUE self, VALUE data)
+{
+ X509_EXTENSION *ext;
+ ASN1_OCTET_STRING *asn1s;
+ char *s;
+
+ GetX509Ext(self, ext);
+ StringValue(data);
+ if(!(s = OPENSSL_malloc(RSTRING(data)->len)))
+ ossl_raise(eX509ExtError, "malloc error");
+ memcpy(s, RSTRING(data)->ptr, RSTRING(data)->len);
+ if(!(asn1s = ASN1_OCTET_STRING_new())){
+ free(s);
+ ossl_raise(eX509ExtError, NULL);
+ }
+ if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING(data)->len)){
+ free(s);
+ ASN1_OCTET_STRING_free(asn1s);
+ ossl_raise(eX509ExtError, NULL);
+ }
+ X509_EXTENSION_set_data(ext, asn1s);
+
+ return data;
+}
+
+static VALUE
+ossl_x509ext_set_critical(VALUE self, VALUE flag)
+{
+ X509_EXTENSION *ext;
+
+ GetX509Ext(self, ext);
+ X509_EXTENSION_set_critical(ext, RTEST(flag) ? 1 : 0);
+
+ return flag;
+}
+
static VALUE
ossl_x509ext_get_oid(VALUE obj)
{
@@ -335,9 +415,11 @@ Init_ossl_x509ext()
rb_define_method(cX509ExtFactory, "create_ext_from_array", ossl_x509extfactory_create_ext_from_array, 1);
cX509Ext = rb_define_class_under(mX509, "Extension", rb_cObject);
- rb_undef_method(CLASS_OF(cX509Ext), "new");
-/* rb_define_alloc_func(cX509Ext, ossl_x509ext_alloc); */
-/* rb_define_method(cX509Ext, "initialize", ossl_x509ext_initialize, -1); */
+ rb_define_alloc_func(cX509Ext, ossl_x509ext_alloc);
+ rb_define_method(cX509Ext, "initialize", ossl_x509ext_initialize, -1);
+ rb_define_method(cX509Ext, "oid=", ossl_x509ext_set_oid, 1);
+ rb_define_method(cX509Ext, "value=", ossl_x509ext_set_value, 1);
+ rb_define_method(cX509Ext, "critical=", ossl_x509ext_set_critical, 1);
rb_define_method(cX509Ext, "oid", ossl_x509ext_get_oid, 0);
rb_define_method(cX509Ext, "value", ossl_x509ext_get_value, 0);
rb_define_method(cX509Ext, "critical?", ossl_x509ext_get_critical, 0);
diff --git a/ext/openssl/ossl_x509name.c b/ext/openssl/ossl_x509name.c
index a1e5cba1b..dfc30de40 100644
--- a/ext/openssl/ossl_x509name.c
+++ b/ext/openssl/ossl_x509name.c
@@ -82,7 +82,6 @@ ossl_x509name_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_x509name_alloc)
static VALUE
ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
diff --git a/ext/openssl/ossl_x509req.c b/ext/openssl/ossl_x509req.c
index e7329d158..4830f2ad3 100644
--- a/ext/openssl/ossl_x509req.c
+++ b/ext/openssl/ossl_x509req.c
@@ -84,7 +84,6 @@ ossl_x509req_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_x509req_alloc)
static VALUE
ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
diff --git a/ext/openssl/ossl_x509revoked.c b/ext/openssl/ossl_x509revoked.c
index 1cd04eaa2..30ce75207 100644
--- a/ext/openssl/ossl_x509revoked.c
+++ b/ext/openssl/ossl_x509revoked.c
@@ -84,7 +84,6 @@ ossl_x509revoked_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_x509revoked_alloc)
static VALUE
ossl_x509revoked_initialize(int argc, VALUE *argv, VALUE self)
diff --git a/ext/openssl/ossl_x509store.c b/ext/openssl/ossl_x509store.c
index d001a0278..4c5f0624a 100644
--- a/ext/openssl/ossl_x509store.c
+++ b/ext/openssl/ossl_x509store.c
@@ -102,7 +102,6 @@ ossl_x509store_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_x509store_alloc)
/*
* General callback for OpenSSL verify
@@ -329,7 +328,6 @@ ossl_x509stctx_alloc(VALUE klass)
return obj;
}
-DEFINE_ALLOC_WRAPPER(ossl_x509stctx_alloc)
static VALUE
ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)