Code cleanup

This commit is contained in:
Christian Basler 2016-02-24 23:25:55 +01:00
parent 9f1e0057c9
commit 0a00a0a1b4
8 changed files with 26 additions and 23 deletions

View File

@ -22,7 +22,6 @@ import ch.dissem.bitmessage.entity.payload.Msg;
import ch.dissem.bitmessage.entity.payload.ObjectPayload;
import ch.dissem.bitmessage.entity.payload.ObjectType;
import ch.dissem.bitmessage.entity.payload.Pubkey.Feature;
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
import ch.dissem.bitmessage.entity.valueobject.Label;
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
import ch.dissem.bitmessage.exception.ApplicationException;

View File

@ -19,6 +19,7 @@ package ch.dissem.bitmessage.entity;
import ch.dissem.bitmessage.entity.payload.Pubkey;
import ch.dissem.bitmessage.entity.payload.V4Pubkey;
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
import ch.dissem.bitmessage.exception.ApplicationException;
import ch.dissem.bitmessage.utils.AccessCounter;
import ch.dissem.bitmessage.utils.Base58;
import ch.dissem.bitmessage.utils.Bytes;
@ -83,7 +84,7 @@ public class BitmessageAddress implements Serializable {
os.write(checksum, 0, 4);
this.address = "BM-" + Base58.encode(os.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}
@ -124,7 +125,7 @@ public class BitmessageAddress implements Serializable {
this.publicDecryptionKey = Arrays.copyOfRange(checksum, 0, 32);
}
} catch (IOException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}
@ -136,7 +137,7 @@ public class BitmessageAddress implements Serializable {
out.write(ripe);
return Arrays.copyOfRange(security().doubleSha512(out.toByteArray()), 32, 64);
} catch (IOException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}

View File

@ -21,6 +21,7 @@ import ch.dissem.bitmessage.entity.payload.ObjectType;
import ch.dissem.bitmessage.entity.payload.Pubkey;
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
import ch.dissem.bitmessage.exception.ApplicationException;
import ch.dissem.bitmessage.exception.DecryptionFailedException;
import ch.dissem.bitmessage.utils.Bytes;
import ch.dissem.bitmessage.utils.Encode;
@ -110,7 +111,7 @@ public class ObjectMessage implements MessagePayload {
payload.writeBytesToSign(out);
return out.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}
@ -144,7 +145,7 @@ public class ObjectMessage implements MessagePayload {
((Encrypted) payload).encrypt(publicKey.getEncryptionKey());
}
} catch (IOException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}
@ -180,7 +181,7 @@ public class ObjectMessage implements MessagePayload {
}
return payloadBytes;
} catch (IOException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}

View File

@ -19,6 +19,7 @@ package ch.dissem.bitmessage.ports;
import ch.dissem.bitmessage.InternalContext;
import ch.dissem.bitmessage.entity.ObjectMessage;
import ch.dissem.bitmessage.entity.payload.Pubkey;
import ch.dissem.bitmessage.exception.ApplicationException;
import ch.dissem.bitmessage.exception.InsufficientProofOfWorkException;
import ch.dissem.bitmessage.factory.Factory;
import ch.dissem.bitmessage.utils.Bytes;
@ -151,7 +152,7 @@ public abstract class AbstractCryptography implements Cryptography, InternalCont
try {
return MessageDigest.getInstance(algorithm, provider);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}
@ -161,7 +162,7 @@ public abstract class AbstractCryptography implements Cryptography, InternalCont
mac.init(new SecretKeySpec(key_m, "HmacSHA256"));
return mac.doFinal(data);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}

View File

@ -17,6 +17,7 @@
package ch.dissem.bitmessage.ports;
import ch.dissem.bitmessage.entity.valueobject.NetworkAddress;
import ch.dissem.bitmessage.exception.ApplicationException;
import ch.dissem.bitmessage.utils.UnixTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -71,7 +72,7 @@ public class MemoryNodeRegistry implements NodeRegistry {
}
}
} catch (IOException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}

View File

@ -16,6 +16,7 @@
package ch.dissem.bitmessage.ports;
import ch.dissem.bitmessage.exception.ApplicationException;
import ch.dissem.bitmessage.utils.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -49,7 +50,7 @@ public class MultiThreadedPOWEngine implements ProofOfWorkEngine {
try {
semaphore.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
throw new ApplicationException(e);
}
callback = new CallbackWrapper(callback);
int cores = Runtime.getRuntime().availableProcessors();
@ -88,7 +89,7 @@ public class MultiThreadedPOWEngine implements ProofOfWorkEngine {
mda = MessageDigest.getInstance("SHA-512");
} catch (NoSuchAlgorithmException e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
throw new ApplicationException(e);
}
}

View File

@ -44,27 +44,27 @@ public class Base58 {
/**
* Encodes the given bytes in base58. No checksum is appended.
*
* @param input to encode
* @param data to encode
* @return base58 encoded input
*/
public static String encode(byte[] input) {
if (input.length == 0) {
public static String encode(byte[] data) {
if (data.length == 0) {
return "";
}
input = copyOfRange(input, 0, input.length);
final byte[] bytes = copyOfRange(data, 0, data.length);
// Count leading zeroes.
int zeroCount = 0;
while (zeroCount < input.length && input[zeroCount] == 0) {
while (zeroCount < bytes.length && bytes[zeroCount] == 0) {
++zeroCount;
}
// The actual encoding.
byte[] temp = new byte[input.length * 2];
byte[] temp = new byte[bytes.length * 2];
int j = temp.length;
int startAt = zeroCount;
while (startAt < input.length) {
byte mod = divmod58(input, startAt);
if (input[startAt] == 0) {
while (startAt < bytes.length) {
byte mod = divmod58(bytes, startAt);
if (bytes[startAt] == 0) {
++startAt;
}
temp[--j] = (byte) ALPHABET[mod];
@ -97,7 +97,7 @@ public class Base58 {
char c = input.charAt(i);
int digit58 = -1;
if (c >= 0 && c < 128) {
if (c < 128) {
digit58 = INDEXES[c];
}
if (digit58 < 0) {

View File

@ -21,7 +21,6 @@ import ch.dissem.bitmessage.entity.CustomMessage;
import ch.dissem.bitmessage.entity.Streamable;
import ch.dissem.bitmessage.entity.payload.CryptoBox;
import ch.dissem.bitmessage.entity.payload.Pubkey;
import ch.dissem.bitmessage.exception.ApplicationException;
import ch.dissem.bitmessage.exception.DecryptionFailedException;
import ch.dissem.bitmessage.factory.Factory;
import ch.dissem.bitmessage.utils.Encode;