diff --git a/src/nodash/core/NoAdapter.java b/src/nodash/core/NoAdapter.java index 0eec1d9..f718dde 100644 --- a/src/nodash/core/NoAdapter.java +++ b/src/nodash/core/NoAdapter.java @@ -36,6 +36,8 @@ public interface NoAdapter { public Collection pollNoByteSets(PublicKey address) throws NoAdapterException; - public void addNoByteSets(Collection noByteSets, PublicKey address) + public void addNoByteSet(NoByteSet byteSet, PublicKey address) throws NoAdapterException; + + public void addNoByteSets(Collection byteSets, PublicKey address) throws NoAdapterException; } diff --git a/src/nodash/core/NoDefaultAdapter.java b/src/nodash/core/NoDefaultAdapter.java index 2883cd2..cf90ca2 100644 --- a/src/nodash/core/NoDefaultAdapter.java +++ b/src/nodash/core/NoDefaultAdapter.java @@ -195,6 +195,14 @@ public class NoDefaultAdapter implements NoAdapter { return new ArrayList(); } } + + @Override + public void addNoByteSet(NoByteSet byteSet, PublicKey address) { + if (!byteSets.containsKey(address)) { + byteSets.put(address, new ArrayList()); + } + byteSets.get(address).add(byteSet); + } @Override public void addNoByteSets(Collection addedByteSets, PublicKey address) { diff --git a/src/nodash/core/NoUtil.java b/src/nodash/core/NoUtil.java index 86a3efc..45a2a2f 100644 --- a/src/nodash/core/NoUtil.java +++ b/src/nodash/core/NoUtil.java @@ -28,7 +28,6 @@ import java.security.spec.KeySpec; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; -import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; diff --git a/src/nodash/models/NoSession.java b/src/nodash/models/NoSession.java index 6a20c71..12adabf 100644 --- a/src/nodash/models/NoSession.java +++ b/src/nodash/models/NoSession.java @@ -13,11 +13,8 @@ import javax.crypto.IllegalBlockSizeException; import org.apache.commons.codec.binary.Base64; import nodash.core.NoAdapter; -import nodash.core.NoCore; import nodash.core.NoUtil; import nodash.exceptions.NoByteSetBadDecryptionException; -import nodash.exceptions.NoDashFatalException; -import nodash.exceptions.NoDashSessionBadUuidException; import nodash.exceptions.NoSessionConfirmedException; import nodash.exceptions.NoSessionExpiredException; import nodash.exceptions.NoSessionNotAwaitingConfirmationException; @@ -191,26 +188,6 @@ public final class NoSession implements Serializable { } } - private static String decryptUuid(String data) throws NoDashSessionBadUuidException { - return decryptUuid(Base64.decodeBase64(data)); - } - - private static String decryptUuid(byte[] data) throws NoDashSessionBadUuidException { - if (data == null) { - throw new NoDashSessionBadUuidException(); - } - - try { - return Base64.encodeBase64String(NoUtil.decrypt(data)); - } catch (IllegalArgumentException e) { - throw new NoDashSessionBadUuidException(); - } catch (IllegalBlockSizeException e) { - throw new NoDashSessionBadUuidException(); - } catch (BadPaddingException e) { - throw new NoDashSessionBadUuidException(); - } - } - public void setIncoming(Collection incoming) { this.incoming = incoming; } diff --git a/src/nodash/models/noactiontypes/NoErrorableAction.java b/src/nodash/models/noactiontypes/NoErrorableAction.java index 5db40c1..d86cd0b 100644 --- a/src/nodash/models/noactiontypes/NoErrorableAction.java +++ b/src/nodash/models/noactiontypes/NoErrorableAction.java @@ -23,8 +23,10 @@ package nodash.models.noactiontypes; import java.security.PublicKey; -import nodash.core.NoCore; +import nodash.core.NoAdapter; +import nodash.exceptions.NoAdapterException; import nodash.exceptions.NoCannotGetInfluenceException; +import nodash.exceptions.NoDashFatalException; import nodash.models.NoByteSet; import nodash.models.NoInfluence; @@ -36,20 +38,27 @@ public abstract class NoErrorableAction extends NoTargetedAction { super(source); } - public void execute() { + @Override + public void execute(NoAdapter adapter) { this.process(); try { NoInfluence influence = this.generateTargetInfluence(); if (influence != null) { NoByteSet byteSet = influence.getByteSet(this.target); - NoCore.addByteSet(byteSet, this.target); + adapter.addNoByteSet(byteSet, this.target); } } catch (NoCannotGetInfluenceException e) { NoInfluence errorInfluence = e.getResponseInfluence(); if (errorInfluence != null) { NoByteSet byteSet = errorInfluence.getByteSet(this.target); - NoCore.addByteSet(byteSet, this.target); + try { + adapter.addNoByteSet(byteSet, this.target); + } catch (NoAdapterException e1) { + throw new NoDashFatalException("Could not add the error byte set to the pool."); + } } + } catch (NoAdapterException e) { + throw new NoDashFatalException("Could not add the byte set to the pool."); } } } diff --git a/src/nodash/models/noactiontypes/NoHandshakeAction.java b/src/nodash/models/noactiontypes/NoHandshakeAction.java index ac8fe76..690e8a0 100644 --- a/src/nodash/models/noactiontypes/NoHandshakeAction.java +++ b/src/nodash/models/noactiontypes/NoHandshakeAction.java @@ -23,8 +23,10 @@ package nodash.models.noactiontypes; import java.security.PublicKey; -import nodash.core.NoCore; +import nodash.core.NoAdapter; +import nodash.exceptions.NoAdapterException; import nodash.exceptions.NoCannotGetInfluenceException; +import nodash.exceptions.NoDashFatalException; import nodash.models.NoByteSet; import nodash.models.NoInfluence; @@ -37,30 +39,33 @@ public abstract class NoHandshakeAction extends NoSourcedAction { super(target, source); } - public void execute() { + @Override + public void execute(NoAdapter adapter) { this.process(); try { NoInfluence influence = this.generateTargetInfluence(); if (influence != null) { NoByteSet byteSet = influence.getByteSet(this.target); - NoCore.addByteSet(byteSet, this.target); + adapter.addNoByteSet(byteSet, this.target); } NoInfluence result = this.generateReturnedInfluence(); if (result != null) { NoByteSet byteSet = result.getByteSet(this.source); - NoCore.addByteSet(byteSet, this.source); + adapter.addNoByteSet(byteSet, this.source); } } catch (NoCannotGetInfluenceException e) { NoInfluence errorInfluence = e.getResponseInfluence(); if (errorInfluence != null) { NoByteSet byteSet = errorInfluence.getByteSet(this.source); - NoCore.addByteSet(byteSet, this.source); + try { + adapter.addNoByteSet(byteSet, this.source); + } catch (NoAdapterException e1) { + throw new NoDashFatalException("Could not add error byte set to the pool."); + } } + } catch (NoAdapterException e) { + throw new NoDashFatalException("Could not add byte sets to the pool.", e); } } - - public void purge() { - super.purge(); - } } diff --git a/src/nodash/models/noactiontypes/NoSourcedAction.java b/src/nodash/models/noactiontypes/NoSourcedAction.java index 7bc8794..81ee08a 100644 --- a/src/nodash/models/noactiontypes/NoSourcedAction.java +++ b/src/nodash/models/noactiontypes/NoSourcedAction.java @@ -22,8 +22,10 @@ package nodash.models.noactiontypes; import java.security.PublicKey; -import nodash.core.NoCore; +import nodash.core.NoAdapter; +import nodash.exceptions.NoAdapterException; import nodash.exceptions.NoCannotGetInfluenceException; +import nodash.exceptions.NoDashFatalException; import nodash.models.NoByteSet; import nodash.models.NoInfluence; @@ -38,23 +40,31 @@ public abstract class NoSourcedAction extends NoTargetedAction { this.source = source; } - public void execute() { + @Override + public void execute(NoAdapter adapter) { this.process(); try { NoInfluence influence = this.generateTargetInfluence(); if (influence != null) { NoByteSet byteSet = influence.getByteSet(this.target); - NoCore.addByteSet(byteSet, this.target); + adapter.addNoByteSet(byteSet, this.target); } } catch (NoCannotGetInfluenceException e) { NoInfluence errorInfluence = e.getResponseInfluence(); if (errorInfluence != null) { NoByteSet byteSet = errorInfluence.getByteSet(this.source); - NoCore.addByteSet(byteSet, this.source); + try { + adapter.addNoByteSet(byteSet, this.source); + } catch (NoAdapterException e1) { + throw new NoDashFatalException("Could not add error byte set to the pool.", e); + } } + } catch (NoAdapterException e) { + throw new NoDashFatalException("Could not add byte set to the pool.", e); } } + @Override public void purge() { super.purge(); this.source = null; diff --git a/src/nodash/models/noactiontypes/NoTargetedAction.java b/src/nodash/models/noactiontypes/NoTargetedAction.java index cd98659..32c092d 100644 --- a/src/nodash/models/noactiontypes/NoTargetedAction.java +++ b/src/nodash/models/noactiontypes/NoTargetedAction.java @@ -19,7 +19,8 @@ package nodash.models.noactiontypes; import java.security.PublicKey; -import nodash.core.NoCore; +import nodash.core.NoAdapter; +import nodash.exceptions.NoAdapterException; import nodash.exceptions.NoCannotGetInfluenceException; import nodash.exceptions.NoDashFatalException; import nodash.models.NoAction; @@ -36,22 +37,26 @@ public abstract class NoTargetedAction extends NoAction { this.target = target; } - public void execute() { + @Override + public void execute(NoAdapter adapter) { this.process(); try { NoInfluence influence = this.generateTargetInfluence(); if (influence != null) { NoByteSet byteSet = influence.getByteSet(this.target); - NoCore.addByteSet(byteSet, this.target); + adapter.addNoByteSet(byteSet, this.target); } } catch (NoCannotGetInfluenceException e) { if (e.getResponseInfluence() != null) { throw new NoDashFatalException( "Unsourced action has generated an error with an undeliverable influence.", e); } + } catch (NoAdapterException e) { + throw new NoDashFatalException("Could not add byte set to the pool.", e); } } + @Override public void purge() { this.target = null; } diff --git a/src/nodash/test/NoCoreTest.java b/src/nodash/test/NoCoreTest.java index 9b12a2b..5e7986b 100644 --- a/src/nodash/test/NoCoreTest.java +++ b/src/nodash/test/NoCoreTest.java @@ -17,7 +17,6 @@ import nodash.exceptions.NoSessionNotAwaitingConfirmationException; import nodash.exceptions.NoSessionNotChangedException; import nodash.exceptions.NoUserAlreadyOnlineException; import nodash.exceptions.NoUserNotValidException; -import nodash.models.NoSession; import nodash.models.NoUser; import org.junit.Test; @@ -123,19 +122,16 @@ public class NoCoreTest { @Test public void testGetUser() { - NoCore core = new NoCore(new NoDefaultAdapter()); fail("Not yet implemented"); } @Test public void testGetSessionState() { - NoCore core = new NoCore(new NoDefaultAdapter()); fail("Not yet implemented"); } @Test public void testShred() { - NoCore core = new NoCore(new NoDefaultAdapter()); fail("Not yet implemented"); } diff --git a/src/nodash/test/NoSessionTest.java b/src/nodash/test/NoSessionTest.java index f080e55..078bd9b 100644 --- a/src/nodash/test/NoSessionTest.java +++ b/src/nodash/test/NoSessionTest.java @@ -1,12 +1,10 @@ package nodash.test; import static org.junit.Assert.*; -import nodash.core.NoCore; import nodash.exceptions.NoSessionConfirmedException; import nodash.exceptions.NoSessionExpiredException; import nodash.models.NoSession; -import org.junit.Before; import org.junit.Test; public class NoSessionTest { diff --git a/src/nodash/test/NoUserTest.java b/src/nodash/test/NoUserTest.java index 09819d0..b71b29a 100644 --- a/src/nodash/test/NoUserTest.java +++ b/src/nodash/test/NoUserTest.java @@ -8,11 +8,9 @@ import java.util.Arrays; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; -import nodash.core.NoCore; import nodash.models.NoUser; import org.apache.commons.codec.binary.Base64; -import org.junit.Before; import org.junit.Test; public class NoUserTest { diff --git a/src/nodash/test/NoUtilTest.java b/src/nodash/test/NoUtilTest.java index f9fd442..f2fb919 100644 --- a/src/nodash/test/NoUtilTest.java +++ b/src/nodash/test/NoUtilTest.java @@ -13,12 +13,9 @@ import java.util.Arrays; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import nodash.core.NoCore; import nodash.core.NoUtil; -import org.junit.Before; import org.junit.Test; public class NoUtilTest {