summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_pkey_dsa.c
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-08 12:30:37 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-08 12:30:37 +0000
commitcc8ee0ad14c9dc3100229c7a238debae8f42445f (patch)
tree153e28be0b43104e98aa68bdce63aa3bdb0e58f9 /ext/openssl/ossl_pkey_dsa.c
parent1dc3b10764a93c469d8ae24b683849f1b8ceb6c5 (diff)
* 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/branches/ruby_1_8@5418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_pkey_dsa.c')
-rw-r--r--ext/openssl/ossl_pkey_dsa.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/ext/openssl/ossl_pkey_dsa.c b/ext/openssl/ossl_pkey_dsa.c
index 8da71a0..9c04a44 100644
--- a/ext/openssl/ossl_pkey_dsa.c
+++ b/ext/openssl/ossl_pkey_dsa.c
@@ -140,7 +140,8 @@ ossl_dsa_initialize(int argc, VALUE *argv, VALUE self)
arg = ossl_to_der_if_possible(arg);
in = ossl_obj2bio(arg);
dsa = PEM_read_bio_DSAPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
- if (!dsa) { BIO_reset(in);
+ if (!dsa) {
+ BIO_reset(in);
dsa = PEM_read_bio_DSAPublicKey(in, NULL, NULL, NULL);
}
if (!dsa) {
@@ -227,6 +228,31 @@ ossl_dsa_export(int argc, VALUE *argv, VALUE self)
return str;
}
+static VALUE
+ossl_dsa_to_der(VALUE self)
+{
+ EVP_PKEY *pkey;
+ int (*i2d_func)_((DSA*, unsigned char**));
+ unsigned char *p;
+ long len;
+ VALUE str;
+
+ GetPKeyDSA(self, pkey);
+ if(DSA_HAS_PRIVATE(pkey->pkey.dsa))
+ i2d_func = (int(*)_((DSA*,unsigned char**)))i2d_DSAPrivateKey;
+ else
+ i2d_func = i2d_DSA_PUBKEY;
+ if((len = i2d_func(pkey->pkey.dsa, NULL)) <= 0)
+ ossl_raise(eDSAError, NULL);
+ str = rb_str_new(0, len);
+ p = RSTRING(str)->ptr;
+ if(i2d_func(pkey->pkey.dsa, &p) < 0)
+ ossl_raise(eDSAError, NULL);
+ ossl_str_adjust(str, p);
+
+ return str;
+}
+
/*
* Stores all parameters of key to the hash
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
@@ -363,6 +389,7 @@ Init_ossl_dsa()
rb_define_method(cDSA, "export", ossl_dsa_export, -1);
rb_define_alias(cDSA, "to_pem", "export");
rb_define_alias(cDSA, "to_s", "export");
+ rb_define_method(cDSA, "to_der", ossl_dsa_to_der, 0);
rb_define_method(cDSA, "public_key", ossl_dsa_to_public_key, 0);
rb_define_method(cDSA, "syssign", ossl_dsa_sign, 1);
rb_define_method(cDSA, "sysverify", ossl_dsa_verify, 2);