Skip to content

Commit 9ae0b47

Browse files
committed
Added getModifiedCopy function and updated version number to 2.3
1 parent f80a129 commit 9ae0b47

33 files changed

+334
-18
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>de.rub.nds</groupId>
55
<artifactId>ModifiableVariable</artifactId>
6-
<version>2.2</version>
6+
<version>2.3</version>
77
<packaging>jar</packaging>
88

99
<name>ModifiableVariable</name>

src/main/java/de/rub/nds/modifiablevariable/VariableModification.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public E modify(E input) {
106106
}
107107

108108
protected abstract E modifyImplementationHook(E input);
109+
110+
protected abstract VariableModification<E> getModifiedCopy();
109111

110112
/**
111113
* Debugging modified variables. Getting stack trace can be time consuming,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Random;
1314
import javax.xml.bind.annotation.XmlRootElement;
1415
import javax.xml.bind.annotation.XmlType;
1516

1617
@XmlRootElement
17-
@XmlType(propOrder = { "summand", "modificationFilter", "postModification" })
18+
@XmlType(propOrder = {"summand", "modificationFilter", "postModification"})
1819
public class BigIntegerAddModification extends VariableModification<BigInteger> {
1920

2021
private BigInteger summand;
@@ -39,4 +40,9 @@ public BigInteger getSummand() {
3940
public void setSummand(BigInteger summand) {
4041
this.summand = summand;
4142
}
43+
44+
@Override
45+
protected VariableModification<BigInteger> getModifiedCopy() {
46+
return new BigIntegerAddModification(summand.add(new BigInteger(8, new Random())));
47+
}
4248
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Random;
1314
import javax.xml.bind.annotation.XmlRootElement;
1415
import javax.xml.bind.annotation.XmlType;
1516

1617
@XmlRootElement
17-
@XmlType(propOrder = { "explicitValue", "modificationFilter", "postModification" })
18+
@XmlType(propOrder = {"explicitValue", "modificationFilter", "postModification"})
1819
public class BigIntegerExplicitValueModification extends VariableModification<BigInteger> {
1920

2021
private BigInteger explicitValue;
@@ -38,4 +39,14 @@ public BigInteger getExplicitValue() {
3839
public void setExplicitValue(BigInteger explicitValue) {
3940
this.explicitValue = explicitValue;
4041
}
41-
}
42+
43+
@Override
44+
protected VariableModification<BigInteger> getModifiedCopy() {
45+
Random r = new Random();
46+
if (r.nextBoolean()) {
47+
return new BigIntegerExplicitValueModification(explicitValue.add(new BigInteger(8, r)));
48+
} else {
49+
return new BigIntegerExplicitValueModification(explicitValue.subtract(new BigInteger(8, r)));
50+
}
51+
}
52+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@ public interface InteractiveBigIntegerModification {
3636

3737
BigInteger modify(BigInteger oldVal);
3838
}
39+
40+
@Override
41+
protected VariableModification<BigInteger> getModifiedCopy() {
42+
throw new UnsupportedOperationException("This method is not supported for interactive Modifactions");
43+
}
44+
45+
3946
}

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

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

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Random;
1314
import javax.xml.bind.annotation.XmlRootElement;
1415
import javax.xml.bind.annotation.XmlType;
1516

@@ -42,4 +43,9 @@ public int getShift() {
4243
public void setShift(int shift) {
4344
this.shift = shift;
4445
}
46+
47+
@Override
48+
protected VariableModification<BigInteger> getModifiedCopy() {
49+
return new BigIntegerShiftLeftModification(shift + new Random().nextInt(32));
50+
}
4551
}

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

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

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Random;
1314
import javax.xml.bind.annotation.XmlRootElement;
1415
import javax.xml.bind.annotation.XmlType;
1516

@@ -42,4 +43,9 @@ public int getShift() {
4243
public void setShift(int shift) {
4344
this.shift = shift;
4445
}
46+
47+
@Override
48+
protected VariableModification<BigInteger> getModifiedCopy() {
49+
return new BigIntegerShiftRightModification(shift + new Random().nextInt(32));
50+
}
4551
}

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

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

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Random;
1314
import javax.xml.bind.annotation.XmlRootElement;
1415
import javax.xml.bind.annotation.XmlType;
1516

@@ -42,4 +43,9 @@ public BigInteger getSubtrahend() {
4243
public void setSubtrahend(BigInteger subtrahend) {
4344
this.subtrahend = subtrahend;
4445
}
46+
47+
@Override
48+
protected VariableModification<BigInteger> getModifiedCopy() {
49+
return new BigIntegerSubtractModification(subtrahend.add(new BigInteger(8, new Random())));
50+
}
4551
}

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

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

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Random;
1314
import javax.xml.bind.annotation.XmlRootElement;
1415
import javax.xml.bind.annotation.XmlType;
1516

@@ -42,4 +43,9 @@ public BigInteger getXor() {
4243
public void setXor(BigInteger xor) {
4344
this.xor = xor;
4445
}
46+
47+
@Override
48+
protected VariableModification<BigInteger> getModifiedCopy() {
49+
return new BigIntegerXorModification(xor.add(new BigInteger(8, new Random())));
50+
}
4551
}

src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ public boolean isExplicitValue() {
3737
public void setExplicitValue(boolean explicitValue) {
3838
this.explicitValue = explicitValue;
3939
}
40+
41+
@Override
42+
protected VariableModification<Boolean> getModifiedCopy() {
43+
return new BooleanExplicitValueModification(!explicitValue);
44+
}
4045
}

0 commit comments

Comments
 (0)