Split from #23130

public static LayerId ofSha256Digest(byte[] digest) {
    Assert.notNull(digest, "Digest must not be null");
    Assert.isTrue(digest.length == 32, "Digest must be exactly 32 bytes");
    String algorithm = "sha256";
    String hash = String.format("%32x", new BigInteger(1, digest));
    return new LayerId(algorithm + ":" + hash, algorithm, hash);
}

%32x is actually only guaranteed to be at least 32 characters. We need 64. So sometimes we get 63 because the content of the digest has a low leading byte value. This would probably work (because Java Formatter pads with spaces not zeros, and docker wants zeros):

String hash = String.format("%64x", new BigInteger(1, digest)).replace(" ", "0");

Comment From: philwebb

Looks like we should include a '0' flag. I think "%032x" might work.