Api cleanup
This commit is contained in:
1 parent
25adc330bd
commit
f03e94cf5e
15 files changed
+91
-83
No files matched your search
@@ -17,6 +17,7 @@
|
||||
package com.ionspin.kotlin.crypto
|
||||
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bPure
|
||||
import com.ionspin.kotlin.crypto.hash.encodeToUByteArray
|
||||
import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure
|
||||
import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure
|
||||
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Pure
|
||||
@@ -41,7 +42,7 @@ class ReadmeTest {
|
||||
@Test
|
||||
fun blake2bObjectExample() {
|
||||
val input = "abc"
|
||||
val result = Blake2bPure.digest(input)
|
||||
val result = Blake2bPure.digest(input.encodeToUByteArray())
|
||||
//@formatter:off
|
||||
val expectedResult = ubyteArrayOf(
|
||||
0xBAU,0x80U,0xA5U,0x3FU,0x98U,0x1CU,0x4DU,0x0DU,0x6AU,0x27U,0x97U,0xB6U,0x9FU,0x12U,0xF6U,0xE9U,
|
||||
@@ -80,7 +81,7 @@ class ReadmeTest {
|
||||
@Test
|
||||
fun sha256Example() {
|
||||
val input = "abc"
|
||||
val result = Sha256Pure.digest(inputString = input)
|
||||
val result = Sha256Pure.digest(input.encodeToUByteArray())
|
||||
val expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult.chunked(2).map { it.toUByte(16) }.toUByteArray())
|
||||
@@ -158,7 +159,7 @@ class ReadmeTest {
|
||||
|
||||
@Test
|
||||
fun debugTest() {
|
||||
val result = Blake2bStateless.digest("test")
|
||||
val result = Blake2bStateless.digest("test".encodeToUByteArray())
|
||||
println(result.toHexString())
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.ionspin.kotlin.crypto.hash.blake2b
|
||||
|
||||
import com.ionspin.kotlin.crypto.hash.encodeToUByteArray
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertTrue
|
||||
@@ -46,7 +47,7 @@ class Blake2BTest {
|
||||
"1234567890" +
|
||||
"1234567890"
|
||||
|
||||
val result = Blake2bPure.digest(test)
|
||||
val result = Blake2bPure.digest(test.encodeToUByteArray())
|
||||
//Generated with b2sum 8.31
|
||||
val expectedResult = ubyteArrayOf(
|
||||
//@formatter:off
|
||||
@@ -77,7 +78,7 @@ class Blake2BTest {
|
||||
"1234567890"
|
||||
|
||||
|
||||
val result = Blake2bPure.digest(test)
|
||||
val result = Blake2bPure.digest(test.encodeToUByteArray())
|
||||
val expectedResultString = "800bb78cd4da18995c8074713bb674" +
|
||||
"3cd94b2b6490a693fe4000ed00833b88b7b474d94af9cfed246b1b" +
|
||||
"4ce1935a76154d7ea7c410493557741d18ec3a08da75"
|
||||
@@ -93,7 +94,7 @@ class Blake2BTest {
|
||||
fun testDigest() {
|
||||
val test = "111111111122222222223333333333333"
|
||||
|
||||
val result = Blake2bPure.digest(test)
|
||||
val result = Blake2bPure.digest(test.encodeToUByteArray())
|
||||
//Generated with b2sum 8.31
|
||||
val expectedResult = ubyteArrayOf(
|
||||
//@formatter:off
|
||||
@@ -115,7 +116,7 @@ class Blake2BTest {
|
||||
val test = "abc"
|
||||
val key = "key"
|
||||
|
||||
val result = Blake2bPure.digest(test, key)
|
||||
val result = Blake2bPure.digest(test.encodeToUByteArray(), key.encodeToUByteArray())
|
||||
|
||||
assertTrue {
|
||||
result.isNotEmpty()
|
||||
@@ -134,7 +135,7 @@ class Blake2BTest {
|
||||
fun testDigestFromRfc() {
|
||||
val test = "abc"
|
||||
|
||||
val result = Blake2bPure.digest(test)
|
||||
val result = Blake2bPure.digest(test.encodeToUByteArray())
|
||||
//@formatter:off
|
||||
val expectedResult = ubyteArrayOf(
|
||||
|
||||
@@ -286,7 +287,7 @@ class Blake2BTest {
|
||||
fun testInvalidHashLength() {
|
||||
val test = "1234567890"
|
||||
assertFailsWith(RuntimeException::class) {
|
||||
val result = Blake2bPure.digest(inputString = test, hashLength = 65)
|
||||
val result = Blake2bPure.digest(test.encodeToUByteArray(), hashLength = 65)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -58,8 +58,8 @@ class Blake2bInstanceTest {
|
||||
fun testDigestToString() {
|
||||
val updates = 14
|
||||
val input = "1234567890"
|
||||
val expectedResult = "2F49AEB613E34E924E175A6AF2FAAD7BC78235F9C5E461C68FD5B47E".toLowerCase() +
|
||||
"E8E2FD2FB4C07D7E4A72404612D92899AF8A328F3B614ED77244B481151D40B11E32A4".toLowerCase()
|
||||
val expectedResult = "2F49AEB613E34E924E175A6AF2FAAD7BC78235F9C5E461C68FD5B407E".toLowerCase() +
|
||||
"E8E2F0D2FB4C07D7E4A72404612D92899AF8A328F3B614ED77244B481151D40B11E32A4".toLowerCase()
|
||||
|
||||
val blake2b = Blake2bPure()
|
||||
for (i in 0 until updates) {
|
||||
|
||||
+4
-3
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.ionspin.kotlin.crypto.hash.sha
|
||||
|
||||
import com.ionspin.kotlin.crypto.hash.encodeToUByteArray
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@@ -31,7 +32,7 @@ class Sha256Test {
|
||||
@Test
|
||||
fun testWellKnownValue() {
|
||||
|
||||
val result = Sha256Pure.digest(inputString = "abc")
|
||||
val result = Sha256Pure.digest("abc".encodeToUByteArray())
|
||||
val expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
assertTrue {
|
||||
result.contentEquals(expectedResult.chunked(2).map { it.toUByte(16) }.toUByteArray())
|
||||
@@ -44,7 +45,7 @@ class Sha256Test {
|
||||
@Test
|
||||
fun testWellKnownDoubleBlock() {
|
||||
|
||||
val resultDoubleBlock = Sha256Pure.digest(inputString = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
|
||||
val resultDoubleBlock = Sha256Pure.digest("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".encodeToUByteArray())
|
||||
val expectedResultForDoubleBlock = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
|
||||
assertTrue {
|
||||
resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.chunked(2).map { it.toUByte(16) }.toUByteArray())
|
||||
@@ -56,7 +57,7 @@ class Sha256Test {
|
||||
fun testWellKnown3() { //It's good that I'm consistent with names.
|
||||
|
||||
|
||||
val resultDoubleBlock = Sha256Pure.digest(inputString = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")
|
||||
val resultDoubleBlock = Sha256Pure.digest("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu".encodeToUByteArray())
|
||||
println(resultDoubleBlock.map{ it.toString(16)}.joinToString(separator = ""))
|
||||
val expectedResultForDoubleBlock = "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1"
|
||||
assertTrue {
|
||||
|
||||
Reference in new issue
Block a user