Skip to content

Commit 8e1a4a9

Browse files
committed
Exchanged Hardcoded ranges with final constants
1 parent aba5edf commit 8e1a4a9

27 files changed

+95
-44
lines changed

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@XmlType(propOrder = { "summand", "modificationFilter", "postModification" })
1919
public class BigIntegerAddModification extends VariableModification<BigInteger> {
2020

21+
private final static int MAX_ADD_LENGTH = 8;
22+
2123
private BigInteger summand;
2224

2325
public BigIntegerAddModification() {
@@ -43,6 +45,6 @@ public void setSummand(BigInteger summand) {
4345

4446
@Override
4547
public VariableModification<BigInteger> getModifiedCopy() {
46-
return new BigIntegerAddModification(summand.add(new BigInteger(8, new Random())));
48+
return new BigIntegerAddModification(summand.add(new BigInteger(MAX_ADD_LENGTH, new Random())));
4749
}
4850
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@XmlType(propOrder = { "explicitValue", "modificationFilter", "postModification" })
1919
public class BigIntegerExplicitValueModification extends VariableModification<BigInteger> {
2020

21+
private final static int MAX_EXPLICIT_LENGTH = 8;
22+
2123
private BigInteger explicitValue;
2224

2325
public BigIntegerExplicitValueModification() {
@@ -44,9 +46,10 @@ public void setExplicitValue(BigInteger explicitValue) {
4446
public VariableModification<BigInteger> getModifiedCopy() {
4547
Random r = new Random();
4648
if (r.nextBoolean()) {
47-
return new BigIntegerExplicitValueModification(explicitValue.add(new BigInteger(8, r)));
49+
return new BigIntegerExplicitValueModification(explicitValue.add(new BigInteger(MAX_EXPLICIT_LENGTH, r)));
4850
} else {
49-
return new BigIntegerExplicitValueModification(explicitValue.subtract(new BigInteger(8, r)));
51+
return new BigIntegerExplicitValueModification(
52+
explicitValue.subtract(new BigInteger(MAX_EXPLICIT_LENGTH, r)));
5053
}
5154
}
5255
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@XmlType(propOrder = { "shift", "modificationFilter", "postModification" })
1919
public class BigIntegerShiftLeftModification extends VariableModification<BigInteger> {
2020

21+
private final static int MAX_SHIFT_LENGTH = 32;
22+
2123
private int shift;
2224

2325
public BigIntegerShiftLeftModification() {
@@ -46,6 +48,6 @@ public void setShift(int shift) {
4648

4749
@Override
4850
public VariableModification<BigInteger> getModifiedCopy() {
49-
return new BigIntegerShiftLeftModification(shift + new Random().nextInt(32));
51+
return new BigIntegerShiftLeftModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH));
5052
}
5153
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@XmlType(propOrder = { "shift", "modificationFilter", "postModification" })
1919
public class BigIntegerShiftRightModification extends VariableModification<BigInteger> {
2020

21+
private final static int MAX_SHIFT_LENGTH = 32;
22+
2123
private int shift;
2224

2325
public BigIntegerShiftRightModification() {
@@ -46,6 +48,6 @@ public void setShift(int shift) {
4648

4749
@Override
4850
public VariableModification<BigInteger> getModifiedCopy() {
49-
return new BigIntegerShiftRightModification(shift + new Random().nextInt(32));
51+
return new BigIntegerShiftRightModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH));
5052
}
5153
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@XmlType(propOrder = { "subtrahend", "modificationFilter", "postModification" })
1919
public class BigIntegerSubtractModification extends VariableModification<BigInteger> {
2020

21+
private final static int MAX_SUBTRACT_LENGTH = 8;
22+
2123
private BigInteger subtrahend;
2224

2325
public BigIntegerSubtractModification() {
@@ -46,6 +48,6 @@ public void setSubtrahend(BigInteger subtrahend) {
4648

4749
@Override
4850
public VariableModification<BigInteger> getModifiedCopy() {
49-
return new BigIntegerSubtractModification(subtrahend.add(new BigInteger(8, new Random())));
51+
return new BigIntegerSubtractModification(subtrahend.add(new BigInteger(MAX_SUBTRACT_LENGTH, new Random())));
5052
}
5153
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@XmlType(propOrder = { "xor", "modificationFilter", "postModification" })
1919
public class BigIntegerXorModification extends VariableModification<BigInteger> {
2020

21+
private final static int MAX_XOR_LENGTH = 8;
22+
2123
private BigInteger xor;
2224

2325
public BigIntegerXorModification() {
@@ -46,6 +48,6 @@ public void setXor(BigInteger xor) {
4648

4749
@Override
4850
public VariableModification<BigInteger> getModifiedCopy() {
49-
return new BigIntegerXorModification(xor.add(new BigInteger(8, new Random())));
51+
return new BigIntegerXorModification(xor.add(new BigInteger(MAX_XOR_LENGTH, new Random())));
5052
}
5153
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
@XmlType(propOrder = { "count", "startPosition", "modificationFilter", "postModification" })
2121
public class ByteArrayDeleteModification extends VariableModification<byte[]> {
2222

23+
private final static int MAX_MODIFIER_LENGTH = 32;
24+
2325
private int count;
2426

2527
private int startPosition;
@@ -83,7 +85,7 @@ public void setCount(int count) {
8385
@Override
8486
public VariableModification<byte[]> getModifiedCopy() {
8587
Random r = new Random();
86-
int modifier = r.nextInt(32);
88+
int modifier = r.nextInt(MAX_MODIFIER_LENGTH);
8789
if (r.nextBoolean()) {
8890
modifier *= -1;
8991
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
@XmlType(propOrder = { "explicitValue", "modificationFilter", "postModification" })
2222
public class ByteArrayExplicitValueModification extends VariableModification<byte[]> {
2323

24+
private final static int MAX_EXPLICIT_VALUE = 256;
25+
2426
private byte[] explicitValue;
2527

2628
public ByteArrayExplicitValueModification() {
@@ -59,7 +61,7 @@ public VariableModification<byte[]> getModifiedCopy() {
5961
}
6062
int index = r.nextInt(explicitValue.length);
6163
byte[] newValue = Arrays.copyOf(explicitValue, explicitValue.length);
62-
newValue[index] = (byte) r.nextInt(256);
64+
newValue[index] = (byte) r.nextInt(MAX_EXPLICIT_VALUE);
6365
return new ByteArrayExplicitValueModification(newValue);
6466
}
6567
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
@XmlType(propOrder = { "bytesToInsert", "startPosition", "modificationFilter", "postModification" })
2222
public class ByteArrayInsertModification extends VariableModification<byte[]> {
2323

24+
private final static int MAX_EXPLICIT_VALUE = 256;
25+
26+
private final static int MAX_INSERT_MODIFIER = 32;
27+
2428
private byte[] bytesToInsert;
2529

2630
private int startPosition;
@@ -85,11 +89,11 @@ public VariableModification<byte[]> getModifiedCopy() {
8589
if (r.nextBoolean()) {
8690
int index = r.nextInt(bytesToInsert.length);
8791
byte[] newValue = Arrays.copyOf(bytesToInsert, bytesToInsert.length);
88-
newValue[index] = (byte) r.nextInt(256);
92+
newValue[index] = (byte) r.nextInt(MAX_EXPLICIT_VALUE);
8993
return new ByteArrayInsertModification(newValue, startPosition);
9094
} else {
9195
byte[] newValue = Arrays.copyOf(bytesToInsert, bytesToInsert.length);
92-
int modifier = r.nextInt(32);
96+
int modifier = r.nextInt(MAX_INSERT_MODIFIER);
9397
if (r.nextBoolean()) {
9498
modifier *= -1;
9599
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
@XmlType(propOrder = { "shuffle", "modificationFilter", "postModification" })
2727
public class ByteArrayShuffleModification extends VariableModification<byte[]> {
2828

29+
private final static int MAX_MODIFIER_VALUE = 256;
30+
2931
private byte[] shuffle;
3032

3133
public ByteArrayShuffleModification() {
@@ -69,7 +71,7 @@ public VariableModification<byte[]> getModifiedCopy() {
6971
Random r = new Random();
7072
int index = r.nextInt(shuffle.length);
7173
byte[] newValue = Arrays.copyOf(shuffle, shuffle.length);
72-
newValue[index] = (byte) r.nextInt(256);
74+
newValue[index] = (byte) r.nextInt(MAX_MODIFIER_VALUE);
7375
return new ByteArrayShuffleModification(shuffle);
7476
}
7577
}

0 commit comments

Comments
 (0)