diff options
| author | J08nY | 2017-12-03 21:34:02 +0100 |
|---|---|---|
| committer | J08nY | 2017-12-03 21:34:02 +0100 |
| commit | be9c68b2ec522f6e7efda9fad325ab88bd0e8a93 (patch) | |
| tree | c0382e80f8a22f5cc4bd4917ddb577fc052e651d /src | |
| parent | da09715d9ec955b4b139b45a1b2c5270ca0ebf2d (diff) | |
| download | ECTester-be9c68b2ec522f6e7efda9fad325ab88bd0e8a93.tar.gz ECTester-be9c68b2ec522f6e7efda9fad325ab88bd0e8a93.tar.zst ECTester-be9c68b2ec522f6e7efda9fad325ab88bd0e8a93.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/cz/crcs/ectester/common/output/TestableWriter.java | 1 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/common/test/SimpleTest.java | 19 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/common/test/TestCallback.java | 1 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/reader/test/CommandTest.java | 55 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java | 16 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java | 2 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/standalone/test/KeyGenerationTest.java | 44 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java | 42 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java (renamed from src/cz/crcs/ectester/standalone/test/KeyGenerationTestable.java) | 8 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/standalone/test/SignatureTest.java | 16 |
10 files changed, 101 insertions, 103 deletions
diff --git a/src/cz/crcs/ectester/common/output/TestableWriter.java b/src/cz/crcs/ectester/common/output/TestableWriter.java index 2097254..a15193a 100644 --- a/src/cz/crcs/ectester/common/output/TestableWriter.java +++ b/src/cz/crcs/ectester/common/output/TestableWriter.java @@ -1,7 +1,6 @@ package cz.crcs.ectester.common.output; import cz.crcs.ectester.common.test.BaseTestable; -import cz.crcs.ectester.common.test.Testable; import java.io.OutputStream; import java.io.PrintStream; diff --git a/src/cz/crcs/ectester/common/test/SimpleTest.java b/src/cz/crcs/ectester/common/test/SimpleTest.java new file mode 100644 index 0000000..f68320a --- /dev/null +++ b/src/cz/crcs/ectester/common/test/SimpleTest.java @@ -0,0 +1,19 @@ +package cz.crcs.ectester.common.test; + +/** + * @param <T> + * @author Jan Jancar johny@neuromancer.sk + */ +public abstract class SimpleTest<T extends BaseTestable> extends Test { + protected T testable; + protected TestCallback<T> callback; + + public SimpleTest(T testable, TestCallback<T> callback) { + this.testable = testable; + this.callback = callback; + } + + public T getTestable() { + return testable; + } +} diff --git a/src/cz/crcs/ectester/common/test/TestCallback.java b/src/cz/crcs/ectester/common/test/TestCallback.java index 488e2f2..ce6000b 100644 --- a/src/cz/crcs/ectester/common/test/TestCallback.java +++ b/src/cz/crcs/ectester/common/test/TestCallback.java @@ -4,6 +4,7 @@ import java.util.function.Function; /** * + * @author Jan Jancar johny@neuromancer.sk * @param <T> */ public abstract class TestCallback<T extends Testable> implements Function<T, Result> { diff --git a/src/cz/crcs/ectester/reader/test/CommandTest.java b/src/cz/crcs/ectester/reader/test/CommandTest.java index b7728b6..5f3dcac 100644 --- a/src/cz/crcs/ectester/reader/test/CommandTest.java +++ b/src/cz/crcs/ectester/reader/test/CommandTest.java @@ -1,45 +1,42 @@ package cz.crcs.ectester.reader.test; import cz.crcs.ectester.common.test.Result; -import cz.crcs.ectester.common.test.Test; +import cz.crcs.ectester.common.test.SimpleTest; +import cz.crcs.ectester.common.test.TestCallback; import cz.crcs.ectester.common.test.TestException; import cz.crcs.ectester.reader.command.Command; import cz.crcs.ectester.reader.response.Response; -import javax.smartcardio.CardException; -import java.util.function.BiFunction; - /** * A simple test that runs one Command to get and evaluate one Response * to get a Result and compare it with the expected one. */ -public class CommandTest extends Test { - private BiFunction<Command, Response, Result> callback; - private Command command; - private Response response; - - public CommandTest(Command command, BiFunction<Command, Response, Result> callback) { - this.command = command; - this.callback = callback; +public class CommandTest extends SimpleTest<CommandTestable> { + private CommandTest(CommandTestable command, TestCallback<CommandTestable> callback) { + super(command, callback); } - public CommandTest(Command command, Result.ExpectedValue expected, String ok, String nok) { - this(command, (cmd, resp) -> { - Result.Value resultValue = Result.Value.fromExpected(expected, resp.successful(), resp.error()); - return new Result(resultValue, resultValue.ok() ? ok : nok); + public CommandTest expect(CommandTestable command, Result.ExpectedValue expected, String ok, String nok) { + return new CommandTest(command, new TestCallback<CommandTestable>() { + @Override + public Result apply(CommandTestable commandTestable) { + Response resp = commandTestable.getResponse(); + Result.Value resultValue = Result.Value.fromExpected(expected, resp.successful(), resp.error()); + return new Result(resultValue, resultValue.ok() ? ok : nok); + } }); } - public CommandTest(Command command, Result.ExpectedValue expected) { - this(command, expected, null, null); + public CommandTest expect(CommandTestable command, Result.ExpectedValue expected) { + return expect(command, expected, null, null); } public Command getCommand() { - return command; + return testable.getCommand(); } public Response getResponse() { - return response; + return testable.getResponse(); } @Override @@ -47,25 +44,13 @@ public class CommandTest extends Test { if (hasRun) return; - try { - response = command.send(); - } catch (CardException e) { - throw new TestException(e); - } - if (callback != null) { - result = callback.apply(command, response); - } else { - if (response.successful()) { - result = new Result(Result.Value.SUCCESS); - } else { - result = new Result(Result.Value.FAILURE); - } - } + testable.run(); + result = callback.apply(testable); hasRun = true; } @Override public String getDescription() { - return response.getDescription(); + return null; } } diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java index a24346e..9604e75 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java +++ b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java @@ -1,7 +1,7 @@ package cz.crcs.ectester.standalone.test; import cz.crcs.ectester.common.test.Result; -import cz.crcs.ectester.common.test.Test; +import cz.crcs.ectester.common.test.SimpleTest; import cz.crcs.ectester.common.test.TestCallback; import cz.crcs.ectester.common.test.TestException; @@ -10,13 +10,9 @@ import java.util.Arrays; /** * @author Jan Jancar johny@neuromancer.sk */ -public class KeyAgreementTest extends Test { - private KeyAgreementTestable ka; - private TestCallback<KeyAgreementTestable> callback; - +public class KeyAgreementTest extends SimpleTest<KeyAgreementTestable> { private KeyAgreementTest(KeyAgreementTestable ka, TestCallback<KeyAgreementTestable> callback) { - this.ka = ka; - this.callback = callback; + super(ka, callback); } public static KeyAgreementTest match(KeyAgreementTestable ka, byte[] expectedSecret) { @@ -52,8 +48,10 @@ public class KeyAgreementTest extends Test { @Override public void run() throws TestException { - ka.run(); - result = callback.apply(ka); + if (hasRun) + return; + testable.run(); + result = callback.apply(testable); hasRun = true; } } diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java index fedf519..fc0f007 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java +++ b/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java @@ -14,7 +14,7 @@ import java.security.interfaces.ECPublicKey; */ public class KeyAgreementTestable extends BaseTestable { private KeyAgreement ka; - private ECPrivateKey privateKey; + private ECPrivateKey privateKey;a private ECPublicKey publicKey; private byte[] secret; diff --git a/src/cz/crcs/ectester/standalone/test/KeyGenerationTest.java b/src/cz/crcs/ectester/standalone/test/KeyGenerationTest.java deleted file mode 100644 index 0ec4741..0000000 --- a/src/cz/crcs/ectester/standalone/test/KeyGenerationTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package cz.crcs.ectester.standalone.test; - -import cz.crcs.ectester.common.test.Result; -import cz.crcs.ectester.common.test.Test; -import cz.crcs.ectester.common.test.TestCallback; -import cz.crcs.ectester.common.test.TestException; - -/** - * @author Jan Jancar johny@neuromancer.sk - */ -public class KeyGenerationTest extends Test { - private KeyGenerationTestable kg; - private TestCallback<KeyGenerationTestable> callback; - - private KeyGenerationTest(KeyGenerationTestable kg, TestCallback<KeyGenerationTestable> callback) { - this.kg = kg; - this.callback = callback; - } - - public static KeyGenerationTest expect(KeyGenerationTestable kg, Result.ExpectedValue expected) { - return new KeyGenerationTest(kg, new TestCallback<KeyGenerationTestable>() { - @Override - public Result apply(KeyGenerationTestable keyGenerationTestable) { - return new Result(Result.Value.fromExpected(expected, keyGenerationTestable.ok(), keyGenerationTestable.error())); - } - }); - } - - public static KeyGenerationTest function(KeyGenerationTestable ka, TestCallback<KeyGenerationTestable> callback) { - return new KeyGenerationTest(ka, callback); - } - - @Override - public String getDescription() { - return null; - } - - @Override - public void run() throws TestException { - kg.run(); - result = callback.apply(kg); - hasRun = true; - } -} diff --git a/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java new file mode 100644 index 0000000..9032415 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java @@ -0,0 +1,42 @@ +package cz.crcs.ectester.standalone.test; + +import cz.crcs.ectester.common.test.Result; +import cz.crcs.ectester.common.test.SimpleTest; +import cz.crcs.ectester.common.test.TestCallback; +import cz.crcs.ectester.common.test.TestException; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class KeyGeneratorTest extends SimpleTest<KeyGeneratorTestable> { + private KeyGeneratorTest(KeyGeneratorTestable kg, TestCallback<KeyGeneratorTestable> callback) { + super(kg, callback); + } + + public static KeyGeneratorTest expect(KeyGeneratorTestable kg, Result.ExpectedValue expected) { + return new KeyGeneratorTest(kg, new TestCallback<KeyGeneratorTestable>() { + @Override + public Result apply(KeyGeneratorTestable keyGenerationTestable) { + return new Result(Result.Value.fromExpected(expected, keyGenerationTestable.ok(), keyGenerationTestable.error())); + } + }); + } + + public static KeyGeneratorTest function(KeyGeneratorTestable ka, TestCallback<KeyGeneratorTestable> callback) { + return new KeyGeneratorTest(ka, callback); + } + + @Override + public String getDescription() { + return null; + } + + @Override + public void run() throws TestException { + if (hasRun) + return; + testable.run(); + result = callback.apply(testable); + hasRun = true; + } +} diff --git a/src/cz/crcs/ectester/standalone/test/KeyGenerationTestable.java b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java index 5a891b7..ca7f1e7 100644 --- a/src/cz/crcs/ectester/standalone/test/KeyGenerationTestable.java +++ b/src/cz/crcs/ectester/standalone/test/KeyGeneratorTestable.java @@ -8,22 +8,22 @@ import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.spec.ECParameterSpec; -public class KeyGenerationTestable extends BaseTestable { +public class KeyGeneratorTestable extends BaseTestable { private KeyPair kp; private KeyPairGenerator kpg; private int keysize = 0; private ECParameterSpec spec = null; - public KeyGenerationTestable(KeyPairGenerator kpg) { + public KeyGeneratorTestable(KeyPairGenerator kpg) { this.kpg = kpg; } - public KeyGenerationTestable(KeyPairGenerator kpg, int keysize) { + public KeyGeneratorTestable(KeyPairGenerator kpg, int keysize) { this.kpg = kpg; this.keysize = keysize; } - public KeyGenerationTestable(KeyPairGenerator kpg, ECParameterSpec spec) { + public KeyGeneratorTestable(KeyPairGenerator kpg, ECParameterSpec spec) { this.kpg = kpg; this.spec = spec; } diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTest.java b/src/cz/crcs/ectester/standalone/test/SignatureTest.java index 828b84f..272a3f7 100644 --- a/src/cz/crcs/ectester/standalone/test/SignatureTest.java +++ b/src/cz/crcs/ectester/standalone/test/SignatureTest.java @@ -1,19 +1,15 @@ package cz.crcs.ectester.standalone.test; -import cz.crcs.ectester.common.test.Test; +import cz.crcs.ectester.common.test.SimpleTest; import cz.crcs.ectester.common.test.TestCallback; import cz.crcs.ectester.common.test.TestException; /** * @author Jan Jancar johny@neuromancer.sk */ -public class SignatureTest extends Test { - private SignatureTestable sig; - private TestCallback<SignatureTestable> callback; - +public class SignatureTest extends SimpleTest<SignatureTestable> { private SignatureTest(SignatureTestable sig, TestCallback<SignatureTestable> callback) { - this.sig = sig; - this.callback = callback; + super(sig, callback); } @Override @@ -23,8 +19,10 @@ public class SignatureTest extends Test { @Override public void run() throws TestException { - sig.run(); - result = callback.apply(sig); + if (hasRun) + return; + testable.run(); + result = callback.apply(testable); hasRun = true; } } |
