summaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java
diff options
context:
space:
mode:
authorJ08nY2018-01-23 17:31:15 +0100
committerJ08nY2018-01-23 17:31:15 +0100
commitcb6c6b8b1274fe5a340c4317a4b015ea0ef15396 (patch)
tree864a54dcdf07da33cd139312c8b0ee693e1a0eff /src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java
parent6c46a27a52854aee24f7a37e74002bd6f4485723 (diff)
parentc581e39e539e6dadb49d9f83f563ab2b375f6e0b (diff)
downloadECTester-0.2.0.tar.gz
ECTester-0.2.0.tar.zst
ECTester-0.2.0.zip
Diffstat (limited to 'src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java')
-rw-r--r--src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java
new file mode 100644
index 0000000..5f697c4
--- /dev/null
+++ b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java
@@ -0,0 +1,57 @@
+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<KeyAgreementTestable> {
+ private KeyAgreementTest(KeyAgreementTestable ka, TestCallback<KeyAgreementTestable> callback) {
+ super(ka, callback);
+ }
+
+ public static KeyAgreementTest match(KeyAgreementTestable ka, byte[] expectedSecret) {
+ return new KeyAgreementTest(ka, new TestCallback<KeyAgreementTestable>() {
+ @Override
+ public Result apply(KeyAgreementTestable ka) {
+ if (Arrays.equals(ka.getSecret(), expectedSecret)) {
+ return new Result(Result.Value.SUCCESS, "The KeyAgreement result matched the expected derived secret.");
+ } else {
+ return new Result(Result.Value.FAILURE, "The KeyAgreement result did not match the expected derived secret.");
+ }
+ }
+ });
+ }
+
+ public static KeyAgreementTest expect(KeyAgreementTestable ka, Result.ExpectedValue expected) {
+ return new KeyAgreementTest(ka, new TestCallback<KeyAgreementTestable>() {
+ @Override
+ public Result apply(KeyAgreementTestable keyAgreementTestable) {
+ return new Result(Result.Value.fromExpected(expected, keyAgreementTestable.ok(), keyAgreementTestable.error()));
+ }
+ });
+ }
+
+ public static KeyAgreementTest function(KeyAgreementTestable ka, TestCallback<KeyAgreementTestable> callback) {
+ return new KeyAgreementTest(ka, callback);
+ }
+
+ @Override
+ public String getDescription() {
+ return "KeyAgreement " + testable.getKa().getAlgorithm();
+ }
+
+ @Override
+ public void run() throws TestException {
+ if (hasRun)
+ return;
+ testable.run();
+ result = callback.apply(testable);
+ hasRun = true;
+ }
+}