summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_x509req.c
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-13 07:48:20 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-13 07:48:20 +0000
commita3845916c0b78bab4adee895ba1b91ddb19d859e (patch)
treeb8f5b2036f970066fff5f2c71917db5d987f3e53 /ext/openssl/ossl_x509req.c
parent06a9101158bdc683d1273972ecc875ee2ee8feda (diff)
* ext/openssl/ossl_x509req.c (ossl_x509req_to_der): add function for
X509::Request#to_der. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_x509req.c')
-rw-r--r--ext/openssl/ossl_x509req.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ext/openssl/ossl_x509req.c b/ext/openssl/ossl_x509req.c
index 3585b20..c532739 100644
--- a/ext/openssl/ossl_x509req.c
+++ b/ext/openssl/ossl_x509req.c
@@ -159,6 +159,26 @@ ossl_x509req_to_pem(VALUE self)
return str;
}
+static VALUE
+ossl_x509req_to_der(VALUE self)
+{
+ X509_REQ *req;
+ VALUE str;
+ long len;
+ unsigned char *p;
+
+ GetX509Req(self, req);
+ if ((len = i2d_X509_REQ(req, NULL)) <= 0)
+ ossl_raise(eX509CertError, NULL);
+ str = rb_str_new(0, len);
+ p = RSTRING(str)->ptr;
+ if (i2d_X509_REQ(req, &p) <= 0)
+ ossl_raise(eX509ReqError, NULL);
+ ossl_str_adjust(str, p);
+
+ return str;
+}
+
static VALUE
ossl_x509req_to_text(VALUE self)
{
@@ -427,6 +447,7 @@ Init_ossl_x509req()
rb_define_copy_func(cX509Req, ossl_x509req_copy);
rb_define_method(cX509Req, "to_pem", ossl_x509req_to_pem, 0);
+ rb_define_method(cX509Req, "to_der", ossl_x509req_to_der, 0);
rb_define_alias(cX509Req, "to_s", "to_pem");
rb_define_method(cX509Req, "to_text", ossl_x509req_to_text, 0);
rb_define_method(cX509Req, "version", ossl_x509req_get_version, 0);