summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJ08nY2017-10-25 00:10:56 +0200
committerJ08nY2017-10-25 00:10:56 +0200
commitffbbf6e6482d48f4d49dd2ba1a63f687978415f8 (patch)
treea2e4e713199931f229b9bc55edc01b602c8a2154 /src
parent76d5e632d26515a6490009d0781604f3a1f2621f (diff)
downloadECTester-ffbbf6e6482d48f4d49dd2ba1a63f687978415f8.tar.gz
ECTester-ffbbf6e6482d48f4d49dd2ba1a63f687978415f8.tar.zst
ECTester-ffbbf6e6482d48f4d49dd2ba1a63f687978415f8.zip
Diffstat (limited to 'src')
-rw-r--r--src/cz/crcs/ectester/reader/output/TextOutputWriter.java24
-rw-r--r--src/cz/crcs/ectester/reader/output/YAMLOutputWriter.java6
-rw-r--r--src/cz/crcs/ectester/reader/test/Test.java39
-rw-r--r--src/cz/crcs/ectester/reader/test/TestSuite.java29
4 files changed, 83 insertions, 15 deletions
diff --git a/src/cz/crcs/ectester/reader/output/TextOutputWriter.java b/src/cz/crcs/ectester/reader/output/TextOutputWriter.java
index 6887f61..d9669be 100644
--- a/src/cz/crcs/ectester/reader/output/TextOutputWriter.java
+++ b/src/cz/crcs/ectester/reader/output/TextOutputWriter.java
@@ -47,22 +47,28 @@ public class TextOutputWriter implements OutputWriter {
output.flush();
}
- @Override
- public void outputTest(Test t) {
+ private String testString(Test t) {
if (!t.hasRun())
- return;
+ return null;
- String out = "";
+ StringBuilder out = new StringBuilder();
if (t instanceof Test.Simple) {
Test.Simple test = (Test.Simple) t;
- out += String.format("%-62s:", testPrefix(t) + " " + test.getDescription()) + " : ";
- out += responseSuffix(test.getResponse());
- } else if (t instanceof Test.Compound) {
+ out.append(String.format("%-62s:", testPrefix(t) + " " + test.getDescription())).append(" : ");
+ out.append(responseSuffix(test.getResponse()));
+ } else if (t instanceof Test.Compound) {
Test.Compound test = (Test.Compound) t;
- out += String.format("%-62s:", testPrefix(t) + " " + test.getDescription());
+ for (Test innerTest : test.getTests()) {
+ out.append(" ").append(testString(innerTest)).append(System.lineSeparator());
+ }
+ out.append(String.format("%-62s:", testPrefix(t) + " " + test.getDescription()));
}
+ return out.toString();
+ }
- output.println(out);
+ @Override
+ public void outputTest(Test t) {
+ output.println(testString(t));
output.flush();
}
diff --git a/src/cz/crcs/ectester/reader/output/YAMLOutputWriter.java b/src/cz/crcs/ectester/reader/output/YAMLOutputWriter.java
index e81cbad..211bd47 100644
--- a/src/cz/crcs/ectester/reader/output/YAMLOutputWriter.java
+++ b/src/cz/crcs/ectester/reader/output/YAMLOutputWriter.java
@@ -82,7 +82,11 @@ public class YAMLOutputWriter implements OutputWriter {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
- String out = yaml.dump(testRun);
+
+ Map<String, List<Object>> result = new HashMap<>();
+ result.put("testRun", testRun);
+ String out = yaml.dump(result);
+
output.println(out);
output.println("---");
}
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) {