Allow a crypto::RSAPrivateKey object to be wrapped round a pre-existing
openssl key, as is currently supported for NSS.

Change-Id: I36c848884273fe8e23451259655680b6b7d46a98

BUG=412427

[email protected]

Review URL: https://codereview.chromium.org/559623002

Cr-Commit-Position: refs/heads/master@{#294254}
diff --git a/crypto/rsa_private_key_openssl.cc b/crypto/rsa_private_key_openssl.cc
index 8dcde61..053c4a2 100644
--- a/crypto/rsa_private_key_openssl.cc
+++ b/crypto/rsa_private_key_openssl.cc
@@ -98,6 +98,16 @@
   return result.release();
 }
 
+// static
+RSAPrivateKey* RSAPrivateKey::CreateFromKey(EVP_PKEY* key) {
+  DCHECK(key);
+  if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA)
+    return NULL;
+  RSAPrivateKey* copy = new RSAPrivateKey();
+  copy->key_ = EVP_PKEY_dup(key);
+  return copy;
+}
+
 RSAPrivateKey::RSAPrivateKey()
     : key_(NULL) {
 }