Remove digestString from api

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-06-07 00:05:14 +02:00
1 parent e61ffdf978
commit 25adc330bd
16 files changed
+7 -66

No files matched your search

+1 -1
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.
@@ -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(),
@@ -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")
}
}
@@ -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 {
@@ -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 {
@@ -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")
}
@@ -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")
@@ -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")
@@ -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")
@@ -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")
}
@@ -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 {
@@ -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 }
}
@@ -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()
@@ -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
@@ -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
@@ -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
}