Playing around with the API, added optins, will remove annotations in next commit

This commit is contained in:
Ugljesa Jovanovic 2020-06-05 20:09:38 +02:00 committed by Ugljesa Jovanovic
parent 9a1073e1c1
commit d901a45b87
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
11 changed files with 60 additions and 16 deletions

View File

@ -16,6 +16,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -259,6 +259,8 @@ kotlin {
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
}
}

View File

@ -8,7 +8,9 @@ import com.ionspin.kotlin.crypto.hash.UpdatableHash
* ugljesa.jovanovic@ionspin.com
* on 24-May-2020
*/
@ExperimentalUnsignedTypes
interface Blake2b : UpdatableHash
@ExperimentalUnsignedTypes
interface Blake2bStatelessInterface : StatelessHash {
@ExperimentalUnsignedTypes
override val MAX_HASH_BYTES: Int

View File

@ -539,6 +539,8 @@ kotlin {
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
}
}

View File

@ -1,5 +1,7 @@
package com.ionspin.kotlin.crypto
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2b
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegated
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bStateless
import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure
import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure
@ -11,13 +13,34 @@ import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure
*/
@ExperimentalUnsignedTypes
typealias Sha256Stateless = Sha256Pure.Companion
@ExperimentalUnsignedTypes
typealias Sha512Stateless = Sha512Pure.Companion
@ExperimentalUnsignedTypes
object Crypto : CryptoProvider {
override suspend fun initialize() {
Initializer.initialize()
}
@ExperimentalUnsignedTypes
@ExperimentalStdlibApi
object Blake2b {
fun updateable() : com.ionspin.kotlin.crypto.hash.blake2b.Blake2b {
return Blake2bDelegated()
}
fun stateless(message : String) : UByteArray {
println("?")
return Blake2bStateless.digest(message)
}
}
}
@ExperimentalUnsignedTypes
object SimpleCrypto {
fun hash(message : String) : UByteArray { return ubyteArrayOf(0U) }
}

View File

@ -30,6 +30,7 @@ import com.ionspin.kotlin.crypto.util.rotateRight
@ExperimentalUnsignedTypes
expect class Blake2bDelegated(key: UByteArray? = null, hashLength: Int = 64) : Blake2b
@ExperimentalUnsignedTypes
expect object Blake2bStateless : Blake2bStatelessInterface

View File

@ -21,9 +21,6 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
}
override fun digest(): UByteArray {
val result = sodium_init()
println("Sodium init")
println(result)
val inputString = "test"
val hashLength = 64
val key : String? = null

View File

@ -344,6 +344,8 @@ kotlin {
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
}
}

View File

@ -269,6 +269,8 @@ kotlin {
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
}
}

View File

@ -1,7 +1,17 @@
package com.ionspin.kotlin.crypto.sample
object Sample {
fun blakehash() {
import com.ionspin.kotlin.crypto.Crypto
import com.ionspin.kotlin.crypto.CryptoProvider
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2b
import com.ionspin.kotlin.crypto.util.toHexString
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
object Sample {
suspend fun runSample() {
Crypto.initialize()
val blake2bUpdateable = Crypto.Blake2b.updateable()
blake2bUpdateable.update("test")
println(blake2bUpdateable.digest().toHexString())
}
}

View File

@ -1,18 +1,21 @@
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegated
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bStateless
import com.ionspin.kotlin.crypto.sample.Sample
import kotlinx.coroutines.runBlocking
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
@ExperimentalTime
@ExperimentalStdlibApi
fun main() {
println("Test")
// Blake
val blake = Blake2bDelegated()
val res = blake.digest()
println("Result of res")
// println(res)
val staticRes = Blake2bStateless.digest("test")
println("Result:")
println(staticRes)
fun main() = runBlocking {
Sample.runSample()
// println("Test")
//// Blake
// val blake = Blake2bDelegated()
// val res = blake.digest()
// println("Result of res")
//// println(res)
// val staticRes = Blake2bStateless.digest("test")
// println("Result:")
// println(staticRes)
}