blob: a24346e1206695a660d4fe6e7dd5b4b475600119 (
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
|
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()));
}
});
}
public static KeyAgreementTest function(KeyAgreementTestable ka, TestCallback<KeyAgreementTestable> callback) {
return new KeyAgreementTest(ka, callback);
}
@Override
public String getDescription() {
return null;
}
@Override
public void run() throws TestException {
ka.run();
result = callback.apply(ka);
hasRun = true;
}
}
|