More hash specifics
This commit is contained in:
parent
3ec189804c
commit
78c3a3c35e
@ -4,7 +4,7 @@ kotlin.code.style=official
|
||||
specifyKotlinAsDependency=false
|
||||
|
||||
projectGroup=ru.dbotthepony.kommons
|
||||
projectVersion=2.7.0
|
||||
projectVersion=2.7.1
|
||||
|
||||
guavaDepVersion=33.0.0
|
||||
gsonDepVersion=2.8.9
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.dbotthepony.kommons.util;
|
||||
|
||||
import java.security.DigestException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -108,8 +109,7 @@ public final class XXHash32 extends MessageDigest {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] engineDigest() {
|
||||
public int digestAsInt() {
|
||||
int h32;
|
||||
|
||||
if (length >= 16) {
|
||||
@ -146,6 +146,13 @@ public final class XXHash32 extends MessageDigest {
|
||||
|
||||
engineReset();
|
||||
|
||||
return h32;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] engineDigest() {
|
||||
int h32 = digestAsInt();
|
||||
|
||||
byte[] result = new byte[4];
|
||||
|
||||
result[0] = (byte) (h32 >>> 24);
|
||||
@ -156,6 +163,28 @@ public final class XXHash32 extends MessageDigest {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int engineGetDigestLength() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException {
|
||||
if (len < 4)
|
||||
throw new DigestException("partial digests not returned");
|
||||
|
||||
if (buf.length - offset < 4)
|
||||
throw new DigestException("insufficient space in the output "
|
||||
+ "buffer to store the digest");
|
||||
|
||||
int h32 = digestAsInt();
|
||||
buf[offset] = (byte) (h32 >>> 24);
|
||||
buf[offset + 1] = (byte) (h32 >>> 16);
|
||||
buf[offset + 2] = (byte) (h32 >>> 8);
|
||||
buf[offset + 3] = (byte) (h32);
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void engineReset() {
|
||||
this.length = 0L;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.dbotthepony.kommons.util;
|
||||
|
||||
import java.security.DigestException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -123,8 +124,7 @@ public final class XXHash64 extends MessageDigest {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] engineDigest() {
|
||||
public long digestAsLong() {
|
||||
long h64;
|
||||
|
||||
if (length >= 32L) {
|
||||
@ -168,6 +168,18 @@ public final class XXHash64 extends MessageDigest {
|
||||
|
||||
engineReset();
|
||||
|
||||
return h64;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int engineGetDigestLength() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] engineDigest() {
|
||||
long h64 = digestAsLong();
|
||||
|
||||
byte[] result = new byte[8];
|
||||
|
||||
result[7] = (byte) h64;
|
||||
@ -182,6 +194,29 @@ public final class XXHash64 extends MessageDigest {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException {
|
||||
if (len < 8)
|
||||
throw new DigestException("partial digests not returned");
|
||||
|
||||
if (buf.length - offset < 8)
|
||||
throw new DigestException("insufficient space in the output "
|
||||
+ "buffer to store the digest");
|
||||
|
||||
long h64 = digestAsLong();
|
||||
|
||||
buf[offset + 7] = (byte) h64;
|
||||
buf[offset + 6] = (byte) (h64 >>> 8);
|
||||
buf[offset + 5] = (byte) (h64 >>> 16);
|
||||
buf[offset + 4] = (byte) (h64 >>> 24);
|
||||
buf[offset + 3] = (byte) (h64 >>> 32);
|
||||
buf[offset + 2] = (byte) (h64 >>> 40);
|
||||
buf[offset + 1] = (byte) (h64 >>> 48);
|
||||
buf[offset] = (byte) (h64 >>> 56);
|
||||
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void engineReset() {
|
||||
this.length = 0L;
|
||||
|
Loading…
Reference in New Issue
Block a user