Browse Source

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>
stable-4.0
David Pletcher 10 years ago
parent
commit
fe7c556f34
  1. 15
      org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java

15
org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java

@ -99,9 +99,7 @@ public class HMACSHA1NonceGenerator implements NonceGenerator {
} 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 @@ public class HMACSHA1NonceGenerator implements NonceGenerator {
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();
}
}

Loading…
Cancel
Save