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; import java.util.Arrays; /** * @author Jan Jancar johny@neuromancer.sk */ public class KeyAgreementTest extends SimpleTest { private KeyAgreementTest(KeyAgreementTestable ka, TestCallback callback) { super(ka, callback); } public static KeyAgreementTest match(KeyAgreementTestable ka, byte[] expectedSecret) { return new KeyAgreementTest(ka, new TestCallback() { @Override public Result apply(KeyAgreementTestable ka) { if (Arrays.equals(ka.getSecret(), expectedSecret)) { return new Result(Result.Value.SUCCESS); } else { return new Result(Result.Value.FAILURE); } } }); } public static KeyAgreementTest expect(KeyAgreementTestable ka, Result.ExpectedValue expected) { return new KeyAgreementTest(ka, new TestCallback() { @Override public Result apply(KeyAgreementTestable keyAgreementTestable) { return new Result(Result.Value.fromExpected(expected, keyAgreementTestable.ok(), keyAgreementTestable.error())); } }); } public static KeyAgreementTest function(KeyAgreementTestable ka, TestCallback callback) { return new KeyAgreementTest(ka, callback); } @Override public String getDescription() { return "KeyAgreement test"; } @Override public void run() throws TestException { if (hasRun) return; testable.run(); result = callback.apply(testable); hasRun = true; } }