blob: 8b6815b106d9b1a560c458a97d79ac1c01ab258a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
package cz.crcs.ectester.standalone.test;
import cz.crcs.ectester.common.test.BaseTestable;
import cz.crcs.ectester.common.test.TestException;
import cz.crcs.ectester.common.test.Testable;
import java.security.InvalidKeyException;
import java.security.Signature;
import java.security.SignatureException;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
public class SignatureTestable extends BaseTestable {
private Signature sig;
private ECPrivateKey signKey;
private ECPublicKey verifyKey;
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;
}
public byte[] getSignature() {
return signature;
}
public boolean getVerified() {
return verified;
}
@Override
public void run() throws TestException {
try {
sig.initSign(signKey);
} catch (InvalidKeyException e) {
throw new TestException(e);
}
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) {
throw new TestException(e);
}
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;
hasRun = true;
}
}
|