Rename WHIRLPOOL to DIGESTS for consistency with the Js5Index flags

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 53db5b3314
commit bdaf5aae2c
  1. 2
      archive/src/main/resources/org/openrs2/archive/V1__init.sql
  2. 12
      cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt
  3. 2
      cache/src/main/kotlin/org/openrs2/cache/MasterIndexFormat.kt
  4. 18
      cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt

@ -93,7 +93,7 @@ CREATE TABLE index_files (
CREATE TYPE master_index_format AS ENUM ( CREATE TYPE master_index_format AS ENUM (
'original', 'original',
'versioned', 'versioned',
'whirlpool', 'digests',
'lengths' 'lengths'
); );

@ -69,7 +69,7 @@ public data class Js5MasterIndex(
public fun write(buf: ByteBuf, key: RSAKeyParameters? = null) { public fun write(buf: ByteBuf, key: RSAKeyParameters? = null) {
val start = buf.writerIndex() val start = buf.writerIndex()
if (format >= MasterIndexFormat.WHIRLPOOL) { if (format >= MasterIndexFormat.DIGESTS) {
buf.writeByte(entries.size) buf.writeByte(entries.size)
} }
@ -85,7 +85,7 @@ public data class Js5MasterIndex(
buf.writeInt(entry.totalUncompressedLength) buf.writeInt(entry.totalUncompressedLength)
} }
if (format >= MasterIndexFormat.WHIRLPOOL) { if (format >= MasterIndexFormat.DIGESTS) {
val digest = entry.digest val digest = entry.digest
if (digest != null) { if (digest != null) {
buf.writeBytes(digest) buf.writeBytes(digest)
@ -95,7 +95,7 @@ public data class Js5MasterIndex(
} }
} }
if (format >= MasterIndexFormat.WHIRLPOOL) { if (format >= MasterIndexFormat.DIGESTS) {
val digest = buf.whirlpool(start, buf.writerIndex() - start) val digest = buf.whirlpool(start, buf.writerIndex() - start)
if (key != null) { if (key != null) {
@ -141,7 +141,7 @@ public data class Js5MasterIndex(
if (index.hasLengths) { if (index.hasLengths) {
masterIndex.format = maxOf(masterIndex.format, MasterIndexFormat.LENGTHS) masterIndex.format = maxOf(masterIndex.format, MasterIndexFormat.LENGTHS)
} else if (index.hasDigests) { } else if (index.hasDigests) {
masterIndex.format = maxOf(masterIndex.format, MasterIndexFormat.WHIRLPOOL) masterIndex.format = maxOf(masterIndex.format, MasterIndexFormat.DIGESTS)
} else if (index.protocol >= Js5Protocol.VERSIONED) { } else if (index.protocol >= Js5Protocol.VERSIONED) {
masterIndex.format = maxOf(masterIndex.format, MasterIndexFormat.VERSIONED) masterIndex.format = maxOf(masterIndex.format, MasterIndexFormat.VERSIONED)
} }
@ -205,7 +205,7 @@ public data class Js5MasterIndex(
totalUncompressedLength = 0 totalUncompressedLength = 0
} }
val digest = if (format >= MasterIndexFormat.WHIRLPOOL) { val digest = if (format >= MasterIndexFormat.DIGESTS) {
val bytes = ByteArray(Whirlpool.DIGESTBYTES) val bytes = ByteArray(Whirlpool.DIGESTBYTES)
buf.readBytes(bytes) buf.readBytes(bytes)
bytes bytes
@ -218,7 +218,7 @@ public data class Js5MasterIndex(
val end = buf.readerIndex() val end = buf.readerIndex()
if (format >= MasterIndexFormat.WHIRLPOOL) { if (format >= MasterIndexFormat.DIGESTS) {
val ciphertext = buf.readSlice(buf.readableBytes()) val ciphertext = buf.readSlice(buf.readableBytes())
decrypt(ciphertext, key).use { plaintext -> decrypt(ciphertext, key).use { plaintext ->
require(plaintext.readableBytes() == SIGNATURE_LENGTH) { require(plaintext.readableBytes() == SIGNATURE_LENGTH) {

@ -3,6 +3,6 @@ package org.openrs2.cache
public enum class MasterIndexFormat { public enum class MasterIndexFormat {
ORIGINAL, ORIGINAL,
VERSIONED, VERSIONED,
WHIRLPOOL, DIGESTS,
LENGTHS LENGTHS
} }

@ -83,7 +83,7 @@ class Js5MasterIndexTest {
assertEquals( assertEquals(
Js5MasterIndex( Js5MasterIndex(
MasterIndexFormat.WHIRLPOOL, MasterIndexFormat.DIGESTS,
mutableListOf( mutableListOf(
Js5MasterIndex.Entry( Js5MasterIndex.Entry(
0, 668177970, 0, 0, ByteBufUtil.decodeHexDump( 0, 668177970, 0, 0, ByteBufUtil.decodeHexDump(
@ -176,7 +176,7 @@ class Js5MasterIndexTest {
@Test @Test
fun testReadWhirlpool() { fun testReadWhirlpool() {
Unpooled.wrappedBuffer(encodedWhirlpool).use { buf -> Unpooled.wrappedBuffer(encodedWhirlpool).use { buf ->
val index = Js5MasterIndex.read(buf, MasterIndexFormat.WHIRLPOOL) val index = Js5MasterIndex.read(buf, MasterIndexFormat.DIGESTS)
assertEquals(decodedWhirlpool, index) assertEquals(decodedWhirlpool, index)
} }
} }
@ -188,7 +188,7 @@ class Js5MasterIndexTest {
buf.setByte(lastIndex, buf.getByte(lastIndex).toInt().inv()) buf.setByte(lastIndex, buf.getByte(lastIndex).toInt().inv())
assertFailsWith<IllegalArgumentException> { assertFailsWith<IllegalArgumentException> {
Js5MasterIndex.read(buf, MasterIndexFormat.WHIRLPOOL) Js5MasterIndex.read(buf, MasterIndexFormat.DIGESTS)
} }
} }
} }
@ -197,7 +197,7 @@ class Js5MasterIndexTest {
fun testReadWhirlpoolInvalidSignatureLength() { fun testReadWhirlpoolInvalidSignatureLength() {
Unpooled.wrappedBuffer(encodedWhirlpool, 0, encodedWhirlpool.size - 1).use { buf -> Unpooled.wrappedBuffer(encodedWhirlpool, 0, encodedWhirlpool.size - 1).use { buf ->
assertFailsWith<IllegalArgumentException> { assertFailsWith<IllegalArgumentException> {
Js5MasterIndex.read(buf, MasterIndexFormat.WHIRLPOOL) Js5MasterIndex.read(buf, MasterIndexFormat.DIGESTS)
} }
} }
} }
@ -227,7 +227,7 @@ class Js5MasterIndexTest {
@Test @Test
fun testReadSigned() { fun testReadSigned() {
Unpooled.wrappedBuffer(encodedSigned).use { buf -> Unpooled.wrappedBuffer(encodedSigned).use { buf ->
val index = Js5MasterIndex.read(buf, MasterIndexFormat.WHIRLPOOL, PUBLIC_KEY) val index = Js5MasterIndex.read(buf, MasterIndexFormat.DIGESTS, PUBLIC_KEY)
assertEquals(decodedWhirlpool, index) assertEquals(decodedWhirlpool, index)
} }
} }
@ -239,7 +239,7 @@ class Js5MasterIndexTest {
buf.setByte(lastIndex, buf.getByte(lastIndex).toInt().inv()) buf.setByte(lastIndex, buf.getByte(lastIndex).toInt().inv())
assertFailsWith<IllegalArgumentException> { assertFailsWith<IllegalArgumentException> {
Js5MasterIndex.read(buf, MasterIndexFormat.WHIRLPOOL, PUBLIC_KEY) Js5MasterIndex.read(buf, MasterIndexFormat.DIGESTS, PUBLIC_KEY)
} }
} }
} }
@ -248,7 +248,7 @@ class Js5MasterIndexTest {
fun testReadSignedInvalidSignatureLength() { fun testReadSignedInvalidSignatureLength() {
Unpooled.wrappedBuffer(encodedSigned, 0, encodedSigned.size - 1).use { buf -> Unpooled.wrappedBuffer(encodedSigned, 0, encodedSigned.size - 1).use { buf ->
assertFailsWith<IllegalArgumentException> { assertFailsWith<IllegalArgumentException> {
Js5MasterIndex.read(buf, MasterIndexFormat.WHIRLPOOL, PUBLIC_KEY) Js5MasterIndex.read(buf, MasterIndexFormat.DIGESTS, PUBLIC_KEY)
} }
} }
} }
@ -319,7 +319,7 @@ class Js5MasterIndexTest {
"b3ecb77cc1a8f9ccd53c405b3264e598820b4940f630ff079a9feb950f639671" "b3ecb77cc1a8f9ccd53c405b3264e598820b4940f630ff079a9feb950f639671"
) )
private val decodedWhirlpool = Js5MasterIndex( private val decodedWhirlpool = Js5MasterIndex(
MasterIndexFormat.WHIRLPOOL, MasterIndexFormat.DIGESTS,
mutableListOf( mutableListOf(
Js5MasterIndex.Entry( Js5MasterIndex.Entry(
0x01234567, 0x89ABCDEF.toInt(), 0, 0, ByteBufUtil.decodeHexDump( 0x01234567, 0x89ABCDEF.toInt(), 0, 0, ByteBufUtil.decodeHexDump(
@ -341,7 +341,7 @@ class Js5MasterIndexTest {
"8a65765bc2dce9d67029be79bd544f96055a41d725c080bc5b85a48b5aae6e4d" "8a65765bc2dce9d67029be79bd544f96055a41d725c080bc5b85a48b5aae6e4d"
) )
private val decodedWhirlpoolNullDigest = Js5MasterIndex( private val decodedWhirlpoolNullDigest = Js5MasterIndex(
MasterIndexFormat.WHIRLPOOL, MasterIndexFormat.DIGESTS,
mutableListOf( mutableListOf(
Js5MasterIndex.Entry(0x01234567, 0x89ABCDEF.toInt(), 0, 0, null) Js5MasterIndex.Entry(0x01234567, 0x89ABCDEF.toInt(), 0, 0, null)
) )

Loading…
Cancel
Save