Skip to content

Commit

Permalink
Output leading zeroes in maven export checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
dmivankov committed Aug 25, 2020
1 parent aed0eb3 commit c09d434
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ private static CompletableFuture<Void> upload(
}

private static String toSha1(byte[] toHash) {
return toHexS("SHA-1", toHash);
return toHexS("%040x", "SHA-1", toHash);
}

private static String toMd5(byte[] toHash) {
return toHexS("MD5", toHash);
return toHexS("%032x", "MD5", toHash);
}

private static String toHexS(String algorithm, byte[] toHash) {
private static String toHexS(String fmt, String algorithm, byte[] toHash) {
try {
MessageDigest digest = MessageDigest.getInstance(algorithm);
digest.update(toHash);
return new BigInteger(1, digest.digest()).toString(16);
return String.format(fmt, new BigInteger(1, digest.digest()));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit c09d434

Please sign in to comment.