diff options
| author | J08nY | 2017-11-13 18:03:00 +0100 |
|---|---|---|
| committer | J08nY | 2017-11-13 18:03:00 +0100 |
| commit | cccf2c9c382fa63c68a6c3821d587bc2caa72b05 (patch) | |
| tree | c97b1ce7c3a81b0b2c23d6c36a2c22bef8056c2d /src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java | |
| parent | 9e615b101398bd4c8e2678bf86337e2756a8ee7a (diff) | |
| download | ECTester-cccf2c9c382fa63c68a6c3821d587bc2caa72b05.tar.gz ECTester-cccf2c9c382fa63c68a6c3821d587bc2caa72b05.tar.zst ECTester-cccf2c9c382fa63c68a6c3821d587bc2caa72b05.zip | |
Add KeyAgreement/KeyGeneration/Signature tests. Implement KeyAgreementTest.
Diffstat (limited to '')
| -rw-r--r-- | src/cz/crcs/ectester/standalone/test/KeyAgreementTestable.java | 80 |
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; + } +} |
