This is an automated email from the ASF dual-hosted git repository. reschke pushed a commit to branch OAK-11793 in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 5af871f08390de40d19661e42222607b08e88121 Author: Julian Reschke <[email protected]> AuthorDate: Sun Jul 6 15:07:47 2025 +0100 OAK-11792: remove usage of Guava common.hash --- .../oak/plugins/memory/AbstractBlob.java | 52 +++++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java index f0bca90bf9..456d5040d7 100644 --- a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java +++ b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java @@ -20,11 +20,12 @@ package org.apache.jackrabbit.oak.plugins.memory; import java.io.IOException; import java.io.InputStream; +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import org.apache.commons.io.IOUtils; -import org.apache.jackrabbit.guava.common.hash.HashCode; -import org.apache.jackrabbit.guava.common.hash.Hashing; - import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier; import org.jetbrains.annotations.NotNull; @@ -120,7 +121,7 @@ public abstract class AbstractBlob implements Blob { // Blobs are immutable so we can safely cache the hash if (hashCode == null) { try { - hashCode = Hashing.sha256().hashBytes(this.getNewStream().readAllBytes()); + hashCode = HashCode.of(this.getNewStream().readAllBytes()); } catch (IOException e) { throw new IllegalStateException("Hash calculation failed", e); } @@ -128,14 +129,6 @@ public abstract class AbstractBlob implements Blob { return hashCode; } - /** - * This hash code implementation returns the hash code of the underlying stream - * @return a byte array of the hash - */ - protected byte[] sha256() { - return getSha256().asBytes(); - } - //--------------------------------------------------------------< Blob >-- @Override @Nullable @@ -189,4 +182,39 @@ public abstract class AbstractBlob implements Blob { return getSha256().toString(); } + public static class HashCode { + + private byte[] digest; + + private HashCode(byte[] digest){ + this.digest = digest; + } + + private static HashCode of(byte[] bytes) { + try { + return new HashCode(MessageDigest.getInstance("SHA-256").digest(bytes)); + } catch (NoSuchAlgorithmException ex) { + throw new IllegalStateException("no SHA256 digest", ex); + } + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) return false; + return Arrays.equals(digest, ((HashCode)o).digest); + } + + @Override + public int hashCode() { + return Arrays.hashCode(digest); + } + + @Override + public String toString() { + // could use commons-coded + BigInteger bigInteger = new BigInteger(1, digest); + return String.format( + "%0" + (digest.length << 1) + "x", bigInteger); + } + } }
