diff --git a/README.md b/README.md index 39bd2fd..727a258 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Result is returned as a `UByteArray` ##### Updatable instance version You can create an instance and feed the data by using `update(input : UByteArray)` call. Once all data is supplied, -you should call `digest()` or `digestString()` convenience method that converts the `UByteArray` into hexadecimal string. +you should call `digest()`. If you want to use Blake2b with a key, you should supply it when creating the `Blake2b` instance. diff --git a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt index 0b2dd6e..cbecaf3 100644 --- a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt +++ b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt @@ -34,12 +34,10 @@ interface UpdatableHash : Hash { fun digest() : UByteArray - fun digestString() : String } interface StatelessHash : Hash { - fun digest(inputString: String, key: String? = null, hashLength: Int = MAX_HASH_BYTES): UByteArray fun digest( inputMessage: UByteArray = ubyteArrayOf(), diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt index 766fa14..3933813 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt @@ -26,9 +26,6 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I TODO("not implemented yet") } - override fun digestString(): String { - TODO("not implemented yet") - } } diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt index 2e738b4..7a04842 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt @@ -20,9 +20,6 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun digestString(): String { - TODO("not implemented yet") - } } actual object Sha256StatelessDelegated : StatelessSha256 { diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index 8bb93f0..f107630 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -20,9 +20,6 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun digestString(): String { - TODO("not implemented yet") - } } actual object Sha512StatelessDelegated : StatelessSha512 { diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt index 6474243..b787229 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt @@ -21,19 +21,11 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I TODO("not implemented yet") } - override fun digestString(): String { - TODO("not implemented yet") - } } actual object Blake2bDelegatedStateless : Blake2bStateless { - - override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { - TODO("not implemented yet") - } - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { TODO("not implemented yet") } diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt index 716a1da..81e110f 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt @@ -22,15 +22,9 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun digestString(): String { - TODO("not implemented yet") - } } actual object Sha256StatelessDelegated : StatelessSha256 { - override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { - TODO("not implemented yet") - } override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { TODO("not implemented yet") diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index 8bb93f0..fa313ca 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -20,15 +20,9 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun digestString(): String { - TODO("not implemented yet") - } } actual object Sha512StatelessDelegated : StatelessSha512 { - override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { - TODO("not implemented yet") - } override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { TODO("not implemented yet") diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt index ee90cf5..4ca7bbb 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt @@ -46,9 +46,6 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I return hashResult } - override fun digestString(): String { - return digest().toHexString() - } } @Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS") diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt index cfa336b..fe4868a 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt @@ -21,9 +21,6 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun digestString(): String { - TODO("not implemented yet") - } diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index 8bb93f0..f107630 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -20,9 +20,6 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun digestString(): String { - TODO("not implemented yet") - } } actual object Sha512StatelessDelegated : StatelessSha512 { diff --git a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt index 15882dc..172b383 100644 --- a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt +++ b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt @@ -8,6 +8,7 @@ package com.ionspin.kotlin.crypto.hash.blake2b import com.ionspin.kotlin.crypto.Crypto import com.ionspin.kotlin.crypto.util.testBlocking +import com.ionspin.kotlin.crypto.util.toHexString import kotlinx.coroutines.runBlocking import kotlin.test.Test @@ -26,7 +27,7 @@ class Blake2bLinuxTest { fun testBlake2bUpdateable() = testBlocking { val blake2b = Crypto.Blake2b.updateable() blake2b.update("test") - val result = blake2b.digestString() + val result = blake2b.digest().toHexString() println(result) assertTrue { result.length > 2 } } diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt index 69ec520..dd8e75c 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt @@ -145,7 +145,7 @@ class Blake2bPure(val key: UByteArray? = null, val hashLength: Int = 64) : Blake } - override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { + fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { val array = inputString.encodeToByteArray().toUByteArray() val keyBytes = key?.run { encodeToByteArray().toUByteArray() @@ -333,9 +333,6 @@ class Blake2bPure(val key: UByteArray? = null, val hashLength: Int = 64) : Blake } - override fun digestString(): String { - return digest().map { it.toString(16) }.joinToString(separator = "") - } private fun reset() { h = iv.copyOf() diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt index 37b096b..8e8dd3a 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt @@ -64,7 +64,7 @@ class Sha256Pure : Sha256 { ) - override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { + fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { return digest( inputString.encodeToByteArray().toUByteArray(), key?.run { encodeToByteArray().toUByteArray()} ?: ubyteArrayOf(), @@ -312,10 +312,6 @@ class Sha256Pure : Sha256 { return digest } - override fun digestString(): String { - return digest().map { it.toString(16) }.joinToString(separator = "") - } - private fun appendToBuffer(array: UByteArray, start: Int) { array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size) bufferCounter += array.size diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt index 0e16e1a..170609c 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt @@ -16,8 +16,6 @@ package com.ionspin.kotlin.crypto.hash.sha -import com.ionspin.kotlin.crypto.hash.StatelessHash -import com.ionspin.kotlin.crypto.hash.UpdatableHash import com.ionspin.kotlin.crypto.util.rotateRight /** @@ -134,14 +132,6 @@ class Sha512Pure : Sha512 { ) - override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { - return digest( - inputString.encodeToByteArray().toUByteArray(), - key?.run { encodeToByteArray().toUByteArray() } ?: ubyteArrayOf(), - hashLength = hashLength - ) - } - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { var h = iv.copyOf() @@ -389,10 +379,6 @@ class Sha512Pure : Sha512 { return digest } - override fun digestString(): String { - return digest().map { it.toString(16) }.joinToString(separator = "") - } - private fun appendToBuffer(array: UByteArray, start: Int) { array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size) bufferCounter += array.size diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bInstanceTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bInstanceTest.kt index 308b0cc..9e50e69 100644 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bInstanceTest.kt +++ b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bInstanceTest.kt @@ -16,6 +16,7 @@ package com.ionspin.kotlin.crypto.hash.blake2b +import com.ionspin.kotlin.crypto.util.toHexString import kotlin.test.Test import kotlin.test.assertTrue @@ -64,7 +65,7 @@ class Blake2bInstanceTest { for (i in 0 until updates) { blake2b.update(input) } - val result = blake2b.digestString() + val result = blake2b.digest().toHexString() assertTrue { result == expectedResult }