1 package org.jastacry.layer;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.io.ByteArrayInputStream;
6 import java.io.ByteArrayOutputStream;
7 import java.io.InputStream;
8 import java.io.OutputStream;
9
10 import org.jastacry.JastacryException;
11 import org.junit.jupiter.api.AfterEach;
12 import org.junit.jupiter.api.BeforeEach;
13 import org.junit.jupiter.api.Test;
14
15
16
17
18
19
20
21 public class TestLayerAesEcb
22 {
23
24
25
26 private final String testdata = "The quick brown fox jumps over the lazy dog.";
27
28
29
30
31 private AesEcbLayer layerEncrypt = null;
32
33
34
35
36 private AesEcbLayer layerDecrypt = null;
37
38
39
40
41 private static final String INITVALUE = "Passwort";
42
43
44
45
46
47
48
49 @BeforeEach
50 public void setUp() throws Exception
51 {
52 layerEncrypt = new AesEcbLayer();
53 layerEncrypt.init(INITVALUE);
54
55 layerDecrypt = new AesEcbLayer();
56 layerDecrypt.init(INITVALUE);
57 }
58
59
60
61
62
63
64
65 @AfterEach
66 public void tearDown() throws Exception
67 {
68 layerEncrypt = null;
69 layerDecrypt = null;
70 }
71
72
73
74
75
76
77
78 @Test
79
80 public void testEncDecStream() throws JastacryException
81 {
82 byte[] buf = testdata.getBytes();
83 final InputStream isEncode = new ByteArrayInputStream(buf);
84 final ByteArrayOutputStream osEncode = new ByteArrayOutputStream();
85 layerEncrypt.encStream(isEncode, osEncode);
86 buf = osEncode.toByteArray();
87
88 final InputStream isDecode = new ByteArrayInputStream(buf);
89 final OutputStream osDecode = new ByteArrayOutputStream();
90 layerDecrypt.decStream(isDecode, osDecode);
91 assertEquals("decoding differs", testdata, osDecode.toString());
92
93 }
94
95
96
97
98 @Test
99 public void testToString()
100 {
101 assertEquals("Layer name mismatch", AesEcbLayer.LAYERNAME, layerEncrypt.toString());
102 }
103
104
105
106
107 @Test
108 public void testEquals()
109 {
110 AesEcbLayer l1 = new AesEcbLayer();
111 AesEcbLayer l2 = new AesEcbLayer();
112 l1.init(INITVALUE);
113 l2.init(INITVALUE);
114 assertEquals("Layer object equal", l1, l2);
115 }
116
117
118
119
120 @Test
121 public void testEqualsSame()
122 {
123 AesEcbLayer l1 = new AesEcbLayer();
124 l1.init(INITVALUE);
125 assertEquals("Layer object same", l1, l1);
126 }
127
128
129
130
131 @Test
132 public void testNotEqualsNull()
133 {
134 AesEcbLayer l1 = new AesEcbLayer();
135 l1.init(INITVALUE);
136 Object o = null;
137 assertEquals("Layer object null unequal", false, l1.equals(o));
138 }
139
140
141
142
143 @Test
144 public void testNotEqualsWrongclass()
145 {
146 AesEcbLayer l1 = new AesEcbLayer();
147 l1.init(INITVALUE);
148 Object o = new Object();
149 assertEquals("Layer object wrong class unequal", false, l1.equals(o));
150 }
151
152
153
154
155 @Test
156 public void testHashcode()
157 {
158 AesEcbLayer l1 = new AesEcbLayer();
159 AesEcbLayer l2 = new AesEcbLayer();
160 l1.init(INITVALUE);
161 l2.init(INITVALUE);
162 assertEquals("Layer hash equal", l1.hashCode(), l2.hashCode());
163 }
164
165 }