diff options
Diffstat (limited to 'src/cz/crcs/ectester/standalone/test')
4 files changed, 173 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..9c761fa --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/KeyAgreementTest.java @@ -0,0 +1,55 @@ +package cz.crcs.ectester.standalone.test; + +import cz.crcs.ectester.common.test.Result; +import cz.crcs.ectester.common.test.Test; +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 Test { + private KeyAgreementTestable ka; + private TestCallback<KeyAgreementTestable> callback; + + private KeyAgreementTest(KeyAgreementTestable ka, TestCallback<KeyAgreementTestable> callback) { + this.ka = ka; + this.callback = 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); + } else { + return new Result(Result.Value.FAILURE); + } + } + }); + } + + 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())); + } + }); + } + + @Override + public String getDescription() { + return null; + } + + @Override + public void run() throws TestException { + ka.run(); + result = callback.apply(ka); + hasRun = true; + } +} diff --git a/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java b/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java new file mode 100644 index 0000000..51c295c --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java @@ -0,0 +1,80 @@ +package cz.crcs.ectester.standalone.test; + +import cz.crcs.ectester.common.test.TestException; +import cz.crcs.ectester.common.test.Testable; + +import javax.crypto.KeyAgreement; +import java.security.InvalidKeyException; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class KeyAgreementTestable implements Testable { + private KeyAgreement ka; + private ECPrivateKey privateKey; + private ECPublicKey publicKey; + private byte[] secret; + private boolean hasRun; + private boolean error; + private boolean ok; + + public KeyAgreementTestable(KeyAgreement ka, ECPrivateKey privateKey, ECPublicKey publicKey) { + this.ka = ka; + this.privateKey = privateKey; + this.publicKey = publicKey; + } + + public byte[] getSecret() { + if (!hasRun) { + return null; + } + return secret; + } + + @Override + public boolean hasRun() { + return hasRun; + } + + @Override + public void run() throws TestException { + try { + ka.init(privateKey); + } catch (InvalidKeyException ikex) { + throw new TestException(ikex); + } + + try { + ka.doPhase(publicKey, true); + } catch (InvalidKeyException ikex) { + throw new TestException(ikex); + } catch (IllegalStateException isex) { + error = true; + ok = false; + hasRun = true; + return; + } + + try { + secret = ka.generateSecret(); + } catch (IllegalStateException isex) { + error = true; + ok = false; + hasRun = true; + return; + } + ok = true; + } + + @Override + public boolean ok() { + return ok; + } + + @Override + public boolean error() { + return error; + } +} diff --git a/src/cz/crcs/ectester/standalone/test/KeyGenerationTest.java b/src/cz/crcs/ectester/standalone/test/KeyGenerationTest.java new file mode 100644 index 0000000..7a96ba1 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/KeyGenerationTest.java @@ -0,0 +1,19 @@ +package cz.crcs.ectester.standalone.test; + +import cz.crcs.ectester.common.test.Test; +import cz.crcs.ectester.common.test.TestException; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class KeyGenerationTest extends Test { + @Override + public String getDescription() { + return null; + } + + @Override + public void run() throws TestException { + + } +} diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTest.java b/src/cz/crcs/ectester/standalone/test/SignatureTest.java new file mode 100644 index 0000000..2102db0 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/test/SignatureTest.java @@ -0,0 +1,19 @@ +package cz.crcs.ectester.standalone.test; + +import cz.crcs.ectester.common.test.Test; +import cz.crcs.ectester.common.test.TestException; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class SignatureTest extends Test { + @Override + public String getDescription() { + return null; + } + + @Override + public void run() throws TestException { + + } +} |
