Merge branch '2.3.x'

Closes gh-23134
This commit is contained in:
Scott Frederick 2020-08-28 17:04:57 -05:00
commit b70d0dd5ac
2 changed files with 11 additions and 1 deletions

View File

@ -98,7 +98,7 @@ public final class LayerId {
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));
String hash = String.format("%064x", new BigInteger(1, digest));
return new LayerId(algorithm + ":" + hash, algorithm, hash);
}

View File

@ -18,6 +18,7 @@ package org.springframework.boot.buildpack.platform.docker.type;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
@ -67,6 +68,15 @@ class LayerIdTests {
assertThat(id.toString()).isEqualTo("sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
}
@Test
void ofSha256DigestWithZeroPadding() {
byte[] digest = new byte[32];
Arrays.fill(digest, (byte) 127);
digest[0] = 1;
LayerId id = LayerId.ofSha256Digest(digest);
assertThat(id.toString()).isEqualTo("sha256:017f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f");
}
@Test
void ofSha256DigestWhenNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> LayerId.ofSha256Digest((byte[]) null))