forked from I2P_Developers/i2p.i2p
Merge branch 'junit-deprecations' into 'master'
fix junit deprecations, issue #339 See merge request i2p-hackers/i2p.i2p!51
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package net.i2p.client.naming;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -13,7 +13,9 @@ package net.i2p.crypto.eddsa;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
@@ -27,9 +29,7 @@ import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
|
||||
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec;
|
||||
import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* @author str4d
|
||||
@@ -41,9 +41,6 @@ public class EdDSAEngineTest {
|
||||
static final byte[] TEST_MSG = "This is a secret message".getBytes(Charset.forName("UTF-8"));
|
||||
static final byte[] TEST_MSG_SIG = Utils.hexToBytes("94825896c7075c31bcb81f06dba2bdcd9dcf16e79288d4b9f87c248215c8468d475f429f3de3b4a2cf67fe17077ae19686020364d6d4fa7a0174bab4a123ba0f");
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testSign() throws Exception {
|
||||
EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
|
||||
@@ -93,9 +90,11 @@ public class EdDSAEngineTest {
|
||||
|
||||
sgr.update(TEST_MSG);
|
||||
|
||||
exception.expect(SignatureException.class);
|
||||
exception.expectMessage("signature length is wrong");
|
||||
sgr.verify(new byte[] {0});
|
||||
try {
|
||||
sgr.verify(new byte[]{0});
|
||||
} catch (SignatureException expected) {
|
||||
assertEquals("signature length is wrong", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,9 +170,12 @@ public class EdDSAEngineTest {
|
||||
|
||||
sgr.update(TEST_MSG);
|
||||
|
||||
exception.expect(SignatureException.class);
|
||||
exception.expectMessage("update() already called");
|
||||
sgr.update(TEST_MSG);
|
||||
try {
|
||||
sgr.update(TEST_MSG);
|
||||
fail("exception not thrown");
|
||||
} catch (SignatureException expected) {
|
||||
assertEquals("update() already called", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,9 +189,12 @@ public class EdDSAEngineTest {
|
||||
|
||||
sgr.update(TEST_MSG);
|
||||
|
||||
exception.expect(SignatureException.class);
|
||||
exception.expectMessage("update() already called");
|
||||
sgr.update(TEST_MSG);
|
||||
try {
|
||||
sgr.update(TEST_MSG);
|
||||
fail("exception not thrown");
|
||||
} catch (SignatureException expected) {
|
||||
assertEquals("update() already called", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,8 +16,8 @@ import org.junit.*;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author str4d
|
||||
@@ -58,7 +58,7 @@ public class UtilsTest {
|
||||
for (int i=0; i<100; i++) {
|
||||
random.nextBytes(bytes1);
|
||||
System.arraycopy(bytes1, 0, bytes2, 0, 32);
|
||||
Assert.assertThat(Utils.equal(bytes1, bytes2), IsEqual.equalTo(1));
|
||||
assertThat(Utils.equal(bytes1, bytes2), IsEqual.equalTo(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class UtilsTest {
|
||||
for (int i=0; i<32; i++) {
|
||||
System.arraycopy(bytes1, 0, bytes2, 0, 32);
|
||||
bytes2[i] = (byte)(bytes2[i] ^ 0xff);
|
||||
Assert.assertThat(Utils.equal(bytes1, bytes2), IsEqual.equalTo(0));
|
||||
assertThat(Utils.equal(bytes1, bytes2), IsEqual.equalTo(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,15 +123,15 @@ public class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void hexToBytesReturnsCorrectByteArray() {
|
||||
Assert.assertThat(Utils.hexToBytes(hex1), IsEqual.equalTo(bytes1));
|
||||
Assert.assertThat(Utils.hexToBytes(hex2), IsEqual.equalTo(bytes2));
|
||||
Assert.assertThat(Utils.hexToBytes(hex3), IsEqual.equalTo(bytes3));
|
||||
assertThat(Utils.hexToBytes(hex1), IsEqual.equalTo(bytes1));
|
||||
assertThat(Utils.hexToBytes(hex2), IsEqual.equalTo(bytes2));
|
||||
assertThat(Utils.hexToBytes(hex3), IsEqual.equalTo(bytes3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bytesToHexReturnsCorrectHexString() {
|
||||
Assert.assertThat(Utils.bytesToHex(bytes1), IsEqual.equalTo(hex1));
|
||||
Assert.assertThat(Utils.bytesToHex(bytes2), IsEqual.equalTo(hex2));
|
||||
Assert.assertThat(Utils.bytesToHex(bytes3), IsEqual.equalTo(hex3));
|
||||
assertThat(Utils.bytesToHex(bytes1), IsEqual.equalTo(hex1));
|
||||
assertThat(Utils.bytesToHex(bytes2), IsEqual.equalTo(hex2));
|
||||
assertThat(Utils.bytesToHex(bytes3), IsEqual.equalTo(hex3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ package net.i2p.crypto.eddsa.math;
|
||||
import org.hamcrest.core.*;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
@@ -37,7 +39,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final FieldElement f = getZeroFieldElement();
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(f.isNonZero(), IsEqual.equalTo(false));
|
||||
assertThat(f.isNonZero(), IsEqual.equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,7 +48,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final FieldElement f = getNonZeroFieldElement();
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(f.isNonZero(), IsEqual.equalTo(true));
|
||||
assertThat(f.isNonZero(), IsEqual.equalTo(true));
|
||||
}
|
||||
|
||||
// endregion
|
||||
@@ -67,7 +69,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final BigInteger b3 = toBigInteger(f3).mod(getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b3, IsEqual.equalTo(b1.add(b2).mod(getQ())));
|
||||
assertThat(b3, IsEqual.equalTo(b1.add(b2).mod(getQ())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +87,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final BigInteger b3 = toBigInteger(f3).mod(getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b3, IsEqual.equalTo(b1.subtract(b2).mod(getQ())));
|
||||
assertThat(b3, IsEqual.equalTo(b1.subtract(b2).mod(getQ())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +103,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final BigInteger b2 = toBigInteger(f2).mod(getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b2, IsEqual.equalTo(b1.negate().mod(getQ())));
|
||||
assertThat(b2, IsEqual.equalTo(b1.negate().mod(getQ())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +121,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final BigInteger b3 = toBigInteger(f3).mod(getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b3, IsEqual.equalTo(b1.multiply(b2).mod(getQ())));
|
||||
assertThat(b3, IsEqual.equalTo(b1.multiply(b2).mod(getQ())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +137,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final BigInteger b2 = toBigInteger(f2).mod(getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b2, IsEqual.equalTo(b1.multiply(b1).mod(getQ())));
|
||||
assertThat(b2, IsEqual.equalTo(b1.multiply(b1).mod(getQ())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +153,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final BigInteger b2 = toBigInteger(f2).mod(getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b2, IsEqual.equalTo(b1.multiply(b1).multiply(new BigInteger("2")).mod(getQ())));
|
||||
assertThat(b2, IsEqual.equalTo(b1.multiply(b1).multiply(new BigInteger("2")).mod(getQ())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +169,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final BigInteger b2 = toBigInteger(f2).mod(getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b2, IsEqual.equalTo(b1.modInverse(getQ())));
|
||||
assertThat(b2, IsEqual.equalTo(b1.modInverse(getQ())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +185,7 @@ public abstract class AbstractFieldElementTest {
|
||||
final BigInteger b2 = toBigInteger(f2).mod(getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b2, IsEqual.equalTo(b1.modPow(BigInteger.ONE.shiftLeft(252).subtract(new BigInteger("3")), getQ())));
|
||||
assertThat(b2, IsEqual.equalTo(b1.modPow(BigInteger.ONE.shiftLeft(252).subtract(new BigInteger("3")), getQ())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,11 +199,11 @@ public abstract class AbstractFieldElementTest {
|
||||
final FieldElement nz = getNonZeroFieldElement();
|
||||
final FieldElement f = getRandomFieldElement();
|
||||
|
||||
Assert.assertThat(zero.cmov(nz, 0), IsEqual.equalTo(zero));
|
||||
Assert.assertThat(zero.cmov(nz, 1), IsEqual.equalTo(nz));
|
||||
assertThat(zero.cmov(nz, 0), IsEqual.equalTo(zero));
|
||||
assertThat(zero.cmov(nz, 1), IsEqual.equalTo(nz));
|
||||
|
||||
Assert.assertThat(f.cmov(nz, 0), IsEqual.equalTo(f));
|
||||
Assert.assertThat(f.cmov(nz, 1), IsEqual.equalTo(nz));
|
||||
assertThat(f.cmov(nz, 0), IsEqual.equalTo(f));
|
||||
assertThat(f.cmov(nz, 1), IsEqual.equalTo(nz));
|
||||
}
|
||||
|
||||
// endregion
|
||||
@@ -217,10 +219,10 @@ public abstract class AbstractFieldElementTest {
|
||||
final FieldElement f4 = getRandomFieldElement();
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(f1, IsEqual.equalTo(f2));
|
||||
Assert.assertThat(f1, IsNot.not(IsEqual.equalTo(f3)));
|
||||
Assert.assertThat(f1, IsNot.not(IsEqual.equalTo(f4)));
|
||||
Assert.assertThat(f3, IsNot.not(IsEqual.equalTo(f4)));
|
||||
assertThat(f1, IsEqual.equalTo(f2));
|
||||
assertThat(f1, IsNot.not(IsEqual.equalTo(f3)));
|
||||
assertThat(f1, IsNot.not(IsEqual.equalTo(f4)));
|
||||
assertThat(f3, IsNot.not(IsEqual.equalTo(f4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,10 +234,10 @@ public abstract class AbstractFieldElementTest {
|
||||
final FieldElement f4 = getRandomFieldElement();
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(f1.hashCode(), IsEqual.equalTo(f2.hashCode()));
|
||||
Assert.assertThat(f1.hashCode(), IsNot.not(IsEqual.equalTo(f3.hashCode())));
|
||||
Assert.assertThat(f1.hashCode(), IsNot.not(IsEqual.equalTo(f4.hashCode())));
|
||||
Assert.assertThat(f3.hashCode(), IsNot.not(IsEqual.equalTo(f4.hashCode())));
|
||||
assertThat(f1.hashCode(), IsEqual.equalTo(f2.hashCode()));
|
||||
assertThat(f1.hashCode(), IsNot.not(IsEqual.equalTo(f3.hashCode())));
|
||||
assertThat(f1.hashCode(), IsNot.not(IsEqual.equalTo(f4.hashCode())));
|
||||
assertThat(f3.hashCode(), IsNot.not(IsEqual.equalTo(f4.hashCode())));
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
@@ -14,8 +14,9 @@ package net.i2p.crypto.eddsa.math;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@@ -21,7 +21,8 @@ import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* @author str4d
|
||||
@@ -50,9 +51,6 @@ public class GroupElementTest {
|
||||
};
|
||||
static final byte[] BYTES_PKR = Utils.hexToBytes("3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29");
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
/**
|
||||
* Test method for {@link GroupElement#p2(Curve, FieldElement, FieldElement, FieldElement)}.
|
||||
*/
|
||||
@@ -201,7 +199,7 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.toGroupElement(bytes);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h1, IsEqual.equalTo(h2));
|
||||
assertThat(h1, IsEqual.equalTo(h2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +245,7 @@ public class GroupElementTest {
|
||||
}
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(Arrays.equals(gBytes, bytes), IsEqual.equalTo(true));
|
||||
assertThat(Arrays.equals(gBytes, bytes), IsEqual.equalTo(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,12 +301,12 @@ public class GroupElementTest {
|
||||
final GroupElement h = g.toP2();
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h, IsEqual.equalTo(g));
|
||||
Assert.assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2));
|
||||
Assert.assertThat(h.getX(), IsEqual.equalTo(g.getX()));
|
||||
Assert.assertThat(h.getY(), IsEqual.equalTo(g.getY()));
|
||||
Assert.assertThat(h.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
Assert.assertThat(h.getT(), IsEqual.equalTo(null));
|
||||
assertThat(h, IsEqual.equalTo(g));
|
||||
assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2));
|
||||
assertThat(h.getX(), IsEqual.equalTo(g.getX()));
|
||||
assertThat(h.getY(), IsEqual.equalTo(g.getY()));
|
||||
assertThat(h.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
assertThat(h.getT(), IsEqual.equalTo(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,12 +321,12 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.P2);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h1, IsEqual.equalTo(h2));
|
||||
Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2));
|
||||
Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getX()));
|
||||
Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY()));
|
||||
Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
Assert.assertThat(h1.getT(), IsEqual.equalTo(null));
|
||||
assertThat(h1, IsEqual.equalTo(h2));
|
||||
assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2));
|
||||
assertThat(h1.getX(), IsEqual.equalTo(g.getX()));
|
||||
assertThat(h1.getY(), IsEqual.equalTo(g.getY()));
|
||||
assertThat(h1.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
assertThat(h1.getT(), IsEqual.equalTo(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,12 +341,12 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.P2);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h1, IsEqual.equalTo(h2));
|
||||
Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2));
|
||||
Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT())));
|
||||
Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ())));
|
||||
Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT())));
|
||||
Assert.assertThat(h1.getT(), IsEqual.equalTo(null));
|
||||
assertThat(h1, IsEqual.equalTo(h2));
|
||||
assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2));
|
||||
assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT())));
|
||||
assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ())));
|
||||
assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT())));
|
||||
assertThat(h1.getT(), IsEqual.equalTo(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,12 +388,12 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.P3);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h1, IsEqual.equalTo(h2));
|
||||
Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3));
|
||||
Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT())));
|
||||
Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ())));
|
||||
Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT())));
|
||||
Assert.assertThat(h1.getT(), IsEqual.equalTo(g.getX().multiply(g.getY())));
|
||||
assertThat(h1, IsEqual.equalTo(h2));
|
||||
assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3));
|
||||
assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT())));
|
||||
assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ())));
|
||||
assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT())));
|
||||
assertThat(h1.getT(), IsEqual.equalTo(g.getX().multiply(g.getY())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,13 +407,13 @@ public class GroupElementTest {
|
||||
final GroupElement h = g.toP3();
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h, IsEqual.equalTo(g));
|
||||
Assert.assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3));
|
||||
Assert.assertThat(h, IsEqual.equalTo(g));
|
||||
Assert.assertThat(h.getX(), IsEqual.equalTo(g.getX()));
|
||||
Assert.assertThat(h.getY(), IsEqual.equalTo(g.getY()));
|
||||
Assert.assertThat(h.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
Assert.assertThat(h.getT(), IsEqual.equalTo(g.getT()));
|
||||
assertThat(h, IsEqual.equalTo(g));
|
||||
assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3));
|
||||
assertThat(h, IsEqual.equalTo(g));
|
||||
assertThat(h.getX(), IsEqual.equalTo(g.getX()));
|
||||
assertThat(h.getY(), IsEqual.equalTo(g.getY()));
|
||||
assertThat(h.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
assertThat(h.getT(), IsEqual.equalTo(g.getT()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,15 +428,15 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.P3PrecomputedDouble);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h1, IsEqual.equalTo(h2));
|
||||
Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3));
|
||||
Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT())));
|
||||
Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ())));
|
||||
Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT())));
|
||||
Assert.assertThat(h1.getT(), IsEqual.equalTo(g.getX().multiply(g.getY())));
|
||||
Assert.assertThat(h1.precmp, IsNull.nullValue());
|
||||
Assert.assertThat(h1.dblPrecmp, IsNull.notNullValue());
|
||||
Assert.assertThat(h1.dblPrecmp, IsEqual.equalTo(h2.dblPrecmp));
|
||||
assertThat(h1, IsEqual.equalTo(h2));
|
||||
assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3));
|
||||
assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT())));
|
||||
assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ())));
|
||||
assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT())));
|
||||
assertThat(h1.getT(), IsEqual.equalTo(g.getX().multiply(g.getY())));
|
||||
assertThat(h1.precmp, IsNull.nullValue());
|
||||
assertThat(h1.dblPrecmp, IsNull.notNullValue());
|
||||
assertThat(h1.dblPrecmp, IsEqual.equalTo(h2.dblPrecmp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,13 +477,13 @@ public class GroupElementTest {
|
||||
final GroupElement h = g.toCached();
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h, IsEqual.equalTo(g));
|
||||
Assert.assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.CACHED));
|
||||
Assert.assertThat(h, IsEqual.equalTo(g));
|
||||
Assert.assertThat(h.getX(), IsEqual.equalTo(g.getX()));
|
||||
Assert.assertThat(h.getY(), IsEqual.equalTo(g.getY()));
|
||||
Assert.assertThat(h.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
Assert.assertThat(h.getT(), IsEqual.equalTo(g.getT()));
|
||||
assertThat(h, IsEqual.equalTo(g));
|
||||
assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.CACHED));
|
||||
assertThat(h, IsEqual.equalTo(g));
|
||||
assertThat(h.getX(), IsEqual.equalTo(g.getX()));
|
||||
assertThat(h.getY(), IsEqual.equalTo(g.getY()));
|
||||
assertThat(h.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
assertThat(h.getT(), IsEqual.equalTo(g.getT()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,13 +498,13 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.CACHED);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h1, IsEqual.equalTo(h2));
|
||||
Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.CACHED));
|
||||
Assert.assertThat(h1, IsEqual.equalTo(g));
|
||||
Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getY().add(g.getX())));
|
||||
Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY().subtract(g.getX())));
|
||||
Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
Assert.assertThat(h1.getT(), IsEqual.equalTo(g.getT().multiply(curve.get2D())));
|
||||
assertThat(h1, IsEqual.equalTo(h2));
|
||||
assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.CACHED));
|
||||
assertThat(h1, IsEqual.equalTo(g));
|
||||
assertThat(h1.getX(), IsEqual.equalTo(g.getY().add(g.getX())));
|
||||
assertThat(h1.getY(), IsEqual.equalTo(g.getY().subtract(g.getX())));
|
||||
assertThat(h1.getZ(), IsEqual.equalTo(g.getZ()));
|
||||
assertThat(h1.getT(), IsEqual.equalTo(g.getT().multiply(curve.get2D())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,7 +529,7 @@ public class GroupElementTest {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
GroupElement h = g;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
Assert.assertThat(MathUtils.toRepresentation(h, GroupElement.Representation.PRECOMP), IsEqual.equalTo(ed25519.getB().precmp[i][j]));
|
||||
assertThat(MathUtils.toRepresentation(h, GroupElement.Representation.PRECOMP), IsEqual.equalTo(ed25519.getB().precmp[i][j]));
|
||||
h = MathUtils.addGroupElements(h, g);
|
||||
}
|
||||
for (int k = 0; k < 8; k++) {
|
||||
@@ -548,7 +546,7 @@ public class GroupElementTest {
|
||||
|
||||
// Act + Assert:
|
||||
for (int i=0; i<8; i++) {
|
||||
Assert.assertThat(MathUtils.toRepresentation(g, GroupElement.Representation.PRECOMP), IsEqual.equalTo(ed25519.getB().dblPrecmp[i]));
|
||||
assertThat(MathUtils.toRepresentation(g, GroupElement.Representation.PRECOMP), IsEqual.equalTo(ed25519.getB().dblPrecmp[i]));
|
||||
g = MathUtils.addGroupElements(g, h);
|
||||
}
|
||||
}
|
||||
@@ -574,7 +572,7 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.doubleGroupElement(g);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h2, IsEqual.equalTo(h1));
|
||||
assertThat(h2, IsEqual.equalTo(h1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,8 +588,8 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = neutral.add(g.toCached());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(g, IsEqual.equalTo(h1));
|
||||
Assert.assertThat(g, IsEqual.equalTo(h2));
|
||||
assertThat(g, IsEqual.equalTo(h1));
|
||||
assertThat(g, IsEqual.equalTo(h2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,7 +605,7 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.addGroupElements(g1, g2);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h2, IsEqual.equalTo(h1));
|
||||
assertThat(h2, IsEqual.equalTo(h1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,7 +621,7 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.addGroupElements(g1, MathUtils.negateGroupElement(g2));
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h2, IsEqual.equalTo(h1));
|
||||
assertThat(h2, IsEqual.equalTo(h1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -647,13 +645,13 @@ public class GroupElementTest {
|
||||
final GroupElement g5 = MathUtils.getRandomGroupElement();
|
||||
|
||||
// Assert
|
||||
Assert.assertThat(g2, IsEqual.equalTo(g1));
|
||||
Assert.assertThat(g3, IsEqual.equalTo(g1));
|
||||
Assert.assertThat(g1, IsEqual.equalTo(g4));
|
||||
Assert.assertThat(g1, IsNot.not(IsEqual.equalTo(g5)));
|
||||
Assert.assertThat(g2, IsNot.not(IsEqual.equalTo(g5)));
|
||||
Assert.assertThat(g3, IsNot.not(IsEqual.equalTo(g5)));
|
||||
Assert.assertThat(g5, IsNot.not(IsEqual.equalTo(g4)));
|
||||
assertThat(g2, IsEqual.equalTo(g1));
|
||||
assertThat(g3, IsEqual.equalTo(g1));
|
||||
assertThat(g1, IsEqual.equalTo(g4));
|
||||
assertThat(g1, IsNot.not(IsEqual.equalTo(g5)));
|
||||
assertThat(g2, IsNot.not(IsEqual.equalTo(g5)));
|
||||
assertThat(g3, IsNot.not(IsEqual.equalTo(g5)));
|
||||
assertThat(g5, IsNot.not(IsEqual.equalTo(g4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -665,11 +663,11 @@ public class GroupElementTest {
|
||||
final GroupElement g4 = MathUtils.getRandomGroupElement();
|
||||
|
||||
// Assert
|
||||
Assert.assertThat(g2.hashCode(), IsEqual.equalTo(g1.hashCode()));
|
||||
Assert.assertThat(g3.hashCode(), IsEqual.equalTo(g1.hashCode()));
|
||||
Assert.assertThat(g1.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
|
||||
Assert.assertThat(g2.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
|
||||
Assert.assertThat(g3.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
|
||||
assertThat(g2.hashCode(), IsEqual.equalTo(g1.hashCode()));
|
||||
assertThat(g3.hashCode(), IsEqual.equalTo(g1.hashCode()));
|
||||
assertThat(g1.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
|
||||
assertThat(g2.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
|
||||
assertThat(g3.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode())));
|
||||
}
|
||||
|
||||
// endregion
|
||||
@@ -780,7 +778,7 @@ public class GroupElementTest {
|
||||
final GroupElement g = basePoint.scalarMultiply(curve.getField().ZERO.toByteArray());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(curve.getZero(GroupElement.Representation.P3), IsEqual.equalTo(g));
|
||||
assertThat(curve.getZero(GroupElement.Representation.P3), IsEqual.equalTo(g));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -792,7 +790,7 @@ public class GroupElementTest {
|
||||
final GroupElement g = basePoint.scalarMultiply(curve.getField().ONE.toByteArray());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(basePoint, IsEqual.equalTo(g));
|
||||
assertThat(basePoint, IsEqual.equalTo(g));
|
||||
}
|
||||
|
||||
// This test is slow (~6s) due to math utils using an inferior algorithm to calculate the result.
|
||||
@@ -808,7 +806,7 @@ public class GroupElementTest {
|
||||
final GroupElement h = MathUtils.scalarMultiplyGroupElement(basePoint, f);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(g, IsEqual.equalTo(h));
|
||||
assertThat(g, IsEqual.equalTo(h));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -871,7 +869,7 @@ public class GroupElementTest {
|
||||
final GroupElement h2 = MathUtils.doubleScalarMultiplyGroupElements(basePoint, f1, g, f2);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(h1, IsEqual.equalTo(h2));
|
||||
assertThat(h1, IsEqual.equalTo(h2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -903,7 +901,7 @@ public class GroupElementTest {
|
||||
final GroupElement g = MathUtils.getRandomGroupElement();
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(g.isOnCurve(), IsEqual.equalTo(true));
|
||||
assertThat(g.isOnCurve(), IsEqual.equalTo(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,7 +913,7 @@ public class GroupElementTest {
|
||||
final GroupElement h = GroupElement.p2(curve, g.getX(), g.getY(), g.getZ().multiply(curve.getField().TWO));
|
||||
|
||||
// Assert (can only fail for 5*Z^2=1):
|
||||
Assert.assertThat(h.isOnCurve(), IsEqual.equalTo(false));
|
||||
assertThat(h.isOnCurve(), IsEqual.equalTo(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.i2p.crypto.eddsa.math.ed25519.*;
|
||||
import net.i2p.crypto.eddsa.spec.*;
|
||||
import org.hamcrest.core.IsEqual;
|
||||
import org.junit.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.SecureRandom;
|
||||
@@ -451,8 +452,8 @@ public class MathUtils {
|
||||
final GroupElement h2 = addGroupElements(neutral, g);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(g, IsEqual.equalTo(h1));
|
||||
Assert.assertThat(g, IsEqual.equalTo(h2));
|
||||
assertThat(g, IsEqual.equalTo(h1));
|
||||
assertThat(g, IsEqual.equalTo(h2));
|
||||
}
|
||||
|
||||
for (int i=0; i<1000; i++) {
|
||||
@@ -460,24 +461,24 @@ public class MathUtils {
|
||||
|
||||
// P3 -> P2.
|
||||
GroupElement h = toRepresentation(g, GroupElement.Representation.P2);
|
||||
Assert.assertThat(h, IsEqual.equalTo(g));
|
||||
assertThat(h, IsEqual.equalTo(g));
|
||||
// P3 -> P1P1.
|
||||
h = toRepresentation(g, GroupElement.Representation.P1P1);
|
||||
Assert.assertThat(g, IsEqual.equalTo(h));
|
||||
assertThat(g, IsEqual.equalTo(h));
|
||||
|
||||
// P3 -> CACHED.
|
||||
h = toRepresentation(g, GroupElement.Representation.CACHED);
|
||||
Assert.assertThat(h, IsEqual.equalTo(g));
|
||||
assertThat(h, IsEqual.equalTo(g));
|
||||
|
||||
// P3 -> P2 -> P3.
|
||||
g = toRepresentation(g, GroupElement.Representation.P2);
|
||||
h = toRepresentation(g, GroupElement.Representation.P3);
|
||||
Assert.assertThat(g, IsEqual.equalTo(h));
|
||||
assertThat(g, IsEqual.equalTo(h));
|
||||
|
||||
// P3 -> P2 -> P1P1.
|
||||
g = toRepresentation(g, GroupElement.Representation.P2);
|
||||
h = toRepresentation(g, GroupElement.Representation.P1P1);
|
||||
Assert.assertThat(g, IsEqual.equalTo(h));
|
||||
assertThat(g, IsEqual.equalTo(h));
|
||||
}
|
||||
|
||||
for (int i=0; i<10; i++) {
|
||||
@@ -488,7 +489,7 @@ public class MathUtils {
|
||||
final GroupElement h = MathUtils.scalarMultiplyGroupElement(g, curve.getField().ZERO);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(curve.getZero(GroupElement.Representation.P3), IsEqual.equalTo(h));
|
||||
assertThat(curve.getZero(GroupElement.Representation.P3), IsEqual.equalTo(h));
|
||||
}
|
||||
}
|
||||
// End TODO BR: Remove when finished!
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
package net.i2p.crypto.eddsa.math.bigint;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
package net.i2p.crypto.eddsa.math.bigint;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ package net.i2p.crypto.eddsa.math.ed25519;
|
||||
import net.i2p.crypto.eddsa.math.*;
|
||||
import org.hamcrest.core.*;
|
||||
import org.junit.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
@@ -95,7 +97,7 @@ public class Ed25519FieldElementTest extends AbstractFieldElementTest {
|
||||
builder.append("]");
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(fAsString, IsEqual.equalTo(builder.toString()));
|
||||
assertThat(fAsString, IsEqual.equalTo(builder.toString()));
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
@@ -14,6 +14,8 @@ package net.i2p.crypto.eddsa.math.ed25519;
|
||||
import net.i2p.crypto.eddsa.math.*;
|
||||
import org.hamcrest.core.IsEqual;
|
||||
import org.junit.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.SecureRandom;
|
||||
@@ -39,8 +41,8 @@ public class Ed25519LittleEndianEncodingTest {
|
||||
final byte[] bytes2 = MathUtils.getField().getEncoding().encode(fieldElement2);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(bytes1, IsEqual.equalTo(MathUtils.toByteArray(BigInteger.ZERO)));
|
||||
Assert.assertThat(bytes2, IsEqual.equalTo(MathUtils.toByteArray(BigInteger.ONE)));
|
||||
assertThat(bytes1, IsEqual.equalTo(MathUtils.toByteArray(BigInteger.ZERO)));
|
||||
assertThat(bytes2, IsEqual.equalTo(MathUtils.toByteArray(BigInteger.ONE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +60,7 @@ public class Ed25519LittleEndianEncodingTest {
|
||||
final byte[] bytes = MathUtils.getField().getEncoding().encode(fieldElement1);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(bytes, IsEqual.equalTo(MathUtils.toByteArray(b.mod(MathUtils.getQ()))));
|
||||
assertThat(bytes, IsEqual.equalTo(MathUtils.toByteArray(b.mod(MathUtils.getQ()))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +78,8 @@ public class Ed25519LittleEndianEncodingTest {
|
||||
final BigInteger b2 = MathUtils.toBigInteger(f2.t);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b1, IsEqual.equalTo(BigInteger.ZERO));
|
||||
Assert.assertThat(b2, IsEqual.equalTo(BigInteger.ONE));
|
||||
assertThat(b1, IsEqual.equalTo(BigInteger.ZERO));
|
||||
assertThat(b2, IsEqual.equalTo(BigInteger.ONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +96,7 @@ public class Ed25519LittleEndianEncodingTest {
|
||||
final BigInteger b2 = MathUtils.toBigInteger(f.t).mod(MathUtils.getQ());
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(b2, IsEqual.equalTo(b1));
|
||||
assertThat(b2, IsEqual.equalTo(b1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +112,7 @@ public class Ed25519LittleEndianEncodingTest {
|
||||
final FieldElement f = new Ed25519FieldElement(MathUtils.getField(), t);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(MathUtils.getField().getEncoding().isNegative(f), IsEqual.equalTo(isNegative));
|
||||
assertThat(MathUtils.getField().getEncoding().isNegative(f), IsEqual.equalTo(isNegative));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ import java.math.BigInteger;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* @author str4d
|
||||
@@ -52,9 +53,9 @@ public class Ed25519ScalarOpsTest {
|
||||
final byte[] reduced2 = MathUtils.reduceModGroupOrder(bytes);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(MathUtils.toBigInteger(reduced1).compareTo(MathUtils.getGroupOrder()), IsEqual.equalTo(-1));
|
||||
Assert.assertThat(MathUtils.toBigInteger(reduced1).compareTo(new BigInteger("-1")), IsEqual.equalTo(1));
|
||||
Assert.assertThat(reduced1, IsEqual.equalTo(reduced2));
|
||||
assertThat(MathUtils.toBigInteger(reduced1).compareTo(MathUtils.getGroupOrder()), IsEqual.equalTo(-1));
|
||||
assertThat(MathUtils.toBigInteger(reduced1).compareTo(new BigInteger("-1")), IsEqual.equalTo(1));
|
||||
assertThat(reduced1, IsEqual.equalTo(reduced2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,9 +85,9 @@ public class Ed25519ScalarOpsTest {
|
||||
final byte[] result2 = MathUtils.multiplyAndAddModGroupOrder(bytes1, bytes2, bytes3);
|
||||
|
||||
// Assert:
|
||||
Assert.assertThat(MathUtils.toBigInteger(result1).compareTo(MathUtils.getGroupOrder()), IsEqual.equalTo(-1));
|
||||
Assert.assertThat(MathUtils.toBigInteger(result1).compareTo(new BigInteger("-1")), IsEqual.equalTo(1));
|
||||
Assert.assertThat(result1, IsEqual.equalTo(result2));
|
||||
assertThat(MathUtils.toBigInteger(result1).compareTo(MathUtils.getGroupOrder()), IsEqual.equalTo(-1));
|
||||
assertThat(MathUtils.toBigInteger(result1).compareTo(new BigInteger("-1")), IsEqual.equalTo(1));
|
||||
assertThat(result1, IsEqual.equalTo(result2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,14 @@
|
||||
package net.i2p.crypto.eddsa.spec;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import net.i2p.crypto.eddsa.Utils;
|
||||
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.junit.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* @author str4d
|
||||
@@ -31,9 +32,6 @@ public class EdDSAPrivateKeySpecTest {
|
||||
|
||||
static final EdDSANamedCurveSpec ed25519 = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
/**
|
||||
* Test method for {@link net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec#EdDSAPrivateKeySpec(byte[], net.i2p.crypto.eddsa.spec.EdDSAParameterSpec)}.
|
||||
*/
|
||||
@@ -47,9 +45,12 @@ public class EdDSAPrivateKeySpecTest {
|
||||
|
||||
@Test
|
||||
public void incorrectSeedLengthThrows() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("seed length is wrong");
|
||||
new EdDSAPrivateKeySpec(new byte[2], ed25519);
|
||||
try {
|
||||
new EdDSAPrivateKeySpec(new byte[2], ed25519);
|
||||
Assert.fail("exception not thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("seed length is wrong", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,8 +66,11 @@ public class EdDSAPrivateKeySpecTest {
|
||||
|
||||
@Test
|
||||
public void incorrectHashLengthThrows() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("hash length is wrong");
|
||||
new EdDSAPrivateKeySpec(ed25519, new byte[2]);
|
||||
try {
|
||||
new EdDSAPrivateKeySpec(ed25519, new byte[2]);
|
||||
fail("exception not thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("hash length is wrong", expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
@@ -15,9 +15,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* @author Comwiz
|
||||
@@ -25,9 +23,6 @@ import org.junit.rules.ExpectedException;
|
||||
public class DataStructureImplTest {
|
||||
DataStructure _struct;
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
_struct = new DataStructureImpl(){
|
||||
@@ -45,38 +40,47 @@ public class DataStructureImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBase64ReturnsNull() throws Exception{
|
||||
public void toBase64ReturnsNull() {
|
||||
assertNull(_struct.toBase64());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromBase64ThrowsOnNull() throws Exception{
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Null data passed in");
|
||||
_struct.fromBase64(null);
|
||||
public void fromBase64ThrowsOnNull() {
|
||||
try {
|
||||
_struct.fromBase64(null);
|
||||
fail("exception not thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Null data passed in", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateHashReturnsNull() throws Exception{
|
||||
public void calculateHashReturnsNull() {
|
||||
assertNull(_struct.calculateHash());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromByteArrayThrowsOnNull() throws Exception{
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Null data passed in");
|
||||
_struct.fromByteArray(null);
|
||||
public void fromByteArrayThrowsOnNull() {
|
||||
try {
|
||||
_struct.fromByteArray(null);
|
||||
fail("exception not thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Null data passed in", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromByteArrayThrowsOnError() throws Exception{
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Error reading the byte array");
|
||||
_struct.fromByteArray(DataHelper.getASCII("water is poison"));
|
||||
public void fromByteArrayThrowsOnError() {
|
||||
try {
|
||||
_struct.fromByteArray(DataHelper.getASCII("water is poison"));
|
||||
fail("exception not thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Error reading the byte array", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toByteArrayReturnsNullOnError() throws Exception{
|
||||
public void toByteArrayReturnsNullOnError() {
|
||||
assertNull(_struct.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by str4d in 2015 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by str4d in 2015 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import net.i2p.crypto.EncType;
|
||||
import net.i2p.crypto.SigType;
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing Lease objects
|
||||
@@ -21,9 +19,6 @@ import org.junit.rules.ExpectedException;
|
||||
*/
|
||||
public class LeaseSetTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
LeaseSet leaseSet = new LeaseSet();
|
||||
leaseSet.setDestination((Destination)(new DestinationTest()).createDataStructure());
|
||||
@@ -31,7 +26,7 @@ public class LeaseSetTest extends StructureTest {
|
||||
leaseSet.setSignature((Signature)(new SignatureTest()).createDataStructure());
|
||||
leaseSet.setSigningKey((SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure());
|
||||
//leaseSet.setVersion(42l);
|
||||
return leaseSet;
|
||||
return leaseSet;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new LeaseSet(); }
|
||||
|
||||
@@ -41,8 +36,10 @@ public class LeaseSetTest extends StructureTest {
|
||||
LeaseSet subj = new LeaseSet();
|
||||
|
||||
// should contain no leases now.
|
||||
exception.expect(IndexOutOfBoundsException.class);
|
||||
subj.getLease(0);
|
||||
try {
|
||||
subj.getLease(0);
|
||||
fail("exception not thrown");
|
||||
} catch (IndexOutOfBoundsException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,8 +48,10 @@ public class LeaseSetTest extends StructureTest {
|
||||
LeaseSet subj = new LeaseSet();
|
||||
|
||||
// this shouldn't work either
|
||||
exception.expect(IndexOutOfBoundsException.class);
|
||||
subj.getLease(-1);
|
||||
try {
|
||||
subj.getLease(-1);
|
||||
fail("exception not thrown");
|
||||
} catch (IndexOutOfBoundsException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,9 +60,12 @@ public class LeaseSetTest extends StructureTest {
|
||||
LeaseSet subj = new LeaseSet();
|
||||
|
||||
// now add an null lease
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("erm, null lease");
|
||||
subj.addLease(null);
|
||||
try {
|
||||
subj.addLease(null);
|
||||
fail("exception not thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("erm, null lease", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,8 +74,11 @@ public class LeaseSetTest extends StructureTest {
|
||||
LeaseSet subj = new LeaseSet();
|
||||
|
||||
// try to add completely invalid lease(ie. no data)
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("erm, lease has no gateway");
|
||||
subj.addLease(new Lease());
|
||||
try {
|
||||
subj.addLease(new Lease());
|
||||
fail("exception not thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("erm, lease has no gateway", expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
@@ -13,9 +13,7 @@ import static org.junit.Assert.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing Lease objects
|
||||
@@ -24,9 +22,6 @@ import org.junit.rules.ExpectedException;
|
||||
*/
|
||||
public class LeaseTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
Lease lease = new Lease();
|
||||
lease.setEndDate(new Date(1000*60*2));
|
||||
@@ -35,7 +30,7 @@ public class LeaseTest extends StructureTest {
|
||||
StructureTest tst = new TunnelIdTest();
|
||||
lease.setTunnelId((TunnelId)tst.createDataStructure());
|
||||
|
||||
return lease;
|
||||
return lease;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new Lease(); }
|
||||
|
||||
@@ -75,9 +70,12 @@ public class LeaseTest extends StructureTest {
|
||||
lease.setGateway(new Hash(h));
|
||||
lease.setTunnelId(null);
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Not enough data to write out a Lease");
|
||||
lease.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
lease.writeBytes(new ByteArrayOutputStream());
|
||||
fail("exception not thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Not enough data to write out a Lease", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,9 +87,12 @@ public class LeaseTest extends StructureTest {
|
||||
StructureTest tst = new TunnelIdTest();
|
||||
lease.setTunnelId((TunnelId)tst.createDataStructure());
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Not enough data to write out a Lease");
|
||||
lease.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
lease.writeBytes(new ByteArrayOutputStream());
|
||||
fail("exception not thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Not enough data to write out a Lease", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the Private domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the Private domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.EOFException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing PrivateKey objects
|
||||
@@ -25,16 +23,13 @@ import org.junit.rules.ExpectedException;
|
||||
*/
|
||||
public class PrivateKeyTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
PrivateKey privateKey = new PrivateKey();
|
||||
byte data[] = new byte[PrivateKey.KEYSIZE_BYTES];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = (byte)(i%16);
|
||||
privateKey.setData(data);
|
||||
return privateKey;
|
||||
return privateKey;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new PrivateKey(); }
|
||||
|
||||
@@ -66,9 +61,12 @@ public class PrivateKeyTest extends StructureTest {
|
||||
PrivateKey privateKey = new PrivateKey();
|
||||
privateKey.toString();
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("No data to write out");
|
||||
privateKey.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
privateKey.writeBytes(new ByteArrayOutputStream());
|
||||
fail("exception not thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("No data to write out", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,9 +76,12 @@ public class PrivateKeyTest extends StructureTest {
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = (byte)(i);
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("Bad data length: 56; required: " + PrivateKey.KEYSIZE_BYTES);
|
||||
privateKey.setData(data);
|
||||
try {
|
||||
privateKey.setData(data);
|
||||
fail("exception not thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("Bad data length: 56; required: " + PrivateKey.KEYSIZE_BYTES, expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,8 +89,11 @@ public class PrivateKeyTest extends StructureTest {
|
||||
PrivateKey privateKey = new PrivateKey();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two"));
|
||||
|
||||
exception.expect(EOFException.class);
|
||||
exception.expectMessage("EOF after reading 31 bytes of " + PrivateKey.KEYSIZE_BYTES + " byte value");
|
||||
privateKey.readBytes(in);
|
||||
try {
|
||||
privateKey.readBytes(in);
|
||||
fail("exception not thrown");
|
||||
} catch (EOFException expected) {
|
||||
assertEquals("EOF after reading 31 bytes of " + PrivateKey.KEYSIZE_BYTES + " byte value", expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
@@ -14,9 +14,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.EOFException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing PublicKey objects
|
||||
@@ -25,16 +23,13 @@ import org.junit.rules.ExpectedException;
|
||||
*/
|
||||
public class PublicKeyTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
PublicKey publicKey = new PublicKey();
|
||||
byte data[] = new byte[PublicKey.KEYSIZE_BYTES];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = (byte)(i%16);
|
||||
publicKey.setData(data);
|
||||
return publicKey;
|
||||
return publicKey;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new PublicKey(); }
|
||||
|
||||
@@ -66,9 +61,12 @@ public class PublicKeyTest extends StructureTest {
|
||||
PublicKey publicKey = new PublicKey();
|
||||
publicKey.toString();
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("No data to write out");
|
||||
publicKey.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
publicKey.writeBytes(new ByteArrayOutputStream());
|
||||
fail("exception not thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("No data to write out", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,10 +76,13 @@ public class PublicKeyTest extends StructureTest {
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = (byte)(i);
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("Bad data length: 56; required: " + PublicKey.KEYSIZE_BYTES);
|
||||
publicKey.setData(data);
|
||||
publicKey.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
publicKey.setData(data);
|
||||
publicKey.writeBytes(new ByteArrayOutputStream());
|
||||
fail("exception not thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("Bad data length: 56; required: " + PublicKey.KEYSIZE_BYTES, expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,8 +90,11 @@ public class PublicKeyTest extends StructureTest {
|
||||
PublicKey publicKey = new PublicKey();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two"));
|
||||
|
||||
exception.expect(EOFException.class);
|
||||
exception.expectMessage("EOF after reading 31 bytes of " + PublicKey.KEYSIZE_BYTES + " byte value");
|
||||
publicKey.readBytes(in);
|
||||
try {
|
||||
publicKey.readBytes(in);
|
||||
fail("exception not thrown");
|
||||
} catch (EOFException expected) {
|
||||
assertEquals("EOF after reading 31 bytes of " + PublicKey.KEYSIZE_BYTES + " byte value", expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.EOFException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing SigningPrivateKey objects
|
||||
@@ -25,16 +23,13 @@ import org.junit.rules.ExpectedException;
|
||||
*/
|
||||
public class SigningPrivateKeyTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
|
||||
byte data[] = new byte[SigningPrivateKey.KEYSIZE_BYTES];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = (byte)(i%16);
|
||||
signingPrivateKey.setData(data);
|
||||
return signingPrivateKey;
|
||||
return signingPrivateKey;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new SigningPrivateKey(); }
|
||||
|
||||
@@ -66,9 +61,12 @@ public class SigningPrivateKeyTest extends StructureTest {
|
||||
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
|
||||
signingPrivateKey.toString();
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("No data to write out");
|
||||
signingPrivateKey.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
signingPrivateKey.writeBytes(new ByteArrayOutputStream());
|
||||
fail("exception not thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("No data to write out", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,10 +76,13 @@ public class SigningPrivateKeyTest extends StructureTest {
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = (byte)(i);
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("Bad data length: 56; required: " + SigningPrivateKey.KEYSIZE_BYTES);
|
||||
signingPrivateKey.setData(data);
|
||||
signingPrivateKey.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
signingPrivateKey.setData(data);
|
||||
signingPrivateKey.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("Bad data length: 56; required: " + SigningPrivateKey.KEYSIZE_BYTES, expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,8 +90,11 @@ public class SigningPrivateKeyTest extends StructureTest {
|
||||
SigningPrivateKey signingPrivateKey = new SigningPrivateKey();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("short"));
|
||||
|
||||
exception.expect(EOFException.class);
|
||||
exception.expectMessage("EOF after reading 5 bytes of " + SigningPrivateKey.KEYSIZE_BYTES + " byte value");
|
||||
signingPrivateKey.readBytes(in);
|
||||
try {
|
||||
signingPrivateKey.readBytes(in);
|
||||
fail("no exception thrown");
|
||||
} catch (EOFException expected) {
|
||||
assertEquals("EOF after reading 5 bytes of " + SigningPrivateKey.KEYSIZE_BYTES + " byte value", expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
@@ -14,9 +14,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.EOFException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing PublicKey objects
|
||||
@@ -25,16 +23,13 @@ import org.junit.rules.ExpectedException;
|
||||
*/
|
||||
public class SigningPublicKeyTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
SigningPublicKey publicKey = new SigningPublicKey();
|
||||
byte data[] = new byte[SigningPublicKey.KEYSIZE_BYTES];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = (byte)(i%16);
|
||||
publicKey.setData(data);
|
||||
return publicKey;
|
||||
return publicKey;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new SigningPublicKey(); }
|
||||
|
||||
@@ -66,9 +61,13 @@ public class SigningPublicKeyTest extends StructureTest {
|
||||
SigningPublicKey publicKey = new SigningPublicKey();
|
||||
publicKey.toString();
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("No data to write out");
|
||||
publicKey.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
publicKey.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("No data to write out", expected.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,10 +77,13 @@ public class SigningPublicKeyTest extends StructureTest {
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = (byte)(i);
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("Bad data length: 56; required: " + SigningPublicKey.KEYSIZE_BYTES);
|
||||
publicKey.setData(data);
|
||||
publicKey.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
publicKey.setData(data);
|
||||
publicKey.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("Bad data length: 56; required: " + SigningPublicKey.KEYSIZE_BYTES, expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,8 +91,11 @@ public class SigningPublicKeyTest extends StructureTest {
|
||||
SigningPublicKey publicKey = new SigningPublicKey();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two"));
|
||||
|
||||
exception.expect(EOFException.class);
|
||||
exception.expectMessage("EOF after reading 31 bytes of " + SigningPublicKey.KEYSIZE_BYTES + " byte value");
|
||||
publicKey.readBytes(in);
|
||||
try {
|
||||
publicKey.readBytes(in);
|
||||
fail("exception not thrown");
|
||||
} catch (EOFException expected) {
|
||||
assertEquals("EOF after reading 31 bytes of " + SigningPublicKey.KEYSIZE_BYTES + " byte value", expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Test harness for the simple data structure
|
||||
@@ -21,9 +19,6 @@ import org.junit.rules.ExpectedException;
|
||||
*/
|
||||
public class SimpleDataStructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void setDataThrowsOnNullAfterDataSet() throws Exception {
|
||||
// create new test subject
|
||||
@@ -36,9 +31,12 @@ public class SimpleDataStructureTest {
|
||||
struct.setData(new byte[3]);
|
||||
|
||||
// now setting it to null should fail
|
||||
exception.expect(RuntimeException.class);
|
||||
exception.expectMessage("Data already set");
|
||||
struct.setData(null);
|
||||
try {
|
||||
struct.setData(null);
|
||||
fail("exception not thrown");
|
||||
} catch (RuntimeException expected) {
|
||||
assertEquals("Data already set", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,9 +51,12 @@ public class SimpleDataStructureTest {
|
||||
struct.setData(new byte[3]);
|
||||
|
||||
// setting it to something non-null should fail.
|
||||
exception.expect(RuntimeException.class);
|
||||
exception.expectMessage("Data already set");
|
||||
struct.setData(new byte[3]);
|
||||
try {
|
||||
struct.setData(new byte[3]);
|
||||
fail("exception not thrown");
|
||||
} catch (RuntimeException expected) {
|
||||
assertEquals("Data already set", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,9 +10,7 @@ package net.i2p.data.i2np;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataFormatException;
|
||||
@@ -30,9 +28,6 @@ import net.i2p.util.Clock;
|
||||
*/
|
||||
public class DatabaseStoreMessageTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
DSMStructure msg = new DSMStructure(I2PAppContext.getGlobalContext());
|
||||
RouterInfo info = (RouterInfo)new RouterInfoTest().createDataStructure();
|
||||
@@ -41,16 +36,18 @@ public class DatabaseStoreMessageTest extends StructureTest {
|
||||
msg.setEntry(info);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public DataStructure createStructureToRead() {
|
||||
return new DSMStructure(I2PAppContext.getGlobalContext());
|
||||
|
||||
public DataStructure createStructureToRead() {
|
||||
return new DSMStructure(I2PAppContext.getGlobalContext());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testStructure() throws Exception {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
super.testStructure();
|
||||
try {
|
||||
super.testStructure();
|
||||
fail("no exception thrown");
|
||||
} catch (UnsupportedOperationException expected) {}
|
||||
}
|
||||
|
||||
private static class DSMStructure extends DatabaseStoreMessage implements DataStructure {
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
package net.i2p.data.router;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataStructure;
|
||||
@@ -29,16 +27,13 @@ import net.i2p.util.OrderedProperties;
|
||||
*/
|
||||
public class RouterAddressTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
|
||||
OrderedProperties options = new OrderedProperties();
|
||||
options.setProperty("hostname", "localhost");
|
||||
options.setProperty("portnum", "1234");
|
||||
RouterAddress addr = new RouterAddress("Blah", options, 42);
|
||||
return addr;
|
||||
return addr;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new RouterAddress(); }
|
||||
|
||||
@@ -47,8 +42,10 @@ public class RouterAddressTest extends StructureTest {
|
||||
public void testSetNullOptions(){
|
||||
RouterAddress addr = new RouterAddress();
|
||||
|
||||
exception.expect(NullPointerException.class);
|
||||
addr.setOptions(null);
|
||||
try {
|
||||
addr.setOptions(null);
|
||||
fail("no exception thrown");
|
||||
} catch (NullPointerException expected) {}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -60,17 +57,22 @@ public class RouterAddressTest extends StructureTest {
|
||||
RouterAddress addr = new RouterAddress("Blah", options, 42);
|
||||
options.setProperty("portnum", "2345");
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
addr.setOptions(options);
|
||||
try {
|
||||
addr.setOptions(options);
|
||||
fail("no exception thrown");
|
||||
} catch (IllegalStateException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadWrite() throws Exception{
|
||||
RouterAddress addr = new RouterAddress();
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("uninitialized");
|
||||
addr.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
addr.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("uninitialized", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.i2p.data.router;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
@@ -12,9 +12,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import net.i2p.data.Certificate;
|
||||
import net.i2p.data.CertificateTest;
|
||||
@@ -33,9 +31,6 @@ import net.i2p.data.StructureTest;
|
||||
*/
|
||||
public class RouterIdentityTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
RouterIdentity ident = new RouterIdentity();
|
||||
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
|
||||
@@ -57,9 +52,12 @@ public class RouterIdentityTest extends StructureTest {
|
||||
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
|
||||
ident.setSigningPublicKey(k);
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Not enough data to format the router identity");
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Not enough data to format the router identity", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,9 +69,12 @@ public class RouterIdentityTest extends StructureTest {
|
||||
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
|
||||
ident.setSigningPublicKey(k);
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Not enough data to format the router identity");
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Not enough data to format the router identity", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,9 +86,12 @@ public class RouterIdentityTest extends StructureTest {
|
||||
ident.setPublicKey(pk);
|
||||
ident.setSigningPublicKey(null);
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Not enough data to format the router identity");
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Not enough data to format the router identity", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,8 +121,11 @@ public class RouterIdentityTest extends StructureTest {
|
||||
public void testBadHash() throws Exception {
|
||||
RouterIdentity ident = new RouterIdentity();
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectMessage("KAC hash error");
|
||||
ident.getHash();
|
||||
try {
|
||||
ident.getHash();
|
||||
fail("no exception thrown");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertEquals("KAC hash error", expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user