diff a/test/lib/jdk/test/lib/Convert.java b/test/lib/jdk/test/lib/Convert.java --- a/test/lib/jdk/test/lib/Convert.java +++ b/test/lib/jdk/test/lib/Convert.java @@ -22,48 +22,27 @@ */ package jdk.test.lib; import java.math.BigInteger; +import java.util.Hex; import java.security.spec.EdECPoint; /** * Utility class containing conversions between strings, arrays, numeric * values, and other types. */ public class Convert { - // Convert from a byte array to a hexadecimal representation as a string. - public static String byteArrayToHexString(byte[] arr) { - StringBuilder result = new StringBuilder(); - for (int i = 0; i < arr.length; ++i) { - byte curVal = arr[i]; - result.append(Character.forDigit(curVal >> 4 & 0xF, 16)); - result.append(Character.forDigit(curVal & 0xF, 16)); - } - return result.toString(); - } - // Expand a single byte to a byte array public static byte[] byteToByteArray(byte v, int length) { byte[] result = new byte[length]; result[0] = v; return result; } - // Convert a hexadecimal string to a byte array - public static byte[] hexStringToByteArray(String str) { - byte[] result = new byte[str.length() / 2]; - for (int i = 0; i < result.length; i++) { - result[i] = (byte) Character.digit(str.charAt(2 * i), 16); - result[i] <<= 4; - result[i] += Character.digit(str.charAt(2 * i + 1), 16); - } - return result; - } - /* * Convert a hexadecimal string to the corresponding little-ending number * as a BigInteger. The clearHighBit argument determines whether the most * significant bit of the highest byte should be set to 0 in the result. */ @@ -90,11 +69,11 @@ BigInteger y = new BigInteger(1, arr); return new EdECPoint(xOdd, y); } public static EdECPoint hexStringToEdPoint(String str) { - return byteArrayToEdPoint(hexStringToByteArray(str)); + return byteArrayToEdPoint(Hex.decoder().decode(str)); } private static void swap(byte[] arr, int i, int j) { byte tmp = arr[i]; arr[i] = arr[j];