Remove CryptoNoteException again as it caused failed tests

Damn codacy forces one to not use Exception ;-(
This commit is contained in:
chimp1984 2020-09-01 01:24:14 -05:00
parent d36306a73c
commit 123183e5e1
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3
2 changed files with 10 additions and 34 deletions

View file

@ -46,7 +46,7 @@ public class CryptoNoteAddressValidator implements AddressValidator {
}
}
return AddressValidationResult.invalidAddress(String.format("invalid address prefix %x", prefix));
} catch (CryptoNoteUtils.CryptoNoteException e) {
} catch (Exception e) {
return AddressValidationResult.invalidStructure();
}
}

View file

@ -34,7 +34,7 @@ public class CryptoNoteUtils {
// omit the type (1st byte) and checksum (last 4 byte)
byte[] slice = Arrays.copyOfRange(decoded, 1, decoded.length - 4);
return Utils.HEX.encode(slice);
} catch (CryptoNoteException e) {
} catch (Exception e) {
e.printStackTrace();
}
return null;
@ -155,7 +155,7 @@ public class CryptoNoteUtils {
int inputLength,
byte[] decoded,
int decodedOffset,
int decodedLength) throws CryptoNoteException {
int decodedLength) throws Exception {
BigInteger result = BigInteger.ZERO;
@ -164,17 +164,17 @@ public class CryptoNoteUtils {
char character = input.charAt(--index);
int digit = ALPHABET.indexOf(character);
if (digit == -1) {
throw new CryptoNoteException("invalid character " + character);
throw new Exception("invalid character " + character);
}
result = result.add(order.multiply(BigInteger.valueOf(digit)));
if (result.compareTo(UINT64_MAX) > 0) {
throw new CryptoNoteException("64-bit unsigned integer overflow " + result.toString());
throw new Exception("64-bit unsigned integer overflow " + result.toString());
}
}
BigInteger maxCapacity = BigInteger.ONE.shiftLeft(8 * decodedLength);
if (result.compareTo(maxCapacity) >= 0) {
throw new CryptoNoteException("capacity overflow " + result.toString());
throw new Exception("capacity overflow " + result.toString());
}
for (int index = decodedOffset + decodedLength; index != decodedOffset; result = result.shiftRight(8)) {
@ -182,7 +182,7 @@ public class CryptoNoteUtils {
}
}
public static byte[] decode(String input) throws CryptoNoteException {
public static byte[] decode(String input) throws Exception {
if (input.length() == 0) {
return new byte[0];
}
@ -218,12 +218,12 @@ public class CryptoNoteUtils {
return result;
}
static long decodeAddress(String address, boolean validateChecksum) throws CryptoNoteException {
static long decodeAddress(String address, boolean validateChecksum) throws Exception {
byte[] decoded = decode(address);
int checksumSize = 4;
if (decoded.length < checksumSize) {
throw new CryptoNoteException("invalid length");
throw new Exception("invalid length");
}
ByteBuffer decodedAddress = ByteBuffer.wrap(decoded, 0, decoded.length - checksumSize);
@ -237,35 +237,11 @@ public class CryptoNoteUtils {
int checksum = fastHash.getInt();
int expected = ByteBuffer.wrap(decoded, decoded.length - checksumSize, checksumSize).getInt();
if (checksum != expected) {
throw new CryptoNoteException(String.format("invalid checksum %08X, expected %08X", checksum, expected));
throw new Exception(String.format("invalid checksum %08X, expected %08X", checksum, expected));
}
return prefix;
}
}
static class CryptoNoteException extends Exception {
public CryptoNoteException() {
}
public CryptoNoteException(String message) {
super(message);
}
public CryptoNoteException(String message, Throwable cause) {
super(message, cause);
}
public CryptoNoteException(Throwable cause) {
super(cause);
}
public CryptoNoteException(String message,
Throwable cause,
boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
}