summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authoremboss <emboss@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-13 20:10:27 +0000
committeremboss <emboss@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-13 20:10:27 +0000
commite16d6108c0420ebe4907b97f0419c9ed1eb4a579 (patch)
tree4dad96479edcadb11896066aa95127ff92cb2efe /ext
parent10219ff6216c9d6459026e9e89ed788e2d440dc5 (diff)
Sat May 14 05:08:32 2011 Martin Bosslet <Martin.Bosslet@googlemail.com>
* ext/openssl/ossl_digest.c * ext/openssl/ossl_pkey.c * ext/openssl/ossl_pkey.h * test/openssl/pkey/test_pkey_rsa.rb Reverted premature commit. Sorry for the noise! Previous revision: 31555 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/openssl/ossl_digest.c2
-rw-r--r--ext/openssl/ossl_pkey.c60
-rw-r--r--ext/openssl/ossl_pkey.h2
3 files changed, 15 insertions, 49 deletions
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index 9f3d2697afd..2b76fe7a49f 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -239,8 +239,6 @@ Init_ossl_digest()
mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
#endif
- /* Allows you to compute cryptographic hashes of arbitrary data.
- */
cDigest = rb_define_class_under(mOSSL, "Digest", rb_path2class("Digest::Class"));
eDigestError = rb_define_class_under(cDigest, "DigestError", eOSSLError);
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c
index d6940acda44..b5047bec261 100644
--- a/ext/openssl/ossl_pkey.c
+++ b/ext/openssl/ossl_pkey.c
@@ -18,9 +18,6 @@ VALUE cPKey;
VALUE ePKeyError;
ID id_private_q;
-#define reset_bio(b) (void)BIO_reset((b)); \
- (void)ERR_get_error();
-
/*
* callback for generating keys
*/
@@ -68,50 +65,23 @@ ossl_pkey_new(EVP_PKEY *pkey)
return Qnil; /* not reached */
}
-/*
- * call-seq:
- * OpenSSL::PKey.read(string [, pwd ] ) -> PKey
- * OpenSSL::PKey.read(file [, pwd ]) -> PKey
- *
- * === Parameters
- * * +string+ is a DER- or PEM-encoded string containing an arbitrary private
- * or public key.
- * * +file+ is an instance of +File+ containing a DER- or PEM-encoded
- * arbitrary private or public key.
- * * +pwd+ is an optional password in case +string+ or +file+ is an encrypted
- * PEM resource.
- */
-VALUE
-ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
+VALUE
+ossl_pkey_new_from_file(VALUE filename)
{
+ FILE *fp;
EVP_PKEY *pkey;
- BIO *bio;
- VALUE data, pass;
- char *passwd = NULL;
-
- rb_scan_args(argc, argv, "11", &data, &pass);
-
- bio = ossl_obj2bio(data);
- if (!(pkey = d2i_PrivateKey_bio(bio, NULL))) {
- reset_bio(bio);
- if (!NIL_P(pass)) {
- passwd = StringValuePtr(pass);
- }
- if (!(pkey = PEM_read_bio_PrivateKey(bio, NULL, ossl_pem_passwd_cb, passwd))) {
- reset_bio(bio);
- if (!(pkey = d2i_PUBKEY_bio(bio, NULL))) {
- reset_bio(bio);
- if (!NIL_P(pass)) {
- passwd = StringValuePtr(pass);
- }
- pkey = PEM_read_bio_PUBKEY(bio, NULL, ossl_pem_passwd_cb, passwd);
- }
- }
+
+ SafeStringValue(filename);
+ if (!(fp = fopen(RSTRING_PTR(filename), "r"))) {
+ ossl_raise(ePKeyError, "%s", strerror(errno));
}
-
- BIO_free(bio);
- if (!pkey)
- ossl_raise(rb_eArgError, "Could not parse PKey");
+
+ pkey = PEM_read_PrivateKey(fp, NULL, ossl_pem_passwd_cb, NULL);
+ fclose(fp);
+ if (!pkey) {
+ ossl_raise(ePKeyError, NULL);
+ }
+
return ossl_pkey_new(pkey);
}
@@ -251,8 +221,6 @@ Init_ossl_pkey()
cPKey = rb_define_class_under(mPKey, "PKey", rb_cObject);
- rb_define_module_function(mPKey, "read", ossl_pkey_new_from_data, -1);
-
rb_define_alloc_func(cPKey, ossl_pkey_alloc);
rb_define_method(cPKey, "initialize", ossl_pkey_initialize, 0);
diff --git a/ext/openssl/ossl_pkey.h b/ext/openssl/ossl_pkey.h
index 4b19164585b..5e3329d3264 100644
--- a/ext/openssl/ossl_pkey.h
+++ b/ext/openssl/ossl_pkey.h
@@ -41,7 +41,7 @@ extern ID id_private_q;
void ossl_generate_cb(int, int, void *);
VALUE ossl_pkey_new(EVP_PKEY *);
-VALUE ossl_pkey_new_from_data(int, VALUE *, VALUE);
+VALUE ossl_pkey_new_from_file(VALUE);
EVP_PKEY *GetPKeyPtr(VALUE);
EVP_PKEY *DupPKeyPtr(VALUE);
EVP_PKEY *GetPrivPKeyPtr(VALUE);