Fix an invalid format string

The %x format specifier is not valid for a byte array.
This patch fixes a bug that would cause an IllegalFormatConversionException.

Change-Id: I025975eca7b2f10bbafa39f5519f8668e6536541
Signed-off-by: David Pletcher <dpletcher@google.com>
This commit is contained in:
David Pletcher 2015-03-09 14:48:32 -07:00
parent a8fb77853a
commit fe7c556f34
1 changed files with 12 additions and 3 deletions

View File

@ -99,9 +99,7 @@ else if (repo.getDirectory() != null)
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
String sentNonce = String.format(
"%d-%20X", new Long(timestamp), rawHmac); //$NON-NLS-1$
return sentNonce;
return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$
}
@Override
@ -146,4 +144,15 @@ else if (received.equals(sent))
return NonceStatus.SLOP;
}
}
private static final String HEX = "0123456789ABCDEF"; //$NON-NLS-1$
private static String toHex(byte[] bytes) {
StringBuilder builder = new StringBuilder(2 * bytes.length);
for (byte b : bytes) {
builder.append(HEX.charAt((b & 0xF0) >> 4));
builder.append(HEX.charAt(b & 0xF));
}
return builder.toString();
}
}