01: package org.bouncycastle.crypto.test;
02:
03: import org.bouncycastle.crypto.BlockCipher;
04: import org.bouncycastle.crypto.DataLengthException;
05: import org.bouncycastle.crypto.engines.NullEngine;
06: import org.bouncycastle.crypto.params.KeyParameter;
07: import org.bouncycastle.util.encoders.Hex;
08: import org.bouncycastle.util.test.SimpleTest;
09:
10: public class NullTest extends CipherTest {
11: static SimpleTest[] tests = { new BlockCipherVectorTest(0,
12: new NullEngine(), new KeyParameter(Hex.decode("00")), "00",
13: "00") };
14:
15: NullTest() {
16: super (tests, new NullEngine(), new KeyParameter(new byte[2]));
17: }
18:
19: public String getName() {
20: return "Null";
21: }
22:
23: public void performTest() throws Exception {
24: super .performTest();
25:
26: BlockCipher engine = new NullEngine();
27:
28: engine.init(true, null);
29:
30: byte[] buf = new byte[1];
31:
32: engine.processBlock(buf, 0, buf, 0);
33:
34: if (buf[0] != 0) {
35: fail("NullCipher changed data!");
36: }
37:
38: byte[] shortBuf = new byte[0];
39:
40: try {
41: engine.processBlock(shortBuf, 0, buf, 0);
42:
43: fail("failed short input check");
44: } catch (DataLengthException e) {
45: // expected
46: }
47:
48: try {
49: engine.processBlock(buf, 0, shortBuf, 0);
50:
51: fail("failed short output check");
52: } catch (DataLengthException e) {
53: // expected
54: }
55: }
56:
57: public static void main(String[] args) {
58: runTest(new NullTest());
59: }
60: }
|