mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-07-14 16:04:41 +00:00
Version bump scodec and specs2
Also fix assorted casting errors and improve test case readability
This commit is contained in:
parent
372a88bb6e
commit
50fb65ac57
6 changed files with 38 additions and 39 deletions
|
|
@ -5,11 +5,11 @@ lazy val commonSettings = Seq(
|
||||||
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"),
|
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"),
|
||||||
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
|
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
|
||||||
libraryDependencies := Seq(
|
libraryDependencies := Seq(
|
||||||
"com.typesafe.akka" %% "akka-actor" % "2.3.11",
|
"com.typesafe.akka" %% "akka-actor" % "2.4.4",
|
||||||
"com.typesafe.scala-logging" %% "scala-logging" % "3.1.0",
|
"com.typesafe.scala-logging" %% "scala-logging" % "3.1.0",
|
||||||
"org.specs2" %% "specs2-core" % "2.3.11" % "test",
|
"org.specs2" %% "specs2-core" % "3.8.3" % "test",
|
||||||
"org.scodec" %% "scodec-core" % "1.8.3",
|
"org.scodec" %% "scodec-core" % "1.9.0",
|
||||||
"org.scodec" %% "scodec-akka" % "0.1.0-SNAPSHOT",
|
"org.scodec" %% "scodec-akka" % "0.1.0",
|
||||||
"net.java.dev.jna" % "jna" % "4.2.1",
|
"net.java.dev.jna" % "jna" % "4.2.1",
|
||||||
"com.typesafe.akka" %% "akka-slf4j" % "2.4.4",
|
"com.typesafe.akka" %% "akka-slf4j" % "2.4.4",
|
||||||
"ch.qos.logback" % "logback-classic" % "1.1.7",
|
"ch.qos.logback" % "logback-classic" % "1.1.7",
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ object CryptoInterface {
|
||||||
if(mac1.length != mac2.length)
|
if(mac1.length != mac2.length)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
for(i <- 0 until mac1.length) {
|
for(i <- 0 until mac1.length.toInt) {
|
||||||
okay = okay && mac1{i} == mac2{i}
|
okay = okay && mac1{i} == mac2{i}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,7 +182,7 @@ object CryptoInterface {
|
||||||
if(plaintext.length % RC5_BLOCK_SIZE != 0)
|
if(plaintext.length % RC5_BLOCK_SIZE != 0)
|
||||||
throw new IllegalArgumentException(s"input must be padded to the nearest $RC5_BLOCK_SIZE byte boundary")
|
throw new IllegalArgumentException(s"input must be padded to the nearest $RC5_BLOCK_SIZE byte boundary")
|
||||||
|
|
||||||
val ciphertext = Array.ofDim[Byte](plaintext.length)
|
val ciphertext = Array.ofDim[Byte](plaintext.length.toInt)
|
||||||
|
|
||||||
val ret = psLib.RC5_Encrypt(encCryptoHandle, plaintext.toArray, plaintext.length, ciphertext)[Boolean]
|
val ret = psLib.RC5_Encrypt(encCryptoHandle, plaintext.toArray, plaintext.length, ciphertext)[Boolean]
|
||||||
|
|
||||||
|
|
@ -196,7 +196,7 @@ object CryptoInterface {
|
||||||
if(ciphertext.length % RC5_BLOCK_SIZE != 0)
|
if(ciphertext.length % RC5_BLOCK_SIZE != 0)
|
||||||
throw new IllegalArgumentException(s"input must be padded to the nearest $RC5_BLOCK_SIZE byte boundary")
|
throw new IllegalArgumentException(s"input must be padded to the nearest $RC5_BLOCK_SIZE byte boundary")
|
||||||
|
|
||||||
val plaintext = Array.ofDim[Byte](ciphertext.length)
|
val plaintext = Array.ofDim[Byte](ciphertext.length.toInt)
|
||||||
|
|
||||||
val ret = psLib.RC5_Decrypt(decCryptoHandle, ciphertext.toArray, ciphertext.length, plaintext)[Boolean]
|
val ret = psLib.RC5_Decrypt(decCryptoHandle, ciphertext.toArray, ciphertext.length, plaintext)[Boolean]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -386,7 +386,7 @@ object PacketCoding {
|
||||||
|
|
||||||
// minus 1 because of the actual byte telling of the padding, which always has to be there
|
// minus 1 because of the actual byte telling of the padding, which always has to be there
|
||||||
val paddingNeeded = CryptoInterface.RC5_BLOCK_SIZE - remainder - 1
|
val paddingNeeded = CryptoInterface.RC5_BLOCK_SIZE - remainder - 1
|
||||||
val paddingEncoded = uint8L.encode(paddingNeeded).require
|
val paddingEncoded = uint8L.encode(paddingNeeded.toInt).require
|
||||||
|
|
||||||
val packetWithPadding = packetNoPadding ++ ByteVector.fill(paddingNeeded)(0x00) ++ paddingEncoded.toByteVector
|
val packetWithPadding = packetNoPadding ++ ByteVector.fill(paddingNeeded)(0x00) ++ paddingEncoded.toByteVector
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
// Copyright (c) 2016 PSForever.net to present
|
// Copyright (c) 2016 PSForever.net to present
|
||||||
|
|
||||||
import org.specs2.mutable._
|
import org.specs2.mutable._
|
||||||
|
import org.specs2.specification
|
||||||
import net.psforever.packet._
|
import net.psforever.packet._
|
||||||
import net.psforever.packet.control._
|
import net.psforever.packet.control._
|
||||||
|
import org.specs2.specification.core.Fragment
|
||||||
import scodec.Attempt.Successful
|
import scodec.Attempt.Successful
|
||||||
import scodec.bits._
|
import scodec.bits._
|
||||||
import scodec.codecs.uint16
|
import scodec.codecs.uint16
|
||||||
|
|
@ -27,7 +29,7 @@ class ControlPacketTest extends Specification {
|
||||||
g mustEqual 0x276
|
g mustEqual 0x276
|
||||||
h mustEqual 0x275
|
h mustEqual 0x275
|
||||||
case default =>
|
case default =>
|
||||||
true mustEqual false
|
ko
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,7 +54,7 @@ class ControlPacketTest extends Specification {
|
||||||
e mustEqual 0x275
|
e mustEqual 0x275
|
||||||
f mustEqual 0x276
|
f mustEqual 0x276
|
||||||
case default =>
|
case default =>
|
||||||
true mustEqual false
|
ko
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +88,7 @@ class ControlPacketTest extends Specification {
|
||||||
subslot mustEqual 0
|
subslot mustEqual 0
|
||||||
rest mustEqual string.drop(4)
|
rest mustEqual string.drop(4)
|
||||||
case default =>
|
case default =>
|
||||||
true mustEqual false
|
ko
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,25 +96,25 @@ class ControlPacketTest extends Specification {
|
||||||
val maxSlots = ControlPacketOpcode.SlottedMetaPacket7.id - ControlPacketOpcode.SlottedMetaPacket0.id
|
val maxSlots = ControlPacketOpcode.SlottedMetaPacket7.id - ControlPacketOpcode.SlottedMetaPacket0.id
|
||||||
|
|
||||||
// create all possible SlottedMetaPackets
|
// create all possible SlottedMetaPackets
|
||||||
for(i <- 0 until maxSlots) {
|
Fragment.foreach(0 to maxSlots) { i =>
|
||||||
val subslot = 12323
|
"slot " + i ! {
|
||||||
val pkt = createMetaPacket(i, subslot, ByteVector.empty)
|
val subslot = 12323
|
||||||
|
val pkt = createMetaPacket(i, subslot, ByteVector.empty)
|
||||||
|
|
||||||
PacketCoding.DecodePacket(pkt).require match {
|
PacketCoding.DecodePacket(pkt).require match {
|
||||||
case SlottedMetaPacket(slot, subslotDecoded, rest) =>
|
case SlottedMetaPacket(slot, subslotDecoded, rest) =>
|
||||||
|
|
||||||
// XXX: there isn't a simple solution to Slot0 and Slot4 be aliases of each other structurally
|
// XXX: there isn't a simple solution to Slot0 and Slot4 be aliases of each other structurally
|
||||||
// This is probably best left to higher layers
|
// This is probably best left to higher layers
|
||||||
//slot mustEqual i % 4 // this is seen at 0x00A3FBFA
|
//slot mustEqual i % 4 // this is seen at 0x00A3FBFA
|
||||||
slot mustEqual i
|
slot mustEqual i
|
||||||
subslotDecoded mustEqual subslot
|
subslotDecoded mustEqual subslot
|
||||||
rest mustEqual ByteVector.empty // empty in this case
|
rest mustEqual ByteVector.empty // empty in this case
|
||||||
case default =>
|
case default =>
|
||||||
true mustEqual false
|
ko
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
"encode" in {
|
"encode" in {
|
||||||
|
|
@ -154,19 +156,15 @@ class ControlPacketTest extends Specification {
|
||||||
)
|
)
|
||||||
|
|
||||||
"decode" in {
|
"decode" in {
|
||||||
for(i <- strings.indices) {
|
Fragment.foreach(strings.indices) { i =>
|
||||||
MultiPacketEx.decode(strings{i}.bits).require.value mustEqual packets{i}
|
"test "+i ! { MultiPacketEx.decode(strings{i}.bits).require.value mustEqual packets{i} }
|
||||||
}
|
}
|
||||||
|
|
||||||
true mustEqual true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
"encode" in {
|
"encode" in {
|
||||||
for(i <- packets.indices) {
|
Fragment.foreach(packets.indices) { i =>
|
||||||
MultiPacketEx.encode(packets{i}).require.toByteVector mustEqual strings{i}
|
"test "+i ! { MultiPacketEx.encode(packets{i}).require.toByteVector mustEqual strings{i} }
|
||||||
}
|
}
|
||||||
|
|
||||||
true mustEqual true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ class CryptoInterfaceTest extends Specification {
|
||||||
hex"b4aea1559444a20b6112a2892de40eac00000000c8aea155b53d187076b79abab59001b600000000"
|
hex"b4aea1559444a20b6112a2892de40eac00000000c8aea155b53d187076b79abab59001b600000000"
|
||||||
val expected = hex"5aa15de41f5220cf5cca489155e1438c5aa15de4"
|
val expected = hex"5aa15de41f5220cf5cca489155e1438c5aa15de4"
|
||||||
|
|
||||||
val output = CryptoInterface.MD5MAC(key, message, expected.length)
|
val output = CryptoInterface.MD5MAC(key, message, expected.length.toInt)
|
||||||
|
|
||||||
output mustEqual expected
|
output mustEqual expected
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class GamePacketTest extends Specification {
|
||||||
buildDate mustEqual ""
|
buildDate mustEqual ""
|
||||||
unk mustEqual 0
|
unk mustEqual 0
|
||||||
case default =>
|
case default =>
|
||||||
true mustEqual false
|
ko
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ class GamePacketTest extends Specification {
|
||||||
serverIp mustEqual "64.37.158.69"
|
serverIp mustEqual "64.37.158.69"
|
||||||
serverPort mustEqual 30012
|
serverPort mustEqual 30012
|
||||||
case default =>
|
case default =>
|
||||||
true mustEqual false
|
ko
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ class GamePacketTest extends Specification {
|
||||||
world.connections{0}.address.getPort mustEqual 30007
|
world.connections{0}.address.getPort mustEqual 30007
|
||||||
world.connections{0}.address.getAddress.toString mustEqual "/64.37.158.69"
|
world.connections{0}.address.getAddress.toString mustEqual "/64.37.158.69"
|
||||||
case default =>
|
case default =>
|
||||||
true mustEqual false
|
ko
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,7 +111,8 @@ class GamePacketTest extends Specification {
|
||||||
|
|
||||||
//println(pkt)
|
//println(pkt)
|
||||||
|
|
||||||
true mustEqual true
|
// TODO: actually test something
|
||||||
|
ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue