add keycard pair and generateKey methods
This commit is contained in:
parent
35ba848127
commit
4bafb4bb6b
|
@ -5,9 +5,11 @@ 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, keycardGetStatusApplication
|
||||
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication,
|
||||
keycardUnpair, keycardGenerateKey
|
||||
export keycardStart, keycardStop, keycardSelect, keycardPair,
|
||||
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication
|
||||
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey, keycardGetStatusApplication,
|
||||
keycardUnpair, keycardGenerateKey
|
||||
|
||||
import statusgo/bookmarks as statusgo_bookmarks
|
||||
import mock/bookmarks as mock_bookmarks
|
||||
|
|
|
@ -24,3 +24,10 @@ method keycardExportKey*(self: Backend, derive: bool, makeCurrent: bool, onlyPub
|
|||
|
||||
method keycardGetStatusApplication*(self: Backend): KeycardStatus =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method keycardUnpair*(self: Backend, index: int) =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method keycardGenerateKey*(self: Backend): string =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
|
|
@ -20,3 +20,8 @@ method keycardExportKey*(self: MockBackend, derive: bool, makeCurrent: bool, onl
|
|||
|
||||
method keycardGetStatusApplication*(self: MockBackend): KeycardStatus =
|
||||
result = KeycardStatus()
|
||||
|
||||
method keycardUnpair*(self: MockBackend, index: int) = discard
|
||||
|
||||
method keycardGenerateKey*(self: MockBackend): string =
|
||||
result = "0x00"
|
||||
|
|
|
@ -91,3 +91,19 @@ method keycardGetStatusApplication*(self: StatusGoBackend): KeycardStatus =
|
|||
pukRetryCount: parsedResponse["status"]["pukRetryCount"].getInt(),
|
||||
keyInitialized: parsedResponse["status"]["keyInitialized"].getBool()
|
||||
)
|
||||
|
||||
method keycardUnpair*(self: StatusGoBackend, index: int) =
|
||||
let inputJSON = %* {
|
||||
"index": index,
|
||||
}
|
||||
let response = keycard_go.unpair($inputJSON)
|
||||
let parsedResponse = parseJson(response)
|
||||
if not parsedResponse{"ok"}.getBool():
|
||||
raise KeycardUnpairException(error: parsedResponse{"error"}.getStr())
|
||||
|
||||
method keycardGenerateKey*(self: StatusGoBackend): string =
|
||||
let response = keycard_go.generateKey()
|
||||
let parsedResponse = parseJson(response)
|
||||
if not parsedResponse{"ok"}.getBool():
|
||||
raise KeycardGenerateKeyException(error: parsedResponse{"error"}.getStr())
|
||||
result = parsedResponse["keyUID"].getStr()
|
||||
|
|
|
@ -58,3 +58,15 @@ proc getStatusApplication*(self: KeycardModel): KeycardStatus =
|
|||
result = self.backend.keycardGetStatusApplication()
|
||||
except:
|
||||
raise
|
||||
|
||||
proc unpair*(self: KeycardModel, index: int) =
|
||||
try:
|
||||
self.backend.keycardUnpair(index)
|
||||
except:
|
||||
raise
|
||||
|
||||
proc generateKey*(self: KeycardModel): string =
|
||||
try:
|
||||
result = self.backend.keycardGenerateKey()
|
||||
except:
|
||||
raise
|
||||
|
|
|
@ -13,6 +13,10 @@ type KeycardOpenSecureChannelException* = ref object of KeycardException
|
|||
|
||||
type KeycardGetStatusException* = ref object of KeycardException
|
||||
|
||||
type KeycardUnpairException* = ref object of KeycardException
|
||||
|
||||
type KeycardGenerateKeyException* = ref object of KeycardException
|
||||
|
||||
type KeycardVerifyPINException* = ref object of KeycardException
|
||||
pinRetry*: int64
|
||||
|
||||
|
|
Loading…
Reference in New Issue