aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone/test/SignatureTestable.java
diff options
context:
space:
mode:
authorJ08nY2018-05-28 20:06:18 +0200
committerJ08nY2018-05-28 20:06:18 +0200
commita4e52b21b1dad5f96df409c44e5b4d611bba01b9 (patch)
tree36f9d21894fc702a4f544bd0145b403ba3930074 /src/cz/crcs/ectester/standalone/test/SignatureTestable.java
parentff6be88e469608a67945a274ec2180aee3f3ccd2 (diff)
downloadECTester-a4e52b21b1dad5f96df409c44e5b4d611bba01b9.tar.gz
ECTester-a4e52b21b1dad5f96df409c44e5b4d611bba01b9.tar.zst
ECTester-a4e52b21b1dad5f96df409c44e5b4d611bba01b9.zip
Implement tracking of stage of execution of standalone testables.
- Output this stage in all the formats.
Diffstat (limited to 'src/cz/crcs/ectester/standalone/test/SignatureTestable.java')
-rw-r--r--src/cz/crcs/ectester/standalone/test/SignatureTestable.java121
1 files changed, 0 insertions, 121 deletions
diff --git a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java b/src/cz/crcs/ectester/standalone/test/SignatureTestable.java
deleted file mode 100644
index 6bc9b30..0000000
--- a/src/cz/crcs/ectester/standalone/test/SignatureTestable.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package cz.crcs.ectester.standalone.test;
-
-import cz.crcs.ectester.common.test.BaseTestable;
-import cz.crcs.ectester.common.test.TestException;
-
-import java.security.InvalidKeyException;
-import java.security.SecureRandom;
-import java.security.Signature;
-import java.security.SignatureException;
-import java.security.interfaces.ECPrivateKey;
-import java.security.interfaces.ECPublicKey;
-
-/**
- * @author Jan Jancar johny@neuromancer.sk
- */
-public class SignatureTestable extends BaseTestable {
- private Signature sig;
- private ECPrivateKey signKey;
- private ECPublicKey verifyKey;
- private KeyGeneratorTestable kgt;
- private byte[] data;
- private byte[] signature;
- private boolean verified;
-
- public SignatureTestable(Signature sig, ECPrivateKey signKey, ECPublicKey verifyKey, byte[] data) {
- this.sig = sig;
- this.signKey = signKey;
- this.verifyKey = verifyKey;
- this.data = data;
- if (data == null) {
- SecureRandom random = new SecureRandom();
- this.data = new byte[32];
- random.nextBytes(this.data);
- }
- }
-
- public SignatureTestable(Signature sig, KeyGeneratorTestable kgt, byte[] data) {
- this(sig, null, null, data);
- this.kgt = kgt;
- }
-
- public Signature getSig() {
- return sig;
- }
-
- public byte[] getData() {
- return data;
- }
-
- public byte[] getSignature() {
- return signature;
- }
-
- public boolean getVerified() {
- return verified;
- }
-
- @Override
- public void run() {
- try {
- if (kgt != null) {
- signKey = (ECPrivateKey) kgt.getKeyPair().getPrivate();
- verifyKey = (ECPublicKey) kgt.getKeyPair().getPublic();
- }
-
- try {
- sig.initSign(signKey);
- } catch (InvalidKeyException e) {
- ok = false;
- hasRun = true;
- return;
- }
-
- try {
- sig.update(data);
- } catch (SignatureException e) {
- ok = false;
- hasRun = true;
- return;
- }
-
- try {
- signature = sig.sign();
- } catch (SignatureException e) {
- ok = false;
- hasRun = true;
- return;
- }
-
- try {
- sig.initVerify(verifyKey);
- } catch (InvalidKeyException e) {
- ok = false;
- hasRun = true;
- return;
- }
-
- try {
- sig.update(data);
- } catch (SignatureException e) {
- ok = false;
- hasRun = true;
- return;
- }
-
- try {
- verified = sig.verify(signature);
- } catch (SignatureException e) {
- ok = false;
- hasRun = true;
- }
-
- ok = true;
- } catch (Exception ex) {
- ok = false;
- error = true;
- errorCause = ex;
- }
- hasRun = true;
- }
-}