Rename WHIRLPOOL to DIGESTS for consistency with the Js5Index flags

Signed-off-by: Graham <gpe@openrs2.org>
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 (
'original',
'versioned',
'whirlpool',
'digests',
'lengths'
);

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

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

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

Loading…
Cancel
Save