changeset 9230:f6daf5edd956

8143377: Test PKCS8Test.java fails Reviewed-by: coffeys Contributed-by: artem.kosarev@oracle.com
author alexp
date Thu, 21 Apr 2016 17:08:50 +0300
parents e9869356eb8a
children d4e4af750774
files test/sun/security/pkcs/pkcs8/PKCS8Test.java
diffstat 1 files changed, 15 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/security/pkcs/pkcs8/PKCS8Test.java	Wed May 24 17:35:54 2017 +0100
+++ b/test/sun/security/pkcs/pkcs8/PKCS8Test.java	Thu Apr 21 17:08:50 2016 +0300
@@ -25,9 +25,15 @@
  * @test
  * @bug 8048357
  * @summary PKCS8 Standards Conformance Tests
+ * @requires (os.family != "solaris")
  * @compile -XDignore.symbol.file PKCS8Test.java
  * @run main PKCS8Test
  */
+
+/*
+ * Skip Solaris since the DSAPrivateKeys returned by
+ * SunPKCS11 Provider are not subclasses of PKCS8Key
+ */
 import java.io.IOException;
 import java.math.BigInteger;
 import java.security.InvalidKeyException;
@@ -38,7 +44,6 @@
 import sun.security.util.DerOutputStream;
 import sun.security.util.DerValue;
 import sun.security.x509.AlgorithmId;
-
 import static java.lang.System.out;
 
 public class PKCS8Test {
@@ -186,7 +191,14 @@
     public static void main(String[] args)
             throws IOException, InvalidKeyException {
 
-        byte[] encodedKey = getEncodedKey();
+        BigInteger p = BigInteger.valueOf(1);
+        BigInteger q = BigInteger.valueOf(2);
+        BigInteger g = BigInteger.valueOf(3);
+        BigInteger x = BigInteger.valueOf(4);
+
+        DSAPrivateKey priv = new DSAPrivateKey(p, q, g, x);
+
+        byte[] encodedKey = priv.getEncoded();
         byte[] expectedBytes = new byte[EXPECTED.length];
         for (int i = 0; i < EXPECTED.length; i++) {
             expectedBytes[i] = (byte) EXPECTED[i];
@@ -198,6 +210,7 @@
         }
 
         PKCS8Key decodedKey = PKCS8Key.parse(new DerValue(encodedKey));
+
         String alg = decodedKey.getAlgorithm();
         AlgorithmId algId = decodedKey.getAlgorithmId();
         out.println("Algorithm :" + alg);
@@ -260,30 +273,10 @@
                         + EXCEPTION_MESSAGE + " get: " + e.getMessage());
             }
         }
-
-    }
-
-    // get a byte array from somewhere
-    static byte[] getEncodedKey() throws InvalidKeyException {
-        BigInteger p = BigInteger.valueOf(1);
-        BigInteger q = BigInteger.valueOf(2);
-        BigInteger g = BigInteger.valueOf(3);
-        BigInteger x = BigInteger.valueOf(4);
-
-        DSAPrivateKey priv = new DSAPrivateKey(p, q, g, x);
-        return priv.getEncoded();
     }
 
     static void dumpByteArray(String nm, byte[] bytes) throws IOException {
         out.println(nm + " length: " + bytes.length);
         hexDump.encodeBuffer(bytes, out);
     }
-
-    static String toString(PKCS8Key key) {
-        StringBuilder builder = new StringBuilder(key.getAlgorithm());
-        builder.append('\n').append("parameters:")
-                .append(key.getAlgorithmId().toString());
-        return builder.toString();
-    }
-
 }