From 90aa3eaf798fda105d78fdb939d288aeb94d2640 Mon Sep 17 00:00:00 2001 From: Carter Jernigan Date: Mon, 25 Apr 2022 11:55:31 -0400 Subject: [PATCH] [#25] Enable strict Kotlin compiler warnings Fixed existing warnings, which included: - Suppressing a deprecation warning for Java 9, as we have to maintain compatibility with Java 8 for Android - Using a new Kotlin API introduced in Kotlin 1.5 - Removed unused local variables --- gradle.properties | 2 +- .../kotlin/cash/z/ecc/android/crypto/FallbackProvider.kt | 3 +++ .../jvmMain/kotlin/cash/z/ecc/android/crypto/Pbkdf2Sha512.kt | 2 +- .../jvmTest/kotlin/cash/z/ecc/android/bip39/MnemonicsTest.kt | 2 +- .../kotlin/cash/z/ecc/android/bip39/ReadmeExamplesTest.kt | 1 - 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 50c556e..c7d8c73 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m kotlin.mpp.stability.nowarn=true -BIP39_IS_TREAT_WARNINGS_AS_ERRORS=false +BIP39_IS_TREAT_WARNINGS_AS_ERRORS=true JVM_TOOLCHAIN=17 JVM_TARGET=1.8 diff --git a/lib/src/jvmMain/kotlin/cash/z/ecc/android/crypto/FallbackProvider.kt b/lib/src/jvmMain/kotlin/cash/z/ecc/android/crypto/FallbackProvider.kt index 88a2e06..81ac2b7 100644 --- a/lib/src/jvmMain/kotlin/cash/z/ecc/android/crypto/FallbackProvider.kt +++ b/lib/src/jvmMain/kotlin/cash/z/ecc/android/crypto/FallbackProvider.kt @@ -13,6 +13,9 @@ import javax.crypto.spec.SecretKeySpec * service provider. This provides a bridge to a commonly used Java implementation that has been * moderately adapted to Kotlin. */ +// Constructor was deprecated in Java 9, but for compatibility with Android (Java 8, effectively) the old constructor +// must continue to be used. +@Suppress("DEPRECATION") class FallbackProvider : Provider( "FallbackProvider", 1.0, diff --git a/lib/src/jvmMain/kotlin/cash/z/ecc/android/crypto/Pbkdf2Sha512.kt b/lib/src/jvmMain/kotlin/cash/z/ecc/android/crypto/Pbkdf2Sha512.kt index ca17933..3a64dcf 100644 --- a/lib/src/jvmMain/kotlin/cash/z/ecc/android/crypto/Pbkdf2Sha512.kt +++ b/lib/src/jvmMain/kotlin/cash/z/ecc/android/crypto/Pbkdf2Sha512.kt @@ -35,7 +35,7 @@ object Pbkdf2Sha512 { ByteArrayOutputStream().use { baos -> val dkLenBytes = dkLen/8 val pBytes = p.foldIndexed(ByteArray(p.size)) { i, acc, c -> - acc.apply { this[i] = c.toByte() } + acc.apply { this[i] = c.code.toByte() } } val hLen = 20.0 // note: dropped length check because it's redundant, given the size of an int in kotlin diff --git a/lib/src/jvmTest/kotlin/cash/z/ecc/android/bip39/MnemonicsTest.kt b/lib/src/jvmTest/kotlin/cash/z/ecc/android/bip39/MnemonicsTest.kt index 746fd50..415eaa1 100644 --- a/lib/src/jvmTest/kotlin/cash/z/ecc/android/bip39/MnemonicsTest.kt +++ b/lib/src/jvmTest/kotlin/cash/z/ecc/android/bip39/MnemonicsTest.kt @@ -102,7 +102,7 @@ class MnemonicsTest : BehaviorSpec({ row(18, "d5bcbf62dea1a07ab1abb0144b299300137168a7939f3071f112b557", "stick tourist suffer run borrow diary shop invite begin flock gospel ability damage reform oxygen initial corn moon dwarf height image"), row(15, "e06ce21369dc09eb2bda66510a76f65ab3f947cce90fcb10", "there grow luggage squirrel scene void quarter error extra father rural rely display physical crisp capable slam lumber"), row(12, "0b01c3c0b0590faf45fc171da17cfb22", "arch asthma usual gaze movie stumble blood load buffalo armor disagree earth") - ) { count, entropy, mnemonic -> + ) { _, entropy, mnemonic -> val code = MnemonicCode(entropy.fromHex()) String(code.chars) shouldBe mnemonic } diff --git a/lib/src/jvmTest/kotlin/cash/z/ecc/android/bip39/ReadmeExamplesTest.kt b/lib/src/jvmTest/kotlin/cash/z/ecc/android/bip39/ReadmeExamplesTest.kt index 976ffb9..18ede75 100644 --- a/lib/src/jvmTest/kotlin/cash/z/ecc/android/bip39/ReadmeExamplesTest.kt +++ b/lib/src/jvmTest/kotlin/cash/z/ecc/android/bip39/ReadmeExamplesTest.kt @@ -11,7 +11,6 @@ import io.kotest.matchers.string.shouldContain class ReadmeExamplesTest : ShouldSpec({ val validPhrase = "still champion voice habit trend flight survey between bitter process artefact blind carbon truly provide dizzy crush flush breeze blouse charge solid fish spread" - val validPhraseChars = validPhrase.toCharArray() context("Example: Create 24-word mnemonic phrase") { val mnemonicCode = MnemonicCode(WordCount.COUNT_24) should("result in a valid 24-word phrase") {