diff options
Diffstat (limited to 'src')
5 files changed, 41 insertions, 4 deletions
diff --git a/src/cz/crcs/ectester/common/test/CompoundTest.java b/src/cz/crcs/ectester/common/test/CompoundTest.java index 4b1df16..d7a2d9c 100644 --- a/src/cz/crcs/ectester/common/test/CompoundTest.java +++ b/src/cz/crcs/ectester/common/test/CompoundTest.java @@ -82,6 +82,43 @@ public class CompoundTest extends Test { return result; } + public static CompoundTest greedyAllTry(Result.ExpectedValue what, Test... all) { + return new CompoundTest((tests) -> { + int run = 0; + int ok = 0; + for (Test test : tests) { + if (test.hasRun()) { + run++; + if (Result.Value.fromExpected(what, test.ok()).ok()) { + ok++; + } + } + } + if (run == tests.length) { + if (ok == run) { + return new Result(Result.Value.SUCCESS, "All sub-tests had the expected result."); + } else { + return new Result(Result.Value.FAILURE, "Some sub-tests did not have the expected result."); + } + } else { + return new Result(Result.Value.SUCCESS, "All considered sub-tests had the expected result."); + } + }, (tests) -> { + for (Test t : tests) { + t.run(); + if (!t.ok()) { + break; + } + } + }, all); + } + + public static CompoundTest greedyAllTry(Result.ExpectedValue what, String description, Test... all) { + CompoundTest result = CompoundTest.greedyAllTry(what, all); + result.setDescription(description); + return result; + } + public static CompoundTest greedyAny(Result.ExpectedValue what, Test... any) { return new CompoundTest((tests) -> { for (Test test : tests) { diff --git a/src/cz/crcs/ectester/reader/test/CardCofactorTestSuite.java b/src/cz/crcs/ectester/reader/test/CardCofactorTestSuite.java index c17a7d9..fd3f0ae 100644 --- a/src/cz/crcs/ectester/reader/test/CardCofactorTestSuite.java +++ b/src/cz/crcs/ectester/reader/test/CardCofactorTestSuite.java @@ -53,7 +53,7 @@ public class CardCofactorTestSuite extends CardTestSuite { } Test ecdh = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform ECDH with public points on non-generator subgroup", ecdhTests.toArray(new Test[0])); - doTest(CompoundTest.greedyAll(Result.ExpectedValue.SUCCESS, "Cofactor test of " + curve.getId(), prepare, ecdh)); + doTest(CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Cofactor test of " + curve.getId(), prepare, ecdh)); new Command.Cleanup(this.card).send(); } } diff --git a/src/cz/crcs/ectester/reader/test/CardCompositeCurvesSuite.java b/src/cz/crcs/ectester/reader/test/CardCompositeCurvesSuite.java index e866c25..b931aad 100644 --- a/src/cz/crcs/ectester/reader/test/CardCompositeCurvesSuite.java +++ b/src/cz/crcs/ectester/reader/test/CardCompositeCurvesSuite.java @@ -42,7 +42,7 @@ public class CardCompositeCurvesSuite extends CardTestSuite { Command ecdhCommand = new Command.ECDH_direct(this.card, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.EXPORT_FALSE, EC_Consts.CORRUPTION_NONE, ECTesterApplet.KeyAgreement_ALG_EC_SVDP_DH, key.flatten()); Test ecdh = CommandTest.expect(ecdhCommand, ExpectedValue.FAILURE, "Card correctly rejected to do ECDH over a composite order curve.", "Card incorrectly does ECDH over a composite order curve, leaks bits of private key."); - doTest(CompoundTest.greedyAll(ExpectedValue.SUCCESS, "Composite test of " + curve.getId() + ", " + key.getDesc(), allocate, set, generate, ecdh)); + doTest(CompoundTest.greedyAllTry(ExpectedValue.SUCCESS, "Composite test of " + curve.getId() + ", " + key.getDesc(), allocate, set, generate, ecdh)); new Command.Cleanup(this.card).send(); } } diff --git a/src/cz/crcs/ectester/reader/test/CardInvalidCurvesSuite.java b/src/cz/crcs/ectester/reader/test/CardInvalidCurvesSuite.java index 190a20c..0cf27ec 100644 --- a/src/cz/crcs/ectester/reader/test/CardInvalidCurvesSuite.java +++ b/src/cz/crcs/ectester/reader/test/CardInvalidCurvesSuite.java @@ -58,7 +58,7 @@ public class CardInvalidCurvesSuite extends CardTestSuite { } Test ecdh = CompoundTest.all(ExpectedValue.SUCCESS, "Perform ECDH with invalid public points", ecdhTests.toArray(new Test[0])); - doTest(CompoundTest.greedyAll(ExpectedValue.SUCCESS, "Invalid curve test of " + curve.getId(), prepare, ecdh)); + doTest(CompoundTest.greedyAllTry(ExpectedValue.SUCCESS, "Invalid curve test of " + curve.getId(), prepare, ecdh)); new Command.Cleanup(this.card).send(); } } diff --git a/src/cz/crcs/ectester/reader/test/CardTwistTestSuite.java b/src/cz/crcs/ectester/reader/test/CardTwistTestSuite.java index c301e1e..fad508f 100644 --- a/src/cz/crcs/ectester/reader/test/CardTwistTestSuite.java +++ b/src/cz/crcs/ectester/reader/test/CardTwistTestSuite.java @@ -53,7 +53,7 @@ public class CardTwistTestSuite extends CardTestSuite { } Test ecdh = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform ECDH with public points on twist", ecdhTests.toArray(new Test[0])); - doTest(CompoundTest.greedyAll(Result.ExpectedValue.SUCCESS, "Twist test of " + curve.getId(), prepare, ecdh)); + doTest(CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Twist test of " + curve.getId(), prepare, ecdh)); new Command.Cleanup(this.card).send(); } } |
