Skip to content

Commit 1e2a30e

Browse files
committed
ref #4
1 parent 307e56c commit 1e2a30e

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/**
2+
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
3+
*
4+
* Copyright 2014-2016 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
package de.rub.nds.modifiablevariable.util;
10+
import java.math.BigInteger;
11+
import static org.junit.Assert.assertArrayEquals;
12+
import static org.junit.Assert.assertEquals;
13+
import org.junit.Test;
14+
15+
/**
16+
* @author Juraj Somorovsky - juraj.somorovsky@rub.de
17+
* @author Florian Pfützenreuter <Florian.Pfuetzenreuter@rub.de>
18+
* @author Matthias Terlinde <matthias.terlinde@rub.de>
19+
*/
20+
public class ArrayConverterTest {
21+
22+
/**
23+
* Test of longToUint64Bytes method, of class ArrayConverter.
24+
*/
25+
@Test
26+
public void testLongToUint64Bytes() {
27+
}
28+
29+
/**
30+
* Test of longToUint32Bytes method, of class ArrayConverter.
31+
*/
32+
@Test
33+
public void testLongToUint32Bytes() {
34+
}
35+
36+
/**
37+
* Test of intToBytes method, of class ArrayConverter.
38+
*/
39+
@Test
40+
public void testIntToBytes() {
41+
int toParse = 5717;
42+
byte[] result = ArrayConverter.intToBytes(toParse, 2);
43+
assertArrayEquals("The conversion result of 5717 should be {0x16} {0x55}", new byte[]{0x16, 0x55}, result);
44+
}
45+
46+
/**
47+
* Test of bytesToInt method, of class ArrayConverter.
48+
*/
49+
@Test
50+
public void testBytesToInt() {
51+
byte[] toParse = {0x16, 0x55};
52+
int expectedResult = 5717;
53+
assertEquals("The conversion result of {0x16, 0x55} should be 5717", expectedResult, ArrayConverter.bytesToInt(toParse));
54+
}
55+
56+
/**
57+
* Test of bytesToLong method, of class ArrayConverter.
58+
*/
59+
@Test
60+
public void testBytesToLong() {
61+
/** TODO get the casting correct.
62+
long result = 571714867398058L;
63+
byte[] toParse = {0x02, 0x07, (byte) 0xf8, (byte) 0xbd, (byte) 0x95, (byte) 0x85, (byte) 0xaa};
64+
byte[] test = ArrayConverter.longToBytes(result, 7);
65+
int a = 0;
66+
//assertEquals(result, ArrayConverter.bytesToLong(toParse));
67+
*/
68+
69+
}
70+
71+
/**
72+
* Test of bytesToHexString method, of class ArrayConverter.
73+
*/
74+
@Test
75+
public void testBytesToHexString_byteArr() {
76+
byte[] toTest = new byte[]{0x00, 0x11, 0x22, 0x33, 0x44};
77+
assertEquals("00 11 22 33 44", ArrayConverter.bytesToHexString(toTest));
78+
toTest = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
79+
assertEquals("00 01 02 03 04 05 06 07 08", ArrayConverter.bytesToHexString(toTest));
80+
toTest = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10};
81+
assertEquals("00 01 02 03 04 05 06 07 08 09 10", ArrayConverter.bytesToHexString(toTest));
82+
toTest = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
83+
0x07,};
84+
assertEquals("\n00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07", ArrayConverter.bytesToHexString(toTest));
85+
toTest = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
86+
0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,};
87+
assertEquals(
88+
"\n00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07\n00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07",
89+
ArrayConverter.bytesToHexString(toTest));
90+
}
91+
92+
/**
93+
* Test of bytesToHexString method, of class ArrayConverter.
94+
*/
95+
@Test
96+
public void testBytesToHexString_byteArr_boolean() {
97+
}
98+
99+
/**
100+
* Test of bytesToHexString method, of class ArrayConverter.
101+
*/
102+
@Test
103+
public void testBytesToHexString_3args() {
104+
}
105+
106+
/**
107+
* Test of concatenate method, of class ArrayConverter.
108+
*/
109+
@Test
110+
public void testConcatenate_GenericType() {
111+
}
112+
113+
/**
114+
* Test of concatenate method, of class ArrayConverter.
115+
*/
116+
@Test
117+
public void testConcatenate_byteArrArr() {
118+
}
119+
120+
/**
121+
* Test of makeArrayNonZero method, of class ArrayConverter.
122+
*/
123+
@Test
124+
public void testMakeArrayNonZero() {
125+
}
126+
127+
/**
128+
* Test of bigIntegerToByteArray method, of class ArrayConverter.
129+
*/
130+
@Test
131+
public void testBigIntegerToByteArray_3args() {
132+
}
133+
134+
/**
135+
* Test of bigIntegerToByteArray method, of class ArrayConverter.
136+
*/
137+
@Test
138+
public void testBigIntegerToByteArray_BigInteger() {
139+
}
140+
141+
/**
142+
* Test of convertListToArray method, of class ArrayConverter.
143+
*/
144+
@Test
145+
public void testConvertListToArray() {
146+
}
147+
148+
/**
149+
* Test of hexStringToByteArray method, of class ArrayConverter.
150+
*/
151+
@Test
152+
public void testHexStringToByteArray() {
153+
String hex = "01";
154+
assertArrayEquals("Testing simple one byte hex value", new byte[]{0x01},
155+
ArrayConverter.hexStringToByteArray(hex));
156+
hex = "FF";
157+
assertArrayEquals("Testing one byte hex value > 0x7f", new byte[]{(byte) 0xff},
158+
ArrayConverter.hexStringToByteArray(hex));
159+
hex = "FFFFFF";
160+
assertArrayEquals("Testing one byte hex value > 0x7f", new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff},
161+
ArrayConverter.hexStringToByteArray(hex));
162+
}
163+
164+
@Test
165+
public void testBigIntegerToNullPaddedByteArray() {
166+
BigInteger test = new BigInteger("1D42C86F7923DFEC", 16);
167+
168+
assertArrayEquals("Check zero output size", new byte[0],
169+
ArrayConverter.bigIntegerToNullPaddedByteArray(test, 0));
170+
assertArrayEquals("Check check output size smaller than input", new byte[]{(byte) 0xEC},
171+
ArrayConverter.bigIntegerToNullPaddedByteArray(test, 1));
172+
assertArrayEquals("Check output size bigger than input size",
173+
ArrayConverter.hexStringToByteArray("0000000000000000000000001D42C86F7923DFEC"),
174+
ArrayConverter.bigIntegerToNullPaddedByteArray(test, 20));
175+
}
176+
177+
@Test
178+
public void testLongToUint48Bytes() {
179+
long testValue = 0x0000123456789ABCL;
180+
byte[] expectedResult = ArrayConverter.hexStringToByteArray("123456789ABC");
181+
182+
assertArrayEquals("Assert correct output", expectedResult, ArrayConverter.longToUint48Bytes(testValue));
183+
184+
testValue = 0x0000000000000001L;
185+
expectedResult = ArrayConverter.hexStringToByteArray("000000000001");
186+
187+
assertArrayEquals("Assert correct output", expectedResult, ArrayConverter.longToUint48Bytes(testValue));
188+
}
189+
}

0 commit comments

Comments
 (0)