aboutsummaryrefslogtreecommitdiffstats
path: root/ossl_x509.c
diff options
context:
space:
mode:
authorMichal Rokos <m.rokos@sh.cvut.cz>2001-11-19 12:44:57 +0000
committerMichal Rokos <m.rokos@sh.cvut.cz>2001-11-19 12:44:57 +0000
commitcceffafefe8d78e8b7b8d0c4563ec0d48f44eed3 (patch)
treefd1286c83be09812fd97b3ac0b58f15ce374fa00 /ossl_x509.c
parentdd5dc9508d397e96ee4aa849f411567e78b49e32 (diff)
downloadruby-openssl-history-cceffafefe8d78e8b7b8d0c4563ec0d48f44eed3.tar.gz
added X509::Certificate .to_der
Diffstat (limited to 'ossl_x509.c')
-rw-r--r--ossl_x509.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/ossl_x509.c b/ossl_x509.c
index 739455e..cd8074d 100644
--- a/ossl_x509.c
+++ b/ossl_x509.c
@@ -135,6 +135,29 @@ static VALUE ossl_x509_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
+static VALUE ossl_x509_to_der(VALUE self)
+{
+ ossl_x509 *x509p = NULL;
+ BIO *out = NULL;
+ BUF_MEM *buf = NULL;
+ VALUE str;
+
+ GetX509(self, x509p);
+
+ if (!(out = BIO_new(BIO_s_mem()))) {
+ rb_raise(eX509CertificateError, "%s", ossl_error());
+ }
+ if (!i2d_X509_bio(out, x509p->x509)) {
+ BIO_free(out);
+ rb_raise(eX509CertificateError, "%s", ossl_error());
+ }
+ BIO_get_mem_ptr(out, &buf);
+ str = rb_str_new(buf->data, buf->length);
+ BIO_free(out);
+
+ return str;
+}
+
static VALUE ossl_x509_to_pem(VALUE self)
{
ossl_x509 *x509p = NULL;
@@ -590,6 +613,7 @@ void Init_ossl_x509(VALUE mX509)
cX509Certificate = rb_define_class_under(mX509, "Certificate", rb_cObject);
rb_define_singleton_method(cX509Certificate, "new", ossl_x509_s_new, -1);
rb_define_method(cX509Certificate, "initialize", ossl_x509_initialize, -1);
+ rb_define_method(cX509Certificate, "to_der", ossl_x509_to_der, 0);
rb_define_method(cX509Certificate, "to_pem", ossl_x509_to_pem, 0);
rb_define_method(cX509Certificate, "to_str", ossl_x509_to_str, 0);
rb_define_method(cX509Certificate, "version", ossl_x509_get_version, 0);