Make KeyFactory.translateKey for OpenSSL keys a no-op.

There's no need for the OpenSSL-backed KeyFactory.translateKey to
create copies of Key instances which are already backed by OpenSSL.

(cherry picked from commit 3fb32505a22a01c95ff82435ac7f4d6da001c11c)

Change-Id: I49322aa2d29e44a06e6bd35aed3aebc0ea70a3f9
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLDSAKeyFactory.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLDSAKeyFactory.java
index ca9f37c..efa4747 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLDSAKeyFactory.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLDSAKeyFactory.java
@@ -141,8 +141,9 @@
         if (key == null) {
             throw new InvalidKeyException("key == null");
         }
-
-        if (key instanceof DSAPublicKey) {
+        if ((key instanceof OpenSSLDSAPublicKey) || (key instanceof OpenSSLDSAPrivateKey)) {
+            return key;
+        } else if (key instanceof DSAPublicKey) {
             DSAPublicKey dsaKey = (DSAPublicKey) key;
 
             BigInteger y = dsaKey.getY();
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLECKeyFactory.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLECKeyFactory.java
index 16d4e64..e4673a5 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLECKeyFactory.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLECKeyFactory.java
@@ -133,8 +133,9 @@
         if (key == null) {
             throw new InvalidKeyException("key == null");
         }
-
-        if (key instanceof ECPublicKey) {
+        if ((key instanceof OpenSSLECPublicKey) || (key instanceof OpenSSLECPrivateKey)) {
+            return key;
+        } else if (key instanceof ECPublicKey) {
             ECPublicKey ecKey = (ECPublicKey) key;
 
             ECPoint w = ecKey.getW();
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLRSAKeyFactory.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLRSAKeyFactory.java
index c61223d..9c61abd 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLRSAKeyFactory.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLRSAKeyFactory.java
@@ -165,7 +165,9 @@
             throw new InvalidKeyException("key == null");
         }
 
-        if (key instanceof RSAPublicKey) {
+        if ((key instanceof OpenSSLRSAPublicKey) || (key instanceof OpenSSLRSAPrivateKey)) {
+            return key;
+        } else if (key instanceof RSAPublicKey) {
             RSAPublicKey rsaKey = (RSAPublicKey) key;
 
             try {