Remove digestString from api
This commit is contained in:
parent
e61ffdf978
commit
25adc330bd
@ -115,7 +115,7 @@ Result is returned as a `UByteArray`
|
|||||||
|
|
||||||
##### Updatable instance version
|
##### Updatable instance version
|
||||||
You can create an instance and feed the data by using `update(input : UByteArray)` call. Once all data is supplied,
|
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.
|
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 digest() : UByteArray
|
||||||
|
|
||||||
fun digestString() : String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface StatelessHash : Hash {
|
interface StatelessHash : Hash {
|
||||||
fun digest(inputString: String, key: String? = null, hashLength: Int = MAX_HASH_BYTES): UByteArray
|
|
||||||
|
|
||||||
fun digest(
|
fun digest(
|
||||||
inputMessage: UByteArray = ubyteArrayOf(),
|
inputMessage: UByteArray = ubyteArrayOf(),
|
||||||
|
@ -26,9 +26,6 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
|
|||||||
TODO("not implemented yet")
|
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")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
TODO("not implemented yet")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual object Sha256StatelessDelegated : StatelessSha256 {
|
actual object Sha256StatelessDelegated : StatelessSha256 {
|
||||||
|
@ -20,9 +20,6 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
TODO("not implemented yet")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual object Sha512StatelessDelegated : StatelessSha512 {
|
actual object Sha512StatelessDelegated : StatelessSha512 {
|
||||||
|
@ -21,19 +21,11 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
|
|||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
TODO("not implemented yet")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual object Blake2bDelegatedStateless : Blake2bStateless {
|
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 {
|
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,9 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
TODO("not implemented yet")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual object Sha256StatelessDelegated : StatelessSha256 {
|
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 {
|
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
|
@ -20,15 +20,9 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
TODO("not implemented yet")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual object Sha512StatelessDelegated : StatelessSha512 {
|
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 {
|
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
|
@ -46,9 +46,6 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
|
|||||||
return hashResult
|
return hashResult
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
return digest().toHexString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS")
|
@Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS")
|
||||||
|
@ -21,9 +21,6 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In
|
|||||||
TODO("not implemented yet")
|
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")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
TODO("not implemented yet")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual object Sha512StatelessDelegated : StatelessSha512 {
|
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.Crypto
|
||||||
import com.ionspin.kotlin.crypto.util.testBlocking
|
import com.ionspin.kotlin.crypto.util.testBlocking
|
||||||
|
import com.ionspin.kotlin.crypto.util.toHexString
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
@ -26,7 +27,7 @@ class Blake2bLinuxTest {
|
|||||||
fun testBlake2bUpdateable() = testBlocking {
|
fun testBlake2bUpdateable() = testBlocking {
|
||||||
val blake2b = Crypto.Blake2b.updateable()
|
val blake2b = Crypto.Blake2b.updateable()
|
||||||
blake2b.update("test")
|
blake2b.update("test")
|
||||||
val result = blake2b.digestString()
|
val result = blake2b.digest().toHexString()
|
||||||
println(result)
|
println(result)
|
||||||
assertTrue { result.length > 2 }
|
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 array = inputString.encodeToByteArray().toUByteArray()
|
||||||
val keyBytes = key?.run {
|
val keyBytes = key?.run {
|
||||||
encodeToByteArray().toUByteArray()
|
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() {
|
private fun reset() {
|
||||||
h = iv.copyOf()
|
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(
|
return digest(
|
||||||
inputString.encodeToByteArray().toUByteArray(),
|
inputString.encodeToByteArray().toUByteArray(),
|
||||||
key?.run { encodeToByteArray().toUByteArray()} ?: ubyteArrayOf(),
|
key?.run { encodeToByteArray().toUByteArray()} ?: ubyteArrayOf(),
|
||||||
@ -312,10 +312,6 @@ class Sha256Pure : Sha256 {
|
|||||||
return digest
|
return digest
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
return digest().map { it.toString(16) }.joinToString(separator = "")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun appendToBuffer(array: UByteArray, start: Int) {
|
private fun appendToBuffer(array: UByteArray, start: Int) {
|
||||||
array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size)
|
array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size)
|
||||||
bufferCounter += array.size
|
bufferCounter += array.size
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.ionspin.kotlin.crypto.hash.sha
|
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
|
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 {
|
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
||||||
|
|
||||||
var h = iv.copyOf()
|
var h = iv.copyOf()
|
||||||
@ -389,10 +379,6 @@ class Sha512Pure : Sha512 {
|
|||||||
return digest
|
return digest
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
|
||||||
return digest().map { it.toString(16) }.joinToString(separator = "")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun appendToBuffer(array: UByteArray, start: Int) {
|
private fun appendToBuffer(array: UByteArray, start: Int) {
|
||||||
array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size)
|
array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size)
|
||||||
bufferCounter += array.size
|
bufferCounter += array.size
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.ionspin.kotlin.crypto.hash.blake2b
|
package com.ionspin.kotlin.crypto.hash.blake2b
|
||||||
|
|
||||||
|
import com.ionspin.kotlin.crypto.util.toHexString
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ class Blake2bInstanceTest {
|
|||||||
for (i in 0 until updates) {
|
for (i in 0 until updates) {
|
||||||
blake2b.update(input)
|
blake2b.update(input)
|
||||||
}
|
}
|
||||||
val result = blake2b.digestString()
|
val result = blake2b.digest().toHexString()
|
||||||
assertTrue {
|
assertTrue {
|
||||||
result == expectedResult
|
result == expectedResult
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user