Path: blob/master/test/jdk/com/sun/crypto/provider/CICO/TestUtilities.java
41155 views
/*1* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* utility class25*/2627public class TestUtilities {28public static boolean equalsBlock(byte[] b1, byte[] b2, int len) {29for (int i = 0; i < len; i++) {30if (b1[i] != b2[i]) {31System.err.println("b1[" + i + "] : " + b1[i]32+ " b2[" + i + "] : " + b2[i]);33return false;34}35}36return true;37}3839public static boolean equals(byte[] b1, byte[] b2) {40if (b2.length != b1.length) {41System.err.println("b1.length = " + b1.length42+ " b2.length = " + b2.length );43return false;44}45return equalsBlock(b1, b2, b1.length);46}4748/**49* Verify b1's partial part is same as b2. compares b1 and b2 by chopping up50* b1 into blocks of b1BKSize and b2 into blocks of b2BKSize, and then51* compare the first b2BKSize bytes of each block, return true if they equal52* , otherwise return false.53* @param b1 byte array to be compared.54* @param b2 saved byte array.55* @param b1BKSize b1's block size.56* @param b2BKSize b2's block size.57* @return true is same. false otherwise.58*/59public static boolean equalsBlockPartial(byte[] b1, byte[] b2, int b1BKSize,60int b2BKSize) {61int numOfBlock = b1.length / b1BKSize;62for (int b = 0; b < numOfBlock; b++) {63for (int i = 0; i < b2BKSize; i++) {64int j1 = b * b1BKSize + i;65int j2 = b * b2BKSize + i;66if (b1[j1] != b2[j2]) {67System.err.println("Compare failed at b1[" + j1 + "]:" +68b1[j1] + " b2[" + j2 + "]:" + b2[j2]);69return false;70}71}72}73return true;74}7576/**77* Generate a byte block by given length. The content of byte block78* is determined by the index.79* @param length length of byte array80* @return a byte array81*/82public static byte[] generateBytes(int length) {83byte[] bytes = new byte[length];84for (int i = 0; i < length; i++) {85bytes[i] = (byte) (i & 0xff);86}87return bytes;88}89}909192