]> source.dussan.org Git - jgit.git/commitdiff
Fix an invalid format string 83/43483/3
authorDavid Pletcher <dpletcher@google.com>
Mon, 9 Mar 2015 21:48:32 +0000 (14:48 -0700)
committerDavid Pletcher <dpletcher@google.com>
Mon, 9 Mar 2015 22:47:01 +0000 (15:47 -0700)
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>
org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java

index c24784771c1c144294e8ad9489c1ebe146b2a2c1..222ca55d5cd2bdffc2feda44540ffdf8ec33dbc3 100644 (file)
@@ -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();
+       }
 }