[#14] add lombok and refactor exceptions. Provide validator.
All checks were successful
DCO / DCO (pull_request) Successful in 34s

Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
Ori Bruk 2024-09-17 17:47:03 +03:00
parent 15cf0893c7
commit 388428af76
87 changed files with 819 additions and 970 deletions

View file

@ -2,16 +2,17 @@ package info.frostfs.sdk;
import com.google.protobuf.ByteString;
import com.google.protobuf.Message;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING;
import static java.util.Objects.isNull;
public class Helper {
private static final String ERROR_MESSAGE = "Input value is missing";
private static final String SHA256 = "SHA-256";
private static final int RIPEMD_160_HASH_BYTE_LENGTH = 20;
@ -20,7 +21,7 @@ public class Helper {
public static byte[] getRipemd160(byte[] value) {
if (isNull(value)) {
throw new IllegalArgumentException(ERROR_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
var hash = new byte[RIPEMD_160_HASH_BYTE_LENGTH];
@ -40,7 +41,7 @@ public class Helper {
public static byte[] getSha256(byte[] value) {
if (isNull(value)) {
throw new IllegalArgumentException(ERROR_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
return getSha256Instance().digest(value);
@ -48,7 +49,7 @@ public class Helper {
public static ByteString getSha256(Message value) {
if (isNull(value)) {
throw new IllegalArgumentException(ERROR_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
return ByteString.copyFrom(getSha256(value.toByteArray()));
@ -56,7 +57,7 @@ public class Helper {
public static String getHexString(byte[] value) {
if (isNull(value) || value.length == 0) {
throw new IllegalArgumentException(ERROR_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
return String.format("%0" + (value.length << 1) + "x", new BigInteger(1, value));