formatting

This commit is contained in:
Dave
2015-12-05 18:01:07 +02:00
parent 86a5d724e3
commit 6e84c0e76e

View File

@@ -59,7 +59,7 @@ public abstract class NoUser implements Serializable {
@NoHash @NoHash
private int influences; private int influences;
@NoHash @NoHash
private int actions; private int actions;
@@ -83,10 +83,10 @@ public abstract class NoUser implements Serializable {
} }
KeyPair keyPair = kpg.generateKeyPair(); KeyPair keyPair = kpg.generateKeyPair();
this.publicKey = (RSAPublicKeyImpl) keyPair.getPublic(); publicKey = (RSAPublicKeyImpl) keyPair.getPublic();
this.privateKey = (RSAPrivateCrtKeyImpl) keyPair.getPrivate(); privateKey = (RSAPrivateCrtKeyImpl) keyPair.getPrivate();
this.influences = 0; influences = 0;
this.actions = 0; actions = 0;
touchRandomizer(); touchRandomizer();
} }
@@ -124,15 +124,15 @@ public abstract class NoUser implements Serializable {
return o1.getName().compareTo(o2.getName()); return o1.getName().compareTo(o2.getName());
} }
}; };
Class<? extends NoUser> userClass = getClass(); Class<? extends NoUser> userClass = getClass();
StringBuilder toString = new StringBuilder(); StringBuilder toString = new StringBuilder();
while (userClass != null) { while (userClass != null) {
Field[] noHashFields = userClass.getDeclaredFields(); Field[] noHashFields = userClass.getDeclaredFields();
Arrays.sort(noHashFields, fieldComp); Arrays.sort(noHashFields, fieldComp);
for (Field field : noHashFields) { for (Field field : noHashFields) {
if (field.isAnnotationPresent(NoHash.class)) { if (field.isAnnotationPresent(NoHash.class)) {
field.setAccessible(true); field.setAccessible(true);
@@ -143,21 +143,23 @@ public abstract class NoUser implements Serializable {
} }
} }
} }
if (userClass == NoUser.class) { if (userClass == NoUser.class) {
userClass = null; userClass = null;
} else { } else {
userClass = (Class<? extends NoUser>) userClass.getSuperclass(); userClass = (Class<? extends NoUser>) userClass.getSuperclass();
} }
} }
byte[] itemBytes = toString.toString().getBytes(); byte[] itemBytes = toString.toString().getBytes();
return NoUtil.getHashFromByteArray(itemBytes); return NoUtil.getHashFromByteArray(itemBytes);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new NoDashFatalException("IllegalArgument Exception encountered while generating user hash.", e); throw new NoDashFatalException(
"IllegalArgument Exception encountered while generating user hash.", e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new NoDashFatalException("IllegalAccess Exception encountered while generating user hash.", e); throw new NoDashFatalException(
"IllegalAccess Exception encountered while generating user hash.", e);
} }
} }
@@ -183,12 +185,12 @@ public abstract class NoUser implements Serializable {
} }
public final void addAction(NoAction action) { public final void addAction(NoAction action) {
this.outgoing.add(action); outgoing.add(action);
actions++; actions++;
} }
public final List<NoAction> getNoActions() { public final List<NoAction> getNoActions() {
return this.outgoing; return outgoing;
} }
public final BigInteger getPublicExponent() { public final BigInteger getPublicExponent() {
@@ -213,23 +215,23 @@ public abstract class NoUser implements Serializable {
private final byte[] decryptRsa(byte[] data) private final byte[] decryptRsa(byte[] data)
throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException { throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
return NoUtil.decryptRsa(data, this.privateKey); return NoUtil.decryptRsa(data, privateKey);
} }
public static NoUser createUserFromFile(byte[] data, char[] password, Class<? extends NoUser> clazz) public static NoUser createUserFromFile(byte[] data, char[] password,
throws NoUserNotValidException { Class<? extends NoUser> clazz) throws NoUserNotValidException {
byte[] decrypted; byte[] decrypted;
try { try {
decrypted = NoUtil.decrypt(data, password); decrypted = NoUtil.decrypt(data, password);
} catch (IllegalBlockSizeException | BadPaddingException e) { } catch (IllegalBlockSizeException | BadPaddingException e) {
throw new NoUserNotValidException(e); throw new NoUserNotValidException(e);
} }
Gson gson = new Gson(); Gson gson = new Gson();
String json = NoUtil.fromBytes(decrypted); String json = NoUtil.fromBytes(decrypted);
try { try {
NoUser noUser = gson.fromJson(json, clazz); NoUser noUser = gson.fromJson(json, clazz);
return noUser; return noUser;
} catch (JsonSyntaxException e) { } catch (JsonSyntaxException e) {
throw new NoUserNotValidException(e); throw new NoUserNotValidException(e);
} }
@@ -244,7 +246,7 @@ public abstract class NoUser implements Serializable {
if (otherUser == null) { if (otherUser == null) {
return false; return false;
} }
if (!NoUser.class.isAssignableFrom(otherUser.getClass())) { if (!NoUser.class.isAssignableFrom(otherUser.getClass())) {
return false; return false;
} }