Remove digestString from api

This commit is contained in:
Ugljesa Jovanovic 2020-06-07 00:05:14 +02:00 committed by Ugljesa Jovanovic
parent e61ffdf978
commit 25adc330bd
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
16 changed files with 7 additions and 66 deletions

View File

@ -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.

View File

@ -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(),

View File

@ -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")
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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")
}

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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")
}

View File

@ -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 {

View File

@ -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 }
}

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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
}