Skip to content

Commit f953346

Browse files
committed
Added auto-format as seen in TLS-Attacker
1 parent 2852b92 commit f953346

File tree

4 files changed

+68
-39
lines changed

4 files changed

+68
-39
lines changed

pom.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,27 @@
6868
<version>2.8.2</version>
6969
</dependency>
7070
</dependencies>
71-
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>net.revelc.code</groupId>
75+
<artifactId>formatter-maven-plugin</artifactId>
76+
<version>0.5.2</version>
77+
<configuration>
78+
<configFile>maven-eclipse-codestyle.xml</configFile>
79+
<lineEnding>LF</lineEnding>
80+
</configuration>
81+
<executions>
82+
<execution>
83+
<phase>process-sources</phase>
84+
<goals>
85+
<goal>format</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
</plugin>
90+
</plugins>
91+
</build>
7292
<properties>
7393
<maven.compiler.source>1.7</maven.compiler.source>
7494
<maven.compiler.target>1.7</maven.compiler.target>

src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
/**
2222
*
23-
* @author Robert Merget - robert.merget@rub.de
24-
* Highly Experimental
23+
* @author Robert Merget - robert.merget@rub.de Highly Experimental
2524
*/
2625
@XmlRootElement
2726
@XmlSeeAlso({ IntegerAddModification.class, IntegerExplicitValueModification.class, IntegerSubtractModification.class,

src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public static byte[] longToUint32Bytes(long l) {
5555
/**
5656
* Takes an integer value and stores its last bytes into a byte array
5757
*
58-
* @param value integer value
59-
* @param size byte size of the new integer byte array
58+
* @param value
59+
* integer value
60+
* @param size
61+
* byte size of the new integer byte array
6062
* @return
6163
*/
6264
public static byte[] intToBytes(int value, int size) {
@@ -76,8 +78,10 @@ public static byte[] intToBytes(int value, int size) {
7678
/**
7779
* Takes a long value and stores its last bytes into a byte array
7880
*
79-
* @param value long value
80-
* @param size byte size of the new integer byte array
81+
* @param value
82+
* long value
83+
* @param size
84+
* byte size of the new integer byte array
8185
* @return
8286
*/
8387
public static byte[] longToBytes(long value, int size) {
@@ -155,14 +159,14 @@ public static String bytesToHexString(byte[] array, boolean usePrettyPrinting, b
155159
result.append(" ");
156160
}
157161
result.append(" ");
158-
}
162+
}
159163
}
160164
byte b = array[i];
161165
result.append(String.format("%02X", b));
162166
}
163167
return result.toString();
164168
}
165-
169+
166170
/**
167171
* Like bytesToHexString() without any formatting.
168172
*/
@@ -173,7 +177,7 @@ public static String bytesToRawHexString(byte[] array) {
173177
result.append(String.format("%02X", b));
174178
}
175179
return result.toString();
176-
}
180+
}
177181

178182
@SafeVarargs
179183
public static <T> T[] concatenate(final T[]... arrays) {
@@ -237,8 +241,9 @@ public static void makeArrayNonZero(final byte[] array) {
237241
*
238242
* @param value
239243
* @param blockSize
240-
* @param removeSignByte in a case the removeSignByte is set, the sign byte
241-
* is removed (in case the byte array contains one)
244+
* @param removeSignByte
245+
* in a case the removeSignByte is set, the sign byte is removed
246+
* (in case the byte array contains one)
242247
* @return
243248
*/
244249
public static byte[] bigIntegerToByteArray(BigInteger value, int blockSize, boolean removeSignByte) {

src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* http://www.apache.org/licenses/LICENSE-2.0
88
*/
99
package de.rub.nds.modifiablevariable.util;
10+
1011
import java.math.BigInteger;
1112
import static org.junit.Assert.assertArrayEquals;
1213
import static org.junit.Assert.assertEquals;
@@ -40,31 +41,32 @@ public void testLongToUint32Bytes() {
4041
public void testIntToBytes() {
4142
int toParse = 5717;
4243
byte[] result = ArrayConverter.intToBytes(toParse, 2);
43-
assertArrayEquals("The conversion result of 5717 should be {0x16} {0x55}", new byte[]{0x16, 0x55}, result);
44+
assertArrayEquals("The conversion result of 5717 should be {0x16} {0x55}", new byte[] { 0x16, 0x55 }, result);
4445
}
4546

4647
/**
4748
* Test of bytesToInt method, of class ArrayConverter.
4849
*/
4950
@Test
5051
public void testBytesToInt() {
51-
byte[] toParse = {0x16, 0x55};
52+
byte[] toParse = { 0x16, 0x55 };
5253
int expectedResult = 5717;
53-
assertEquals("The conversion result of {0x16, 0x55} should be 5717", expectedResult, ArrayConverter.bytesToInt(toParse));
54+
assertEquals("The conversion result of {0x16, 0x55} should be 5717", expectedResult,
55+
ArrayConverter.bytesToInt(toParse));
5456
}
5557

5658
/**
5759
* Test of bytesToLong method, of class ArrayConverter.
5860
*/
5961
@Test
6062
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-
*/
63+
/**
64+
* TODO get the casting correct. long result = 571714867398058L; byte[]
65+
* toParse = {0x02, 0x07, (byte) 0xf8, (byte) 0xbd, (byte) 0x95, (byte)
66+
* 0x85, (byte) 0xaa}; byte[] test = ArrayConverter.longToBytes(result,
67+
* 7); int a = 0; //assertEquals(result,
68+
* ArrayConverter.bytesToLong(toParse));
69+
*/
6870

6971
}
7072

@@ -73,17 +75,17 @@ public void testBytesToLong() {
7375
*/
7476
@Test
7577
public void testBytesToHexString_byteArr() {
76-
byte[] toTest = new byte[]{0x00, 0x11, 0x22, 0x33, 0x44};
78+
byte[] toTest = new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44 };
7779
assertEquals("00 11 22 33 44", ArrayConverter.bytesToHexString(toTest));
78-
toTest = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
80+
toTest = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
7981
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};
82+
toTest = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10 };
8183
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+
toTest = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
85+
0x07, };
8486
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+
toTest = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
88+
0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, };
8789
assertEquals(
8890
"\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",
8991
ArrayConverter.bytesToHexString(toTest));
@@ -94,11 +96,13 @@ public void testBytesToHexString_byteArr() {
9496
*/
9597
@Test
9698
public void testBytesToHexString_byteArr_boolean() {
97-
byte[] toTest = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
98-
0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
99+
byte[] toTest = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04,
100+
0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
101+
0x06, 0x07 };
99102
assertEquals("00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07",
100103
ArrayConverter.bytesToHexString(toTest, false));
101-
assertEquals("\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",
104+
assertEquals(
105+
"\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",
102106
ArrayConverter.bytesToHexString(toTest, true));
103107
}
104108

@@ -108,14 +112,15 @@ public void testBytesToHexString_byteArr_boolean() {
108112
@Test
109113
public void testBytesToHexString_3args() {
110114
}
111-
115+
112116
/**
113117
* Test ArrayConverter.bytesToRawHexString().
114118
*/
115119
@Test
116120
public void testBytesToRawHexString() {
117-
byte[] toTest = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
118-
0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
121+
byte[] toTest = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04,
122+
0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
123+
0x06, 0x07 };
119124
assertEquals("0001020304050607000102030405060700010203040506070001020304050607",
120125
ArrayConverter.bytesToRawHexString(toTest));
121126
}
@@ -168,13 +173,13 @@ public void testConvertListToArray() {
168173
@Test
169174
public void testHexStringToByteArray() {
170175
String hex = "01";
171-
assertArrayEquals("Testing simple one byte hex value", new byte[]{0x01},
176+
assertArrayEquals("Testing simple one byte hex value", new byte[] { 0x01 },
172177
ArrayConverter.hexStringToByteArray(hex));
173178
hex = "FF";
174-
assertArrayEquals("Testing one byte hex value > 0x7f", new byte[]{(byte) 0xff},
179+
assertArrayEquals("Testing one byte hex value > 0x7f", new byte[] { (byte) 0xff },
175180
ArrayConverter.hexStringToByteArray(hex));
176181
hex = "FFFFFF";
177-
assertArrayEquals("Testing one byte hex value > 0x7f", new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff},
182+
assertArrayEquals("Testing one byte hex value > 0x7f", new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff },
178183
ArrayConverter.hexStringToByteArray(hex));
179184
}
180185

@@ -184,7 +189,7 @@ public void testBigIntegerToNullPaddedByteArray() {
184189

185190
assertArrayEquals("Check zero output size", new byte[0],
186191
ArrayConverter.bigIntegerToNullPaddedByteArray(test, 0));
187-
assertArrayEquals("Check check output size smaller than input", new byte[]{(byte) 0xEC},
192+
assertArrayEquals("Check check output size smaller than input", new byte[] { (byte) 0xEC },
188193
ArrayConverter.bigIntegerToNullPaddedByteArray(test, 1));
189194
assertArrayEquals("Check output size bigger than input size",
190195
ArrayConverter.hexStringToByteArray("0000000000000000000000001D42C86F7923DFEC"),

0 commit comments

Comments
 (0)