[#23] Update proto api
Add chain functionality Add tests Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
64e275713f
commit
694bb963e4
38 changed files with 1414 additions and 299 deletions
|
@ -3,6 +3,7 @@ package info.frostfs.sdk;
|
|||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Message;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
@ -15,6 +16,7 @@ import static java.util.Objects.isNull;
|
|||
public class Helper {
|
||||
private static final String SHA256 = "SHA-256";
|
||||
private static final int RIPEMD_160_HASH_BYTE_LENGTH = 20;
|
||||
private static final int HEX_RADIX = 16;
|
||||
|
||||
private Helper() {
|
||||
}
|
||||
|
@ -62,4 +64,12 @@ public class Helper {
|
|||
|
||||
return String.format("%0" + (value.length << 1) + "x", new BigInteger(1, value));
|
||||
}
|
||||
|
||||
public static byte[] getByteArrayFromHex(String hex) {
|
||||
if (StringUtils.isBlank(hex)) {
|
||||
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||
}
|
||||
|
||||
return new BigInteger(hex, HEX_RADIX).toByteArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,4 +108,23 @@ public class HelperTest {
|
|||
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(null));
|
||||
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(new byte[]{}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByteArrayFromHex_success() {
|
||||
//Given
|
||||
var value = "0102030405";
|
||||
|
||||
//When
|
||||
var result = Helper.getByteArrayFromHex(value);
|
||||
|
||||
//Then
|
||||
assertThat(result).containsOnly(new byte[]{1, 2, 3, 4, 5});
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByteArrayFromHex_wrong() {
|
||||
//When + Then
|
||||
assertThrows(ValidationFrostFSException.class, () -> Helper.getByteArrayFromHex(null));
|
||||
assertThrows(ValidationFrostFSException.class, () -> Helper.getByteArrayFromHex(""));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue