Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions common/src/test/java/org/conscrypt/EdDsaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -29,6 +30,7 @@

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -328,7 +330,8 @@ public void serializePrivateKey_isEqualToTestVector() throws Exception {

String classNameHex = TestUtils.encodeHex(
privateKey.getClass().getName().getBytes(StandardCharsets.UTF_8));
String expectedHexEncoding = "aced000573720024" + classNameHex
String expectedHexEncoding = "aced0005737200"
+ Integer.toHexString(privateKey.getClass().getName().length()) + classNameHex
+ "d479f95a133abadc" // serialVersionUID
+ "0200015b000f"
+ "707269766174654b65794279746573" // hex("privateKeyBytes")
Expand Down Expand Up @@ -357,7 +360,8 @@ public void serializePublicKey_isEqualToTestVector() throws Exception {

String classNameHex = TestUtils.encodeHex(
publicKey.getClass().getName().getBytes(StandardCharsets.UTF_8));
String expectedHexEncoding = "aced000573720023" + classNameHex
String expectedHexEncoding = "aced0005737200"
+ Integer.toHexString(publicKey.getClass().getName().length()) + classNameHex
+ "064c7113d078e42d" // serialVersionUID
+ "0200015b000e"
+ "7075626c69634b65794279746573" // hex("publicKeyBytes")
Expand Down Expand Up @@ -386,7 +390,12 @@ public void deserializeInvalidPrivateKey_fails() throws Exception {
new ByteArrayInputStream(TestUtils.decodeHex(invalidPrivateKeySerialized));
ObjectInputStream ois = new ObjectInputStream(bais);

assertThrows(IllegalArgumentException.class, () -> ois.readObject());
try {
ois.readObject();
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException | EOFException e) {
// Expected
}
}

@Test
Expand All @@ -408,6 +417,11 @@ public void deserializeInvalidPublicKey_fails() throws Exception {
new ByteArrayInputStream(TestUtils.decodeHex(invalidPublicKeySerialized));
ObjectInputStream ois = new ObjectInputStream(bais);

assertThrows(IllegalArgumentException.class, () -> ois.readObject());
try {
ois.readObject();
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException | EOFException e) {
// Expected
}
}
}
23 changes: 20 additions & 3 deletions common/src/test/java/org/conscrypt/MlDsaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -27,6 +28,7 @@

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -451,7 +453,12 @@ public void deserializePrivateKeyWithWrongSuffix_fails() throws Exception {
new ByteArrayInputStream(TestUtils.decodeHex(invalidPrivateKey));
ObjectInputStream ois = new ObjectInputStream(bais);

assertThrows(IllegalArgumentException.class, () -> ois.readObject());
try {
ois.readObject();
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException | EOFException e) {
// Expected
}
}

@Test
Expand Down Expand Up @@ -479,7 +486,12 @@ public void deserializePrivateKeyWithWrongSize_fails() throws Exception {
new ByteArrayInputStream(TestUtils.decodeHex(invalidPrivateKey));
ObjectInputStream ois = new ObjectInputStream(bais);

assertThrows(IllegalArgumentException.class, () -> ois.readObject());
try {
ois.readObject();
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException | EOFException e) {
// Expected
}
}

@Test
Expand All @@ -504,6 +516,11 @@ public void deserializeInvalidPublicKey_fails() throws Exception {
ByteArrayInputStream bais = new ByteArrayInputStream(TestUtils.decodeHex(hexPublicKey));
ObjectInputStream ois = new ObjectInputStream(bais);

assertThrows(IllegalArgumentException.class, () -> ois.readObject());
try {
ois.readObject();
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException | EOFException e) {
// Expected
}
}
}
Loading