Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 979f9f99 authored by Satoshi Kataoka's avatar Satoshi Kataoka Committed by Android (Google) Code Review
Browse files

Merge "Consolidate hex string utils"

parents 221929c6 3894a559
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -370,12 +370,19 @@ public final class StringUtils {
        return sb.toString();
    }

    /**
     * Convert hex string to byte array. The string length must be an even number.
     */
    @UsedForTesting
    public static byte[] hexStringToByteArray(String hexString) {
        if (TextUtils.isEmpty(hexString)) {
            return null;
        }
        final int N = hexString.length();
        if (N % 2 != 0) {
            throw new NumberFormatException("Input hex string length must be an even number."
                    + " Length = " + N);
        }
        final byte[] bytes = new byte[N / 2];
        for (int i = 0; i < N; i += 2) {
            bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)