parse int from KeycardApplicationInfo

This commit is contained in:
Andrea Franz 2021-10-04 10:48:02 +02:00
parent c8d0142a16
commit 622a50e950
3 changed files with 15 additions and 5 deletions

15
main.go
View File

@ -3,6 +3,7 @@ package main
// #cgo LDFLAGS: -shared
import "C"
import (
"encoding/binary"
"encoding/json"
"fmt"
"time"
@ -103,8 +104,8 @@ func Select() *C.char {
Initialized: info.Initialized,
InstanceUID: info.InstanceUID,
SecureChannelPublicKey: info.SecureChannelPublicKey,
Version: info.Version,
AvailableSlots: info.AvailableSlots,
Version: bytesToInt(info.Version),
AvailableSlots: bytesToInt(info.AvailableSlots),
KeyUID: info.KeyUID,
Capabilities: Capability(info.Capabilities),
})
@ -411,3 +412,13 @@ func ChangePairingPassword(jsonParams *C.char) *C.char {
func SetSignalEventCallback(cb unsafe.Pointer) {
signal.SetSignalEventCallback(cb)
}
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[:]))
}

View File

@ -1,7 +1,6 @@
package signal
const (
// EventSignRequestAdded is triggered when send transaction request is queued
EventKeycardConnected = "keycard.connected"
)

View File

@ -93,8 +93,8 @@ type ApplicationInfo struct {
Initialized bool `json:"initialized"`
InstanceUID hexString `json:"instanceUID"`
SecureChannelPublicKey hexString `json:"secureChannelPublicKey"`
Version hexString `json:"version"`
AvailableSlots hexString `json:"availableSlots"`
Version int `json:"version"`
AvailableSlots int `json:"availableSlots"`
// KeyUID is the sha256 of of the master public key on the card.
// It's empty if the card doesn't contain any key.
KeyUID hexString `json:"keyUID"`