From ac0e2428775e33884abed515ff1c57e611685abf Mon Sep 17 00:00:00 2001 From: Matthew Nelson Date: Sat, 4 Jan 2025 07:16:52 -0500 Subject: [PATCH] Rename digestProtected parameters to buf && bufPos --- .../kotlincrypto/core/benchmarks/DigestOps.kt | 2 +- .../org/kotlincrypto/core/digest/Digest.kt | 10 +++---- .../core/digest/internal/-Buffer.kt | 20 ++++++------- .../kotlincrypto/core/digest/TestDigest.kt | 4 +-- .../org/kotlincrypto/core/digest/Digest.kt | 28 +++++++++---------- .../core/digest/JvmDigestUnitTest.kt | 4 +-- .../org/kotlincrypto/core/digest/Digest.kt | 28 +++++++++---------- 7 files changed, 48 insertions(+), 48 deletions(-) diff --git a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/core/benchmarks/DigestOps.kt b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/core/benchmarks/DigestOps.kt index d00d68d..e004033 100644 --- a/benchmarks/src/commonMain/kotlin/org/kotlincrypto/core/benchmarks/DigestOps.kt +++ b/benchmarks/src/commonMain/kotlin/org/kotlincrypto/core/benchmarks/DigestOps.kt @@ -32,7 +32,7 @@ open class DigestBenchmark { override fun resetProtected() {} override fun copy(): TestDigest = TestDigest(this) override fun compressProtected(input: ByteArray, offset: Int) {} - override fun digestProtected(buffer: ByteArray, offset: Int): ByteArray = ByteArray(0) + override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray = ByteArray(0) } private val digest = TestDigest() diff --git a/library/digest/src/commonMain/kotlin/org/kotlincrypto/core/digest/Digest.kt b/library/digest/src/commonMain/kotlin/org/kotlincrypto/core/digest/Digest.kt index ca1452c..29a8dde 100644 --- a/library/digest/src/commonMain/kotlin/org/kotlincrypto/core/digest/Digest.kt +++ b/library/digest/src/commonMain/kotlin/org/kotlincrypto/core/digest/Digest.kt @@ -118,13 +118,13 @@ public expect abstract class Digest: Algorithm, Copyable, Resettable, Up protected abstract fun compressProtected(input: ByteArray, offset: Int) /** - * Called to complete the computation, providing any input that may be - * buffered awaiting processing. + * Called to complete the computation, providing any input that may be buffered + * and awaiting processing. * - * @param [buffer] Unprocessed input - * @param [offset] The index at which the next input would be placed in the [buffer] + * @param [buf] Unprocessed input + * @param [bufPos] The index at which the **next** input would be placed into [buf] * */ - protected abstract fun digestProtected(buffer: ByteArray, offset: Int): ByteArray + protected abstract fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray /** * Optional override for implementations to intercept cleansed input before diff --git a/library/digest/src/commonMain/kotlin/org/kotlincrypto/core/digest/internal/-Buffer.kt b/library/digest/src/commonMain/kotlin/org/kotlincrypto/core/digest/internal/-Buffer.kt index 263dfaf..65654a9 100644 --- a/library/digest/src/commonMain/kotlin/org/kotlincrypto/core/digest/internal/-Buffer.kt +++ b/library/digest/src/commonMain/kotlin/org/kotlincrypto/core/digest/internal/-Buffer.kt @@ -46,17 +46,17 @@ internal value class Buffer private constructor(internal val value: ByteArray) { @Suppress("NOTHING_TO_INLINE") internal inline fun Buffer.commonUpdate( input: Byte, - bufOffsPlusPlus: Int, - bufOffsSet: (zero: Int) -> Unit, + bufPosPlusPlus: Int, + bufPosSet: (zero: Int) -> Unit, compressProtected: (buf: ByteArray, offset: Int) -> Unit, ) { val buf = value - buf[bufOffsPlusPlus] = input + buf[bufPosPlusPlus] = input // buf.size == blockSize - if ((bufOffsPlusPlus + 1) != buf.size) return + if ((bufPosPlusPlus + 1) != buf.size) return compressProtected(buf, 0) - bufOffsSet(0) + bufPosSet(0) } @Suppress("NOTHING_TO_INLINE") @@ -64,15 +64,15 @@ internal inline fun Buffer.commonUpdate( input: ByteArray, offset: Int, len: Int, - bufOffs: Int, - bufOffsSet: (value: Int) -> Unit, + bufPos: Int, + bufPosSet: (value: Int) -> Unit, compressProtected: (buf: ByteArray, offset: Int) -> Unit, ) { val buf = value val blockSize = buf.size var offsInput = offset val limit = offsInput + len - var offsBuf = bufOffs + var offsBuf = bufPos if (offsBuf > 0) { // Need to use buffered data (if possible) @@ -80,7 +80,7 @@ internal inline fun Buffer.commonUpdate( if (offsBuf + len < blockSize) { // Not enough for a compression. Add it to the buffer. input.copyInto(buf, offsBuf, offsInput, limit) - bufOffsSet(offsBuf + len) + bufPosSet(offsBuf + len) return } @@ -108,5 +108,5 @@ internal inline fun Buffer.commonUpdate( } // Update globals - bufOffsSet(offsBuf) + bufPosSet(offsBuf) } diff --git a/library/digest/src/commonTest/kotlin/org/kotlincrypto/core/digest/TestDigest.kt b/library/digest/src/commonTest/kotlin/org/kotlincrypto/core/digest/TestDigest.kt index c5e5735..9a2e09b 100644 --- a/library/digest/src/commonTest/kotlin/org/kotlincrypto/core/digest/TestDigest.kt +++ b/library/digest/src/commonTest/kotlin/org/kotlincrypto/core/digest/TestDigest.kt @@ -51,8 +51,8 @@ class TestDigest: Digest { compressions++ } - override fun digestProtected(buffer: ByteArray, offset: Int): ByteArray { - return finalize.invoke(buffer, offset) + override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray { + return finalize.invoke(buf, bufPos) } override fun resetProtected() { diff --git a/library/digest/src/jvmMain/kotlin/org/kotlincrypto/core/digest/Digest.kt b/library/digest/src/jvmMain/kotlin/org/kotlincrypto/core/digest/Digest.kt index 029f18f..78f8329 100644 --- a/library/digest/src/jvmMain/kotlin/org/kotlincrypto/core/digest/Digest.kt +++ b/library/digest/src/jvmMain/kotlin/org/kotlincrypto/core/digest/Digest.kt @@ -41,7 +41,7 @@ public actual abstract class Digest: MessageDigest, Algorithm, Cloneable, Copyab private val digestLength: Int private val buf: Buffer - private var bufOffs: Int + private var bufPos: Int /** * Creates a new [Digest] for the specified parameters. @@ -59,7 +59,7 @@ public actual abstract class Digest: MessageDigest, Algorithm, Cloneable, Copyab protected actual constructor(algorithm: String, blockSize: Int, digestLength: Int): super(algorithm) { this.buf = Buffer.initialize(algorithm, blockSize, digestLength) this.digestLength = digestLength - this.bufOffs = 0 + this.bufPos = 0 } /** @@ -87,7 +87,7 @@ public actual abstract class Digest: MessageDigest, Algorithm, Cloneable, Copyab protected actual constructor(other: Digest): super(other.algorithm) { this.digestLength = other.digestLength this.buf = other.buf.copy() - this.bufOffs = other.bufOffs + this.bufPos = other.bufPos } /** @@ -125,7 +125,7 @@ public actual abstract class Digest: MessageDigest, Algorithm, Cloneable, Copyab * the resultant array of bytes. The [Digest] is [reset] afterward. * */ public actual final override fun digest(): ByteArray { - val final = digestProtected(buf.value, bufOffs) + val final = digestProtected(buf.value, bufPos) reset() return final } @@ -143,7 +143,7 @@ public actual abstract class Digest: MessageDigest, Algorithm, Cloneable, Copyab // See Resettable interface documentation public actual final override fun reset() { buf.value.fill(0) - bufOffs = 0 + bufPos = 0 resetProtected() } @@ -155,13 +155,13 @@ public actual abstract class Digest: MessageDigest, Algorithm, Cloneable, Copyab protected actual abstract fun compressProtected(input: ByteArray, offset: Int) /** - * Called to complete the computation, providing any input that may be - * buffered awaiting processing. + * Called to complete the computation, providing any input that may be buffered + * and awaiting processing. * - * @param [buffer] Unprocessed input - * @param [offset] The index at which the next input would be placed in the [buffer] + * @param [buf] Unprocessed input + * @param [bufPos] The index at which the **next** input would be placed into [buf] * */ - protected actual abstract fun digestProtected(buffer: ByteArray, offset: Int): ByteArray + protected actual abstract fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray /** * Optional override for implementations to intercept cleansed input before @@ -170,8 +170,8 @@ public actual abstract class Digest: MessageDigest, Algorithm, Cloneable, Copyab protected actual open fun updateProtected(input: Byte) { buf.commonUpdate( input = input, - bufOffsPlusPlus = bufOffs++, - bufOffsSet = { bufOffs = it }, + bufPosPlusPlus = bufPos++, + bufPosSet = { bufPos = it }, compressProtected = ::compressProtected, ) } @@ -186,8 +186,8 @@ public actual abstract class Digest: MessageDigest, Algorithm, Cloneable, Copyab input = input, offset = offset, len = len, - bufOffs = bufOffs, - bufOffsSet = { bufOffs = it }, + bufPos = bufPos, + bufPosSet = { bufPos = it }, compressProtected = ::compressProtected, ) } diff --git a/library/digest/src/jvmTest/kotlin/org/kotlincrypto/core/digest/JvmDigestUnitTest.kt b/library/digest/src/jvmTest/kotlin/org/kotlincrypto/core/digest/JvmDigestUnitTest.kt index c55dd55..a7d8657 100644 --- a/library/digest/src/jvmTest/kotlin/org/kotlincrypto/core/digest/JvmDigestUnitTest.kt +++ b/library/digest/src/jvmTest/kotlin/org/kotlincrypto/core/digest/JvmDigestUnitTest.kt @@ -43,8 +43,8 @@ class JvmDigestUnitTest { delegate.update(input, offset, blockSize()) } - override fun digestProtected(buffer: ByteArray, offset: Int): ByteArray { - delegate.update(buffer, 0, offset) + override fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray { + delegate.update(buf, 0, bufPos) return delegate.digest() } diff --git a/library/digest/src/nonJvmMain/kotlin/org/kotlincrypto/core/digest/Digest.kt b/library/digest/src/nonJvmMain/kotlin/org/kotlincrypto/core/digest/Digest.kt index 32298dc..6d94959 100644 --- a/library/digest/src/nonJvmMain/kotlin/org/kotlincrypto/core/digest/Digest.kt +++ b/library/digest/src/nonJvmMain/kotlin/org/kotlincrypto/core/digest/Digest.kt @@ -36,7 +36,7 @@ public actual abstract class Digest: Algorithm, Copyable, Resettable, Up private val algorithm: String private val digestLength: Int private val buf: Buffer - private var bufOffs: Int + private var bufPos: Int /** * Creates a new [Digest] for the specified parameters. @@ -55,7 +55,7 @@ public actual abstract class Digest: Algorithm, Copyable, Resettable, Up this.buf = Buffer.initialize(algorithm, blockSize, digestLength) this.algorithm = algorithm this.digestLength = digestLength - this.bufOffs = 0 + this.bufPos = 0 } /** @@ -84,7 +84,7 @@ public actual abstract class Digest: Algorithm, Copyable, Resettable, Up this.algorithm = other.algorithm this.digestLength = other.digestLength this.buf = other.buf.copy() - this.bufOffs = other.bufOffs + this.bufPos = other.bufPos } /** @@ -122,7 +122,7 @@ public actual abstract class Digest: Algorithm, Copyable, Resettable, Up * the resultant array of bytes. The [Digest] is [reset] afterward. * */ public actual fun digest(): ByteArray { - val final = digestProtected(buf.value, bufOffs) + val final = digestProtected(buf.value, bufPos) reset() return final } @@ -140,7 +140,7 @@ public actual abstract class Digest: Algorithm, Copyable, Resettable, Up // See Resettable interface documentation public actual final override fun reset() { buf.value.fill(0) - bufOffs = 0 + bufPos = 0 resetProtected() } @@ -152,13 +152,13 @@ public actual abstract class Digest: Algorithm, Copyable, Resettable, Up protected actual abstract fun compressProtected(input: ByteArray, offset: Int) /** - * Called to complete the computation, providing any input that may be - * buffered awaiting processing. + * Called to complete the computation, providing any input that may be buffered + * and awaiting processing. * - * @param [buffer] Unprocessed input - * @param [offset] The index at which the next input would be placed in the [buffer] + * @param [buf] Unprocessed input + * @param [bufPos] The index at which the **next** input would be placed into [buf] * */ - protected actual abstract fun digestProtected(buffer: ByteArray, offset: Int): ByteArray + protected actual abstract fun digestProtected(buf: ByteArray, bufPos: Int): ByteArray /** * Optional override for implementations to intercept cleansed input before @@ -167,8 +167,8 @@ public actual abstract class Digest: Algorithm, Copyable, Resettable, Up protected actual open fun updateProtected(input: Byte) { buf.commonUpdate( input = input, - bufOffsPlusPlus = bufOffs++, - bufOffsSet = { bufOffs = it }, + bufPosPlusPlus = bufPos++, + bufPosSet = { bufPos = it }, compressProtected = ::compressProtected, ) } @@ -183,8 +183,8 @@ public actual abstract class Digest: Algorithm, Copyable, Resettable, Up input = input, offset = offset, len = len, - bufOffs = bufOffs, - bufOffsSet = { bufOffs = it }, + bufPos = bufPos, + bufPosSet = { bufPos = it }, compressProtected = ::compressProtected, ) }