From bdaf5aae2c07bf51f636bd58a5e774a89858dc9d Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 13 Feb 2021 16:17:17 +0000 Subject: [PATCH] Rename WHIRLPOOL to DIGESTS for consistency with the Js5Index flags Signed-off-by: Graham --- .../resources/org/openrs2/archive/V1__init.sql | 2 +- .../kotlin/org/openrs2/cache/Js5MasterIndex.kt | 12 ++++++------ .../org/openrs2/cache/MasterIndexFormat.kt | 2 +- .../org/openrs2/cache/Js5MasterIndexTest.kt | 18 +++++++++--------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/archive/src/main/resources/org/openrs2/archive/V1__init.sql b/archive/src/main/resources/org/openrs2/archive/V1__init.sql index c03d0812..69c48391 100644 --- a/archive/src/main/resources/org/openrs2/archive/V1__init.sql +++ b/archive/src/main/resources/org/openrs2/archive/V1__init.sql @@ -93,7 +93,7 @@ CREATE TABLE index_files ( CREATE TYPE master_index_format AS ENUM ( 'original', 'versioned', - 'whirlpool', + 'digests', 'lengths' ); diff --git a/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt b/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt index 2f09d6e0..23c4f03e 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt @@ -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) { diff --git a/cache/src/main/kotlin/org/openrs2/cache/MasterIndexFormat.kt b/cache/src/main/kotlin/org/openrs2/cache/MasterIndexFormat.kt index c629fe26..017d351d 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/MasterIndexFormat.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/MasterIndexFormat.kt @@ -3,6 +3,6 @@ package org.openrs2.cache public enum class MasterIndexFormat { ORIGINAL, VERSIONED, - WHIRLPOOL, + DIGESTS, LENGTHS } diff --git a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt b/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt index f51cdad4..d2d21ab7 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt @@ -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 { - 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 { - 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 { - 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 { - 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) )