aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java')
-rw-r--r--src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java80
1 files changed, 80 insertions, 0 deletions
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;
+ }
+}