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 distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -259,6 +259,8 @@ kotlin {
all { all {
languageSettings.enableLanguageFeature("InlineClasses") 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 * ugljesa.jovanovic@ionspin.com
* on 24-May-2020 * on 24-May-2020
*/ */
@ExperimentalUnsignedTypes
interface Blake2b : UpdatableHash interface Blake2b : UpdatableHash
@ExperimentalUnsignedTypes
interface Blake2bStatelessInterface : StatelessHash { interface Blake2bStatelessInterface : StatelessHash {
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
override val MAX_HASH_BYTES: Int override val MAX_HASH_BYTES: Int

View File

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

View File

@ -1,5 +1,7 @@
package com.ionspin.kotlin.crypto 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.blake2b.Blake2bStateless
import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure
import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure 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 typealias Sha256Stateless = Sha256Pure.Companion
@ExperimentalUnsignedTypes
typealias Sha512Stateless = Sha512Pure.Companion typealias Sha512Stateless = Sha512Pure.Companion
@ExperimentalUnsignedTypes
object Crypto : CryptoProvider { object Crypto : CryptoProvider {
override suspend fun initialize() { override suspend fun initialize() {
Initializer.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 @ExperimentalUnsignedTypes
expect class Blake2bDelegated(key: UByteArray? = null, hashLength: Int = 64) : Blake2b expect class Blake2bDelegated(key: UByteArray? = null, hashLength: Int = 64) : Blake2b
@ExperimentalUnsignedTypes
expect object Blake2bStateless : Blake2bStatelessInterface expect object Blake2bStateless : Blake2bStatelessInterface

View File

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

View File

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

View File

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

View File

@ -1,7 +1,17 @@
package com.ionspin.kotlin.crypto.sample package com.ionspin.kotlin.crypto.sample
object Sample { import com.ionspin.kotlin.crypto.Crypto
fun blakehash() { 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.Blake2bDelegated
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bStateless 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.ExperimentalTime
import kotlin.time.measureTime import kotlin.time.measureTime
@ExperimentalTime @ExperimentalTime
@ExperimentalStdlibApi @ExperimentalStdlibApi
fun main() { fun main() = runBlocking {
println("Test") Sample.runSample()
// Blake // println("Test")
val blake = Blake2bDelegated() //// Blake
val res = blake.digest() // val blake = Blake2bDelegated()
println("Result of res") // val res = blake.digest()
// println(res) // println("Result of res")
val staticRes = Blake2bStateless.digest("test") //// println(res)
println("Result:") // val staticRes = Blake2bStateless.digest("test")
println(staticRes) // println("Result:")
// println(staticRes)
} }