This commit is contained in:
Ugljesa Jovanovic 2020-07-31 20:08:33 +02:00 committed by Ugljesa Jovanovic
parent c5082a0f47
commit c975bdb248
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
3 changed files with 19 additions and 13 deletions

View File

@ -10,6 +10,10 @@ import com.squareup.kotlinpoet.asTypeName
* on 28-Jul-2020
*/
val packageName = "debug.test"
fun withPackageName(name: String) = ClassName(packageName, name)
class KotlinFileDefinition(
val name: String,
val commonClassList: MutableList<ClassDefinition> = mutableListOf()
@ -117,6 +121,16 @@ fun funcDef(
return function
}
fun funcDef(
name: String,
returnType: GeneralTypeDefinition,
body: FunctionDefinition.() -> Unit
): FunctionDefinition {
val function = FunctionDefinition(name, name, name, name, returnType = returnType)
function.body()
return function
}
object LibSodiumDefinitions {
val testKotlinFile = fileDef("DebugTest") {
@ -128,22 +142,16 @@ object LibSodiumDefinitions {
"crypto_hash_sha256_state"
)
+funcDef(
"init",
"crypto_hash_sha256_init",
"crypto_hash_sha256_init",
"crypto_hash_sha256_init",
TypeDefinition.INT
) {
+ParameterDefinition("state", CustomTypeDefinition(ClassName.bestGuess("Sha256State")))
+ParameterDefinition("state", CustomTypeDefinition((withPackageName("Sha256State"))))
}
}
+classDef("GenericHash") {
+funcDef(
"init",
"crypto_generichash_init",
"crypto_generichash_init",
"crypto_generichash_init",
TypeDefinition.INT
) {

View File

@ -1,17 +1,16 @@
package debug.test
import Sha256State
import kotlin.Int
import kotlin.UByteArray
expect class Sha256State
expect class Hashing {
fun init(state: Sha256State): Int
fun crypto_hash_sha256_init(state: Sha256State): Int
}
expect class GenericHash {
fun init(
fun crypto_generichash_init(
state: UByteArray,
key: UByteArray,
outlen: Int

View File

@ -1,6 +1,5 @@
package debug.test
import Sha256State
import com.goterl.lazycode.lazysodium.SodiumJava
import com.goterl.lazycode.lazysodium.interfaces.Hash
import kotlin.Int
@ -11,14 +10,14 @@ val sodium: SodiumJava = SodiumJava()
actual typealias Sha256State = Hash.State256
actual class Hashing {
actual fun init(state: Sha256State): Int {
actual fun crypto_hash_sha256_init(state: Sha256State): Int {
println("Debug")
return sodium.crypto_hash_sha256_init(state)
}
}
actual class GenericHash {
actual fun init(
actual fun crypto_generichash_init(
state: UByteArray,
key: UByteArray,
outlen: Int