diff options
| author | J08nY | 2017-10-25 00:10:56 +0200 |
|---|---|---|
| committer | J08nY | 2017-10-25 00:10:56 +0200 |
| commit | ffbbf6e6482d48f4d49dd2ba1a63f687978415f8 (patch) | |
| tree | a2e4e713199931f229b9bc55edc01b602c8a2154 /src/cz/crcs/ectester/reader/test | |
| parent | 76d5e632d26515a6490009d0781604f3a1f2621f (diff) | |
| download | ECTester-ffbbf6e6482d48f4d49dd2ba1a63f687978415f8.tar.gz ECTester-ffbbf6e6482d48f4d49dd2ba1a63f687978415f8.tar.zst ECTester-ffbbf6e6482d48f4d49dd2ba1a63f687978415f8.zip | |
Add Compund test to test-vectors suite.
Diffstat (limited to 'src/cz/crcs/ectester/reader/test')
| -rw-r--r-- | src/cz/crcs/ectester/reader/test/Test.java | 39 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/reader/test/TestSuite.java | 29 |
2 files changed, 63 insertions, 5 deletions
diff --git a/src/cz/crcs/ectester/reader/test/Test.java b/src/cz/crcs/ectester/reader/test/Test.java index 14cf554..f873c19 100644 --- a/src/cz/crcs/ectester/reader/test/Test.java +++ b/src/cz/crcs/ectester/reader/test/Test.java @@ -114,10 +114,19 @@ public abstract class Test { this.tests = tests; } + private Compound(Function<Test[], Result> callback, String descripiton, Test... tests) { + this(callback, tests); + this.description = descripiton; + } + public static Compound function(Function<Test[], Result> callback, Test... tests) { return new Compound(callback, tests); } + public static Compound function(Function<Test[], Result> callback, String description, Test... tests) { + return new Compound(callback, description, tests); + } + public static Compound all(Result what, Test... all) { return new Compound((tests) -> { for (Test test : tests) { @@ -129,6 +138,12 @@ public abstract class Test { }, all); } + public static Compound all(Result what, String description, Test... all) { + Compound result = Compound.all(what, all); + result.setDescription(description); + return result; + } + public static Compound any(Result what, Test... any) { return new Compound((tests) -> { for (Test test : tests) { @@ -140,6 +155,29 @@ public abstract class Test { }, any); } + public static Compound any(Result what, String description, Test... any) { + Compound result = Compound.any(what, any); + result.setDescription(description); + return result; + } + + public static Compound mask(Result[] results, Test... masked) { + return new Compound((tests) -> { + for (int i = 0; i < results.length; ++i) { + if (results[i] != Result.ANY && results[i] != tests[i].getResult()) { + return Result.FAILURE; + } + } + return Result.SUCCESS; + }, masked); + } + + public static Compound mask(Result[] results, String description, Test... masked) { + Compound result = Compound.mask(results, masked); + result.setDescription(description); + return result; + } + public Test[] getTests() { return tests; } @@ -155,6 +193,7 @@ public abstract class Test { test.run(); } result = callback.apply(tests); + this.hasRun = true; } public void setDescription(String description) { diff --git a/src/cz/crcs/ectester/reader/test/TestSuite.java b/src/cz/crcs/ectester/reader/test/TestSuite.java index 8369439..4bca641 100644 --- a/src/cz/crcs/ectester/reader/test/TestSuite.java +++ b/src/cz/crcs/ectester/reader/test/TestSuite.java @@ -1,5 +1,6 @@ package cz.crcs.ectester.reader.test; +import static cz.crcs.ectester.reader.test.Test.Result; import cz.crcs.ectester.applet.ECTesterApplet; import cz.crcs.ectester.applet.EC_Consts; import cz.crcs.ectester.data.EC_Store; @@ -104,6 +105,9 @@ public abstract class TestSuite { return tests; } + /** + * + */ public static class Default extends TestSuite { public Default(EC_Store dataStore, ECTester.Config cfg, OutputWriter writer) { @@ -157,6 +161,9 @@ public abstract class TestSuite { } } + /** + * + */ public static class TestVectors extends TestSuite { public TestVectors(EC_Store dataStore, ECTester.Config cfg, OutputWriter writer) { @@ -191,13 +198,14 @@ public abstract class TestSuite { if (onekey == null || otherkey == null) { throw new IOException("Test vector keys couldn't be located."); } + List<Test> testVector = new LinkedList<>(); - tests.add(new Test.Simple(new Command.Allocate(cardManager, ECTesterApplet.KEYPAIR_BOTH, curve.getBits(), curve.getField()), Test.Result.SUCCESS)); - tests.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, curve.getParams(), curve.flatten()), Test.Result.SUCCESS)); + testVector.add(new Test.Simple(new Command.Allocate(cardManager, ECTesterApplet.KEYPAIR_BOTH, curve.getBits(), curve.getField()), Test.Result.SUCCESS)); + testVector.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, curve.getParams(), curve.flatten()), Test.Result.SUCCESS)); //tests.add(new Test.Simple(new Command.Generate(cardManager, ECTesterApplet.KEYPAIR_BOTH), Test.Result.SUCCESS)); - tests.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_LOCAL, EC_Consts.CURVE_external, EC_Consts.PARAMETER_S, onekey.flatten(EC_Consts.PARAMETER_S)), Test.Result.SUCCESS)); - tests.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_REMOTE, EC_Consts.CURVE_external, EC_Consts.PARAMETER_W, otherkey.flatten(EC_Consts.PARAMETER_W)), Test.Result.SUCCESS)); - tests.add(new Test.Simple(new Command.ECDH(cardManager, ECTesterApplet.KEYPAIR_REMOTE, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.EXPORT_TRUE, EC_Consts.CORRUPTION_NONE, result.getKA()), Test.Result.SUCCESS, (command, response) -> { + testVector.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_LOCAL, EC_Consts.CURVE_external, EC_Consts.PARAMETER_S, onekey.flatten(EC_Consts.PARAMETER_S)), Test.Result.SUCCESS)); + testVector.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_REMOTE, EC_Consts.CURVE_external, EC_Consts.PARAMETER_W, otherkey.flatten(EC_Consts.PARAMETER_W)), Test.Result.SUCCESS)); + testVector.add(new Test.Simple(new Command.ECDH(cardManager, ECTesterApplet.KEYPAIR_REMOTE, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.EXPORT_TRUE, EC_Consts.CORRUPTION_NONE, result.getKA()), Test.Result.SUCCESS, (command, response) -> { Response.ECDH dh = (Response.ECDH) response; if (!dh.successful() || !dh.hasSecret()) return Test.Result.FAILURE; @@ -206,6 +214,8 @@ public abstract class TestSuite { } return Test.Result.SUCCESS; })); + //tests.addAll(testVector); + tests.add(Test.Compound.all(Result.SUCCESS, "Test vector " + result.getId(), testVector.toArray(new Test[0]))); tests.add(new Test.Simple(new Command.Cleanup(cardManager), Test.Result.ANY)); } @@ -213,6 +223,9 @@ public abstract class TestSuite { } } + /** + * + */ public static class Composite extends TestSuite { public Composite(EC_Store dataStore, ECTester.Config cfg, OutputWriter writer) { @@ -252,6 +265,9 @@ public abstract class TestSuite { } } + /** + * + */ public static class Invalid extends TestSuite { public Invalid(EC_Store dataStore, ECTester.Config cfg, OutputWriter writer) { @@ -299,6 +315,9 @@ public abstract class TestSuite { } } + /** + * + */ public static class Wrong extends TestSuite { public Wrong(EC_Store dataStore, ECTester.Config cfg, OutputWriter writer) { |
