forked from TrueCloudLab/frostfs-sdk-java
[#6] cover the cryptography module with junit tests
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
0d76332f01
commit
c9a54d56fb
8 changed files with 432 additions and 34 deletions
|
@ -16,6 +16,8 @@ public class Base58 {
|
|||
private static final char ENCODED_ZERO = ALPHABET[0];
|
||||
private static final char BASE58_ASCII_MAX_VALUE = 128;
|
||||
private static final int[] INDEXES = new int[BASE58_ASCII_MAX_VALUE];
|
||||
private static final String ERROR_VALUE_MISSING_MESSAGE = "Input value is missing";
|
||||
private static final String ERROR_INVALID_CHARACTER_TEMPLATE = "Invalid character in Base58: 0x%04x";
|
||||
|
||||
static {
|
||||
Arrays.fill(INDEXES, -1);
|
||||
|
@ -29,7 +31,7 @@ public class Base58 {
|
|||
|
||||
public static byte[] base58CheckDecode(String input) {
|
||||
if (StringUtils.isEmpty(input)) {
|
||||
throw new IllegalArgumentException("Input value is missing");
|
||||
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
|
||||
}
|
||||
|
||||
byte[] buffer = decode(input);
|
||||
|
@ -50,7 +52,7 @@ public class Base58 {
|
|||
|
||||
public static String base58CheckEncode(byte[] data) {
|
||||
if (isNull(data)) {
|
||||
throw new IllegalArgumentException("Input value is missing");
|
||||
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
|
||||
}
|
||||
|
||||
byte[] checksum = getSha256(getSha256(data));
|
||||
|
@ -99,7 +101,7 @@ public class Base58 {
|
|||
char c = input.charAt(i);
|
||||
int digit = c < BASE58_ASCII_MAX_VALUE ? INDEXES[c] : -1;
|
||||
if (digit < 0) {
|
||||
throw new IllegalArgumentException(String.format("Invalid character in Base58: 0x%04x", (int) c));
|
||||
throw new IllegalArgumentException(String.format(ERROR_INVALID_CHARACTER_TEMPLATE, (int) c));
|
||||
}
|
||||
input58[i] = (byte) digit;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue