diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java index 830835c7..be27ffd5 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java @@ -11,8 +11,8 @@ import java.io.InputStream; import java.net.URL; import java.nio.file.Path; +import java.util.Arrays; import java.util.Map; -import java.util.Objects; public final class Texture extends StreamObject { private static final SecurityHelper.DigestAlgorithm DIGEST_ALGO = SecurityHelper.DigestAlgorithm.SHA256; @@ -55,20 +55,20 @@ public Texture(String url, Path local, boolean cloak) throws IOException { try (InputStream input = IOHelper.newInput(local)) { IOHelper.readTexture(input, cloak); // Verify texture } - this.digest = Objects.requireNonNull(SecurityHelper.digest(DIGEST_ALGO, local), "digest"); + this.digest = SecurityHelper.digest(DIGEST_ALGO, local); this.metadata = null; } public Texture(String url, byte[] digest) { this.url = IOHelper.verifyURL(url); - this.digest = Objects.requireNonNull(digest, "digest"); + this.digest = digest == null ? new byte[0] : digest; this.metadata = null; } public Texture(String url, byte[] digest, Map metadata) { this.url = url; - this.digest = digest; + this.digest = digest == null ? new byte[0] : digest; this.metadata = metadata; } @@ -77,4 +77,13 @@ public void write(HOutput output) throws IOException { output.writeASCII(url, 2048); output.writeByteArray(digest, -DIGEST_ALGO.bytes); } + + @Override + public String toString() { + return "Texture{" + + "url='" + url + '\'' + + ", digest=" + Arrays.toString(digest) + + ", metadata=" + metadata + + '}'; + } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java index 26dfe32a..cd568982 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java @@ -394,6 +394,9 @@ public static byte[] sign(byte[] bytes, ECPrivateKey privateKey) { public static String toHex(byte[] bytes) { + if (bytes == null) { + return null; + } int offset = 0; char[] hex = new char[bytes.length << 1]; for (byte currentByte : bytes) {