aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/reader/test/TestVectorSuite.java
diff options
context:
space:
mode:
authorJ08nY2017-11-05 16:48:30 +0100
committerJ08nY2017-11-05 16:48:30 +0100
commitdaaa7abd91ff8ae12e0b1835045489acbda0539f (patch)
tree1a2a944473285359a9af3691f2ce69b608264f12 /src/cz/crcs/ectester/reader/test/TestVectorSuite.java
parent16f20afbff36a7e048d24d7e7d1db8657f002c5e (diff)
downloadECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.tar.gz
ECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.tar.zst
ECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.zip
Implement Result.ExpectedValue to add more logic to test evaluation.
- Introduces a new enum Result.ExpectedValue, which is used to signify what Test results are expected. - Changes the Result.Value enum to contain information about what was expected. It gains more values: - UXSUCCESS -> Unexpected success. - XFAILURE -> Expected failure. The values SUCCESS and XFAILURE are the OK, values. - Creates a hierarchy of evaluating Responses, Simple tests and Compoung tests. Simple test evaluates the OK property of the response object (using .successfull() method) and again exposes its OK property which depends on the tests ExpectedValue and the response success. Compound test evaluates the OK property of the Simple tests it contains (using the .ok() method) and again exposes its OK property which depends on the concrete Compound test variant, but involves some ExpectedValues and the success of the individual Simple tests it contains.
Diffstat (limited to '')
-rw-r--r--src/cz/crcs/ectester/reader/test/TestVectorSuite.java25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/cz/crcs/ectester/reader/test/TestVectorSuite.java b/src/cz/crcs/ectester/reader/test/TestVectorSuite.java
index 7a2767e..ff46feb 100644
--- a/src/cz/crcs/ectester/reader/test/TestVectorSuite.java
+++ b/src/cz/crcs/ectester/reader/test/TestVectorSuite.java
@@ -16,6 +16,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import static cz.crcs.ectester.reader.test.Result.ExpectedValue;
+import static cz.crcs.ectester.reader.test.Result.Value;
+
/**
* @author Jan Jancar johny@neuromancer.sk
*/
@@ -55,25 +58,25 @@ public class TestVectorSuite extends TestSuite {
}
List<Test> testVector = new LinkedList<>();
- testVector.add(new Test.Simple(new Command.Allocate(cardManager, ECTesterApplet.KEYPAIR_BOTH, curve.getBits(), curve.getField()), Result.Value.SUCCESS));
- testVector.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, curve.getParams(), curve.flatten()), Result.Value.SUCCESS));
- //tests.add(new Test.Simple(new Command.Generate(cardManager, ECTesterApplet.KEYPAIR_BOTH), Result.Value.SUCCESS));
- 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)), Result.Value.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)), Result.Value.SUCCESS));
+ testVector.add(new Test.Simple(new Command.Allocate(cardManager, ECTesterApplet.KEYPAIR_BOTH, curve.getBits(), curve.getField()), ExpectedValue.SUCCESS));
+ testVector.add(new Test.Simple(new Command.Set(cardManager, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, curve.getParams(), curve.flatten()), ExpectedValue.SUCCESS));
+ //tests.add(new Test.Simple(new Command.Generate(cardManager, ECTesterApplet.KEYPAIR_BOTH), ExpectedValue.SUCCESS));
+ 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)), ExpectedValue.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)), ExpectedValue.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()), (command, response) -> {
Response.ECDH dh = (Response.ECDH) response;
if (!dh.successful())
- return new Result(Result.Value.FAILURE, "ECDH was unsuccessful.");
+ return new Result(Value.FAILURE, "ECDH was unsuccessful.");
if (!dh.hasSecret())
- return new Result(Result.Value.FAILURE, "ECDH response did not contain the derived secret.");
+ return new Result(Value.FAILURE, "ECDH response did not contain the derived secret.");
if (!Util.compareBytes(dh.getSecret(), 0, result.getParam(0), 0, dh.secretLength())) {
int firstDiff = Util.diffBytes(dh.getSecret(), 0, result.getParam(0), 0, dh.secretLength());
- return new Result(Result.Value.FAILURE, "ECDH derived secret does not match the test, first difference was at byte " + String.valueOf(firstDiff) + ".");
+ return new Result(Value.FAILURE, "ECDH derived secret does not match the test, first difference was at byte " + String.valueOf(firstDiff) + ".");
}
- return new Result(Result.Value.SUCCESS);
+ return new Result(Value.SUCCESS);
}));
- tests.add(Test.Compound.all(Result.Value.SUCCESS, "Test vector " + result.getId(), testVector.toArray(new Test[0])));
- tests.add(new Test.Simple(new Command.Cleanup(cardManager), Result.Value.ANY));
+ tests.add(Test.Compound.all(ExpectedValue.SUCCESS, "Test vector " + result.getId(), testVector.toArray(new Test[0])));
+ tests.add(new Test.Simple(new Command.Cleanup(cardManager), ExpectedValue.ANY));
}
}