From a87de29538d1e33302c9dbf4cd83fd0f926b9538 Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Fri, 22 Jul 2011 10:25:46 +0800 Subject: [PATCH] 6330275: Rework the PaddingTest regression test Reviewed-by: wetmore, smarks --- jdk/test/ProblemList.txt | 3 - .../provider/Cipher/DES/PaddingTest.java | 130 +++++++----------- 2 files changed, 52 insertions(+), 81 deletions(-) diff --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt index a5a5312b040..2b9eaa9dc4a 100644 --- a/jdk/test/ProblemList.txt +++ b/jdk/test/ProblemList.txt @@ -537,9 +537,6 @@ sun/security/krb5/auto/basic.sh solaris-sparc sun/security/provider/PolicyFile/getinstance/getinstance.sh solaris-sparc sun/security/tools/jarsigner/samename.sh solaris-sparc -# Timed out, Solaris 10 64bit sparcv9 -com/sun/crypto/provider/Cipher/DES/PaddingTest.java generic-all - # Othervm, sparc, NoRouteToHostException: Cannot assign requested address sun/security/ssl/javax/net/ssl/NewAPIs/SessionCacheSizeTests.java generic-all diff --git a/jdk/test/com/sun/crypto/provider/Cipher/DES/PaddingTest.java b/jdk/test/com/sun/crypto/provider/Cipher/DES/PaddingTest.java index fa61e3f94ab..bbd6621447e 100644 --- a/jdk/test/com/sun/crypto/provider/Cipher/DES/PaddingTest.java +++ b/jdk/test/com/sun/crypto/provider/Cipher/DES/PaddingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,16 +23,17 @@ /* * @test - * @bug 0000000 6296075 + * @bug 0000000 6296075 6330275 * @summary PaddingTest * @author Jan Luehe */ import java.io.*; -import java.security.*; +import java.nio.file.Files; +import java.nio.file.Paths; import java.security.spec.*; import javax.crypto.*; import javax.crypto.spec.*; -import com.sun.crypto.provider.*; +import java.util.Arrays; public class PaddingTest { @@ -80,7 +81,7 @@ public class PaddingTest { public void run() throws Exception { for (int l=0; l 0) { - totalInputLen += len; - byte[] output = cipher.update(input, 0, len); - cout.write(output, 0, output.length); - cout.flush(); + while ((len = pin.read(input, 0, bufferLen)) > 0) { + totalInputLen += len; + byte[] output = cipher.update(input, 0, len); + cout.write(output, 0, output.length); + } + + len = cipher.getOutputSize(0); + + byte[] out = new byte[len]; + len = cipher.doFinal(out, 0); + cout.write(out, 0, len); } - len = cipher.getOutputSize(0); + try (FileInputStream fin = new FileInputStream(cfile); + BufferedInputStream cin = new BufferedInputStream(fin); + FileOutputStream fout = new FileOutputStream(poutfile); + BufferedOutputStream pout = new BufferedOutputStream(fout)) { + cipher.init(Cipher.DECRYPT_MODE, cipherKey, params); - byte[] out = new byte[len]; - len = cipher.doFinal(out, 0); - cout.write(out, 0, len); - cout.flush(); + byte[] output = null; + while ((len = cin.read(input, 0, bufferLen)) > 0) { + output = cipher.update(input, 0, len); + pout.write(output, 0, output.length); + } - cin = new BufferedInputStream(new FileInputStream(cfile)); - pout = new BufferedOutputStream(new FileOutputStream(poutfile)); - cipher.init(Cipher.DECRYPT_MODE, cipherKey, params); - - byte[] output = null; - while ((len = cin.read(input, 0, bufferLen)) > 0) { - output = cipher.update(input, 0, len); - pout.write(output, 0, output.length); - pout.flush(); + len = cipher.getOutputSize(0); + byte[] out = new byte[len]; + len = cipher.doFinal(out, 0); + pout.write(out, 0, len); } - len = cipher.getOutputSize(0); - out = new byte[len]; - len = cipher.doFinal(out, 0); - pout.write(out, 0, len); - pout.flush(); - - Process child = Runtime.getRuntime().exec - ("diff " + pinfile + " " + poutfile); - InputStream in = child.getInputStream(); - byte[] data = new byte[64]; - - while((len = in.read(data)) != -1) - System.out.write(data, 0, len); - in.close(); - child.waitFor(); - System.out.println("child exited with " + child.exitValue()); - } - catch (IllegalBlockSizeException ex) { - if ((totalInputLen % 8 != 0) && (padding.equals("NoPadding"))) + diff(pinfile, poutfile); + } catch (IllegalBlockSizeException ex) { + if ((totalInputLen % 8 != 0) && (padding.equals("NoPadding"))) { return; - else { + } else { System.out.println("Test failed!"); throw ex; } } - finally { - try { - if (pin != null) - pin.close(); - if (pout != null) - pout.close(); - if (cin != null) - cin.close(); - if (cout != null) - cout.close(); - } - catch (IOException e) { - e.printStackTrace(); - return; - } - } } + private static void diff(String fname1, String fname2) throws Exception { + if (!Arrays.equals(Files.readAllBytes(Paths.get(fname1)), + Files.readAllBytes(Paths.get(fname1)))) { + throw new Exception( + "files " + fname1 + " and " + fname2 + " differ"); + } + } }