Skip to content

Commit bca9930

Browse files
committed
Revert "Implemented a toString method for ModifiableByteArray and made a new hexToString method which handles ModifiableByteArray"
Netbeans pushed my branch directly to the master o.O This reverts commit d5c65ec.
1 parent d5c65ec commit bca9930

File tree

4 files changed

+11
-89
lines changed

4 files changed

+11
-89
lines changed

src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import de.rub.nds.modifiablevariable.ModifiableVariable;
1212
import de.rub.nds.modifiablevariable.VariableModification;
13-
import de.rub.nds.modifiablevariable.util.ArrayConverter;
1413
import de.rub.nds.modifiablevariable.util.ByteArrayAdapter;
1514
import java.io.Serializable;
1615
import java.util.Arrays;
@@ -72,11 +71,4 @@ public boolean validateAssertions() {
7271
}
7372
return valid;
7473
}
75-
76-
@Override
77-
public String toString() {
78-
return ArrayConverter.bytesToHexString(this);
79-
}
80-
81-
8274
}

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
*/
99
package de.rub.nds.modifiablevariable.util;
1010

11-
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
1211
import java.lang.reflect.Array;
1312
import java.math.BigInteger;
1413
import java.util.List;
1514

1615
/**
1716
* @author Juraj Somorovsky <juraj.somorovsky@rub.de>
18-
* @author Matthias Terlinde <matthias.terlinde@rub.de>
1917
*/
2018
public class ArrayConverter {
2119

@@ -58,7 +56,7 @@ public static byte[] longToUint32Bytes(long l) {
5856
* Takes an integer value and stores its last bytes into a byte array
5957
*
6058
* @param value integer value
61-
* @param size byte size of the new integer byte array
59+
* @param size byte size of the new integer byte array
6260
* @return
6361
*/
6462
public static byte[] intToBytes(int value, int size) {
@@ -79,7 +77,7 @@ public static byte[] intToBytes(int value, int size) {
7977
* Takes a long value and stores its last bytes into a byte array
8078
*
8179
* @param value long value
82-
* @param size byte size of the new integer byte array
80+
* @param size byte size of the new integer byte array
8381
* @return
8482
*/
8583
public static byte[] longToBytes(long value, int size) {
@@ -165,19 +163,6 @@ public static String bytesToHexString(byte[] array, boolean usePrettyPrinting, b
165163
return result.toString();
166164
}
167165

168-
public static String bytesToHexString(ModifiableByteArray array) {
169-
return bytesToHexString(array.getValue());
170-
}
171-
172-
public static String bytesToHexString(ModifiableByteArray array, boolean usePrettyPrinting) {
173-
174-
return bytesToHexString(array.getValue(), usePrettyPrinting, true);
175-
}
176-
177-
public static String bytesToHexString(ModifiableByteArray array, boolean usePrettyPrinting, boolean initialNewLine) {
178-
return bytesToHexString(array.getValue(), usePrettyPrinting, initialNewLine);
179-
}
180-
181166
@SafeVarargs
182167
public static <T> T[] concatenate(final T[]... arrays) {
183168
if (arrays == null || arrays.length == 0) {

src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
*/
99
package de.rub.nds.modifiablevariable.bytearray;
1010

11-
import de.rub.nds.modifiablevariable.ModifiableVariableFactory;
11+
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
12+
import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory;
1213
import de.rub.nds.modifiablevariable.VariableModification;
1314
import de.rub.nds.modifiablevariable.util.ArrayConverter;
1415
import org.apache.logging.log4j.LogManager;
1516
import org.apache.logging.log4j.Logger;
1617
import static org.junit.Assert.assertArrayEquals;
17-
import static org.junit.Assert.assertEquals;
1818
import static org.junit.Assert.assertFalse;
1919
import static org.junit.Assert.assertNotNull;
2020
import static org.junit.Assert.assertTrue;
@@ -430,27 +430,4 @@ public void testShuffle() {
430430
result = new byte[] { 6, 0, 3, 2, 5, 4, 1 };
431431
assertArrayEquals(result, start.getValue());
432432
}
433-
434-
@Test
435-
public void toStringTest() {
436-
ModifiableByteArray toTest = new ModifiableByteArray();
437-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x11, 0x22, 0x33, 0x44});
438-
assertEquals("00 11 22 33 44", toTest.toString());
439-
440-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08});
441-
assertEquals("00 01 02 03 04 05 06 07 08", toTest.toString());
442-
443-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10});
444-
assertEquals("00 01 02 03 04 05 06 07 08 09 10", toTest.toString());
445-
446-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
447-
0x07,});
448-
assertEquals("\n00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07", toTest.toString());
449-
450-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
451-
0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,});
452-
assertEquals(
453-
"\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",
454-
toTest.toString());
455-
}
456433
}

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

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
* http://www.apache.org/licenses/LICENSE-2.0
88
*/
99
package de.rub.nds.modifiablevariable.util;
10-
11-
import de.rub.nds.modifiablevariable.ModifiableVariableFactory;
12-
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
1310
import java.math.BigInteger;
1411
import static org.junit.Assert.assertArrayEquals;
1512
import static org.junit.Assert.assertEquals;
@@ -61,13 +58,13 @@ public void testBytesToInt() {
6158
*/
6259
@Test
6360
public void testBytesToLong() {
64-
/**
65-
* TODO get the casting correct. long result = 571714867398058L; byte[]
66-
* toParse = {0x02, 0x07, (byte) 0xf8, (byte) 0xbd, (byte) 0x95, (byte)
67-
* 0x85, (byte) 0xaa}; byte[] test = ArrayConverter.longToBytes(result,
68-
* 7); int a = 0; //assertEquals(result,
69-
* ArrayConverter.bytesToLong(toParse));
70-
*/
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+
*/
7168

7269
}
7370

@@ -189,33 +186,4 @@ public void testLongToUint48Bytes() {
189186

190187
assertArrayEquals("Assert correct output", expectedResult, ArrayConverter.longToUint48Bytes(testValue));
191188
}
192-
193-
/**
194-
* Test of bytesToHexString method, of class ArrayConverter. Differences in
195-
* the overloaded methods should be visible in the other tests since the
196-
* methods just pass the .getValue().
197-
*/
198-
@Test
199-
public void testBytesToHexString_ModifiableByteArray() {
200-
ModifiableByteArray toTest = new ModifiableByteArray();
201-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x11, 0x22, 0x33, 0x44});
202-
assertEquals("00 11 22 33 44", ArrayConverter.bytesToHexString(toTest));
203-
204-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08});
205-
assertEquals("00 01 02 03 04 05 06 07 08", ArrayConverter.bytesToHexString(toTest));
206-
207-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10});
208-
assertEquals("00 01 02 03 04 05 06 07 08 09 10", ArrayConverter.bytesToHexString(toTest));
209-
210-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
211-
0x07,});
212-
assertEquals("\n00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07", ArrayConverter.bytesToHexString(toTest));
213-
214-
toTest = ModifiableVariableFactory.safelySetValue(toTest, new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
215-
0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,});
216-
assertEquals(
217-
"\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",
218-
ArrayConverter.bytesToHexString(toTest));
219-
}
220-
221189
}

0 commit comments

Comments
 (0)