52 lines
952 B
Go
Raw Normal View History

package statuskeycardgo
2021-09-13 13:09:23 +02:00
import "C"
2021-10-15 12:38:06 +03:00
import (
2021-10-18 14:50:56 +03:00
"encoding/binary"
2021-10-15 12:38:06 +03:00
"encoding/hex"
"encoding/json"
2021-10-18 14:50:56 +03:00
ktypes "github.com/status-im/keycard-go/types"
2021-10-15 12:38:06 +03:00
)
2021-09-13 13:09:23 +02:00
func retValue(pairs ...interface{}) *C.char {
obj := make(map[string]interface{})
for i := 0; i < len(pairs)/2; i++ {
key := pairs[i*2]
value := pairs[(i*2)+1]
obj[key.(string)] = value
}
b, err := json.Marshal(obj)
if err != nil {
return C.CString(err.Error())
}
return C.CString(string(b))
}
2021-10-15 12:38:06 +03:00
func tox(bytes []byte) string {
return hex.EncodeToString(bytes)
}
2021-10-18 14:50:56 +03:00
func bytesToInt(s []byte) int {
if len(s) > 4 {
return 0
}
var b [4]byte
copy(b[4-len(s):], s)
return int(binary.BigEndian.Uint32(b[:]))
}
func toAppInfo(r *ktypes.ApplicationInfo) ApplicationInfo {
return ApplicationInfo{
Initialized: r.Initialized,
InstanceUID: r.InstanceUID,
Version: bytesToInt(r.Version),
AvailableSlots: bytesToInt(r.AvailableSlots),
KeyUID: r.KeyUID,
}
}