Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / net / android / javatests / src / org / chromium / net / AndroidKeyStoreTestUtil.java
index 460dc50..865b1ef 100644 (file)
@@ -1,31 +1,27 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 package org.chromium.net;
 
-import android.os.Build;
 import android.util.Log;
 
-import java.security.PrivateKey;
-import java.security.PrivateKey;
-import java.security.Signature;
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
 import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.spec.InvalidKeySpecException;
 import java.security.spec.KeySpec;
 import java.security.spec.PKCS8EncodedKeySpec;
-import java.security.KeyStoreException;
-import java.security.spec.InvalidKeySpecException;
-import java.security.NoSuchAlgorithmException;
-
-import org.chromium.base.CalledByNative;
-import org.chromium.base.JNINamespace;
-import org.chromium.net.PrivateKeyType;
 
 @JNINamespace("net::android")
 public class AndroidKeyStoreTestUtil {
 
     private static final String TAG = "AndroidKeyStoreTestUtil";
 
+    private static final DefaultAndroidKeyStore sKeyStore = new DefaultAndroidKeyStore();
     /**
      * Called from native code to create a PrivateKey object from its
      * encoded PKCS#8 representation.
@@ -33,8 +29,7 @@ public class AndroidKeyStoreTestUtil {
      * @return new PrivateKey handle, or null in case of error.
      */
     @CalledByNative
-    public static PrivateKey createPrivateKeyFromPKCS8(int type,
-                                                       byte[] encoded_key) {
+    public static AndroidPrivateKey createPrivateKeyFromPKCS8(int type, byte[] encodedKey) {
         String algorithm = null;
         switch (type) {
             case PrivateKeyType.RSA:
@@ -52,9 +47,9 @@ public class AndroidKeyStoreTestUtil {
 
         try {
             KeyFactory factory = KeyFactory.getInstance(algorithm);
-            KeySpec ks = new PKCS8EncodedKeySpec(encoded_key);
+            KeySpec ks = new PKCS8EncodedKeySpec(encodedKey);
             PrivateKey key = factory.generatePrivate(ks);
-            return key;
+            return sKeyStore.createKey(key);
 
         } catch (NoSuchAlgorithmException e) {
             Log.e(TAG, "Could not create " + algorithm + " factory instance!");