summaryrefslogtreecommitdiffstats
path: root/ext/openssl/ossl_pkey_dh.c
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@ruby-lang.org>2004-01-08 12:24:22 +0000
committergotoyuzo <gotoyuzo@ruby-lang.org>2004-01-08 12:24:22 +0000
commitca4f574c6dfcff523572b2ff7f8c119d4605299c (patch)
treea12f072b856ee41638b0a7b1eafa27b9a1991eeb /ext/openssl/ossl_pkey_dh.c
parent3168175690d6cc8ad35e52d85ca1224c7a413d82 (diff)
downloadruby-openssl-history-ca4f574c6dfcff523572b2ff7f8c119d4605299c.tar.gz
* ext/openssl/ossl_pkey.c (ossl_pkey_to_der): removed; it returns
public key only. * ext/openssl/ossl_pkey_dh.c (ossl_dh_to_der): new function for OpenSSL::PKey::DH#to_der. * ext/openssl/ossl_pkey_dsa.c (ossl_dsa_to_der): new function for OpenSSL::PKey::DSA#to_der. * ext/openssl/ossl_pkey_rsa.c (ossl_rsa_to_der): new function for OpenSSL::PKey::RSA#to_der. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_pkey_dh.c')
-rw-r--r--ext/openssl/ossl_pkey_dh.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ext/openssl/ossl_pkey_dh.c b/ext/openssl/ossl_pkey_dh.c
index e4823a2..5b91386 100644
--- a/ext/openssl/ossl_pkey_dh.c
+++ b/ext/openssl/ossl_pkey_dh.c
@@ -199,6 +199,26 @@ ossl_dh_export(VALUE self)
return str;
}
+static VALUE
+ossl_dh_to_der(VALUE self)
+{
+ EVP_PKEY *pkey;
+ unsigned char *p;
+ long len;
+ VALUE str;
+
+ GetPKeyDH(self, pkey);
+ if((len = i2d_DHparams(pkey->pkey.dh, NULL)) <= 0)
+ ossl_raise(eDHError, NULL);
+ str = rb_str_new(0, len);
+ p = RSTRING(str)->ptr;
+ if(i2d_DHparams(pkey->pkey.dh, &p) < 0)
+ ossl_raise(eDHError, NULL);
+ ossl_str_adjust(str, p);
+
+ return str;
+}
+
/*
* Stores all parameters of key to the hash
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
@@ -341,6 +361,7 @@ Init_ossl_dh()
rb_define_method(cDH, "export", ossl_dh_export, 0);
rb_define_alias(cDH, "to_pem", "export");
rb_define_alias(cDH, "to_s", "export");
+ rb_define_method(cDH, "to_der", ossl_dh_to_der, 0);
rb_define_method(cDH, "public_key", ossl_dh_to_public_key, 0);
rb_define_method(cDH, "params_ok?", ossl_dh_check_params, 0);