70 lines
1.2 KiB
Go
Raw Normal View History

2021-10-15 10:35:09 +02:00
package main
// #cgo LDFLAGS: -shared
import "C"
import (
2021-10-29 13:33:26 +03:00
"encoding/json"
2021-10-15 10:35:09 +02:00
2021-10-29 13:33:26 +03:00
skg "github.com/status-im/status-keycard-go"
2021-10-15 10:35:09 +02:00
)
func main() {}
2021-10-29 13:33:26 +03:00
var globalFlow *skg.KeycardFlow
func retErr(err error) *C.char {
if err == nil {
return C.CString("ok")
} else {
return C.CString(err.Error())
}
}
func jsonToParams(jsonParams *C.char) (skg.FlowParams, error) {
var params skg.FlowParams
if err := json.Unmarshal([]byte(C.GoString(jsonParams)), &params); err != nil {
return nil, err
}
return params, nil
}
//export KeycardInitFlow
func KeycardInitFlow(storageDir *C.char) *C.char {
var err error
globalFlow, err = skg.NewFlow(C.GoString(storageDir))
return retErr(err)
}
//export KeycardStartFlow
func KeycardStartFlow(flowType C.int, jsonParams *C.char) *C.char {
params, err := jsonToParams(jsonParams)
if err != nil {
return retErr(err)
}
err = globalFlow.Start(skg.FlowType(flowType), params)
return retErr(err)
}
//export KeycardResumeFlow
func KeycardResumeFlow(jsonParams *C.char) *C.char {
params, err := jsonToParams(jsonParams)
if err != nil {
return retErr(err)
}
err = globalFlow.Resume(params)
return retErr(err)
}
//export KeycardCancelFlow
func KeycardCancelFlow() *C.char {
err := globalFlow.Cancel()
return retErr(err)
2021-10-15 10:35:09 +02:00
}