summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
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 c59d809bae2..d8153346131 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 02e3dcd4887..b639af2035e 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 8511eccf4e2..74a7e1b3487 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 05b6e812025..ffd5ec38411 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 bcefcbdfde4..3932f3e9710 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 3ec5c39472d..57d9cbee18b 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 c612eb43ff9..2ebf6d4a7b0 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 cd73355d66b..3121cdbb6a0 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 5611f436790..6305e4c9980 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 b6ed438e0f5..b689f578dc0 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 2c1f9e0cdb6..517080b32de 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 4d981ed9383..d65320311a3 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 a1e5cba1b4f..dfc30de405a 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 e7329d158b0..4830f2ad347 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 1cd04eaa25d..30ce75207f3 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 d001a02787c..4c5f0624a9e 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)