add keycardGetStatusApplication

This commit is contained in:
Andrea Franz 2021-10-05 11:35:07 +02:00
parent e3389d6bfe
commit 13463c8106
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
7 changed files with 48 additions and 2 deletions

View File

@ -5,9 +5,9 @@ from base/bookmarks as bookmarks_methods import storeBookmark, updateBookmark, g
export storeBookmark, updateBookmark, getBookmarks, deleteBookmark
from base/keycard as keycard_methods import keycardStart, keycardStop, keycardSelect, keycardPair,
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication
export keycardStart, keycardStop, keycardSelect, keycardPair,
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication
import statusgo/bookmarks as statusgo_bookmarks
import mock/bookmarks as mock_bookmarks

View File

@ -21,3 +21,6 @@ method keycardVerifyPin*(self: Backend, pin: string) =
method keycardExportKey*(self: Backend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string =
raise newException(ValueError, "No implementation available")
method keycardGetStatusApplication*(self: Backend): KeycardStatus =
raise newException(ValueError, "No implementation available")

View File

@ -17,3 +17,6 @@ method keycardVerifyPin*(self: MockBackend, pin: string) = discard
method keycardExportKey*(self: MockBackend, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): string =
result = "0x00"
method keycardGetStatusApplication*(self: MockBackend): KeycardStatus =
result = KeycardStatus()

View File

@ -80,3 +80,14 @@ method keycardExportKey*(self: StatusGoBackend, derive: bool, makeCurrent: bool,
raise KeycardSelectException(error: parsedResponse{"error"}.getStr())
result = parsedResponse["key"].getStr()
method keycardGetStatusApplication*(self: StatusGoBackend): KeycardStatus =
let response = keycard_go.getStatusApplication()
let parsedResponse = parseJson(response)
if not parsedResponse{"ok"}.getBool():
raise KeycardGetStatusException(error: parsedResponse{"error"}.getStr())
result = KeycardStatus(
pinRetryCount: parsedResponse["status"]["pinRetryCount"].getInt(),
pukRetryCount: parsedResponse["status"]["pukRetryCount"].getInt(),
keyInitialized: parsedResponse["status"]["keyInitialized"].getBool()
)

View File

@ -52,3 +52,9 @@ proc exportKey*(self: KeycardModel, derive: bool, makeCurrent: bool, onlyPublic:
result = self.backend.keycardExportKey(derive, makeCurrent, onlyPublic, path)
except:
raise
proc getStatusApplication*(self: KeycardModel): KeycardStatus =
try:
result = self.backend.keycardGetStatusApplication()
except:
raise

View File

@ -49,3 +49,18 @@ suite "#Keycard":
except KeycardException as ex:
echo "keycard exception"
echo repr(ex)
test "getStatusApplication":
try:
statuslib_instance.keycard.start()
discard statuslib_instance.keycard.select()
statuslib_instance.keycard.openSecureChannel(0, "000000")
let info = statuslib_instance.keycard.getStatusApplication()
# echo repr(info)
statuslib_instance.keycard.stop()
except KeycardGetStatusException as ex:
echo "keycard get status exception"
echo repr(ex)
except KeycardException as ex:
echo "keycard exception"
echo repr(ex)

View File

@ -11,6 +11,8 @@ type KeycardPairException* = ref object of KeycardException
type KeycardOpenSecureChannelException* = ref object of KeycardException
type KeycardGetStatusException* = ref object of KeycardException
type KeycardVerifyPINException* = ref object of KeycardException
pinRetry*: int64
@ -29,3 +31,9 @@ type KeycardApplicationInfo* = ref object
type KeycardPairingInfo* = ref object
key*: string
index*: int64
type KeycardStatus* = ref object
pinRetryCount*: int64
pukRetryCount *: int64
keyInitialized*: bool
path*: string