Path: blob/master/test/jdk/com/sun/crypto/provider/Cipher/DES/TestUtility.java
41161 views
/*1* Copyright (c) 1997, 2007, 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 TestUtility {2829private static final String DIGITS = "0123456789abcdef";3031private TestUtility() {3233}3435public static String hexDump(byte[] bytes) {3637StringBuilder buf = new StringBuilder(bytes.length * 2);38int i;3940buf.append(" "); // four spaces41for (i = 0; i < bytes.length; i++) {42buf.append(DIGITS.charAt(bytes[i] >> 4 & 0x0f));43buf.append(DIGITS.charAt(bytes[i] & 0x0f));44if ((i + 1) % 32 == 0) {45if (i + 1 != bytes.length) {46buf.append("\n "); // line after four words47}48} else if ((i + 1) % 4 == 0) {49buf.append(' '); // space between words50}51}52return buf.toString();53}5455public static String hexDump(byte[] bytes, int index) {56StringBuilder buf = new StringBuilder(bytes.length * 2);57int i;5859buf.append(" "); // four spaces60buf.append(DIGITS.charAt(bytes[index] >> 4 & 0x0f));61buf.append(DIGITS.charAt(bytes[index] & 0x0f));62return buf.toString();63}6465public static boolean equalsBlock(byte[] b1, byte[] b2) {6667if (b1.length != b2.length) {68return false;69}7071for (int i = 0; i < b1.length; i++) {72if (b1[i] != b2[i]) {73return false;74}75}7677return true;78}7980public static boolean equalsBlock(byte[] b1, byte[] b2, int len) {8182for (int i = 0; i < len; i++) {83if (b1[i] != b2[i]) {84return false;85}86}8788return true;89}9091}929394