status-lib/status/keycard.nim

73 lines
1.6 KiB
Nim
Raw Permalink Normal View History

Keycard initial integration (#63) * add nim-keycard-go to makefile * fix keycard-go build * add keycard.nim * remove test make task * remove debug line from makefile * fix import keycard_go * add keycard-go to .PHONY * add keycard start/stop/select methods * use https url for submodule * add KeycardApplication info and return it from select * update nim-keycard-go version * fix select return type * actually return the result * update nim-keycard-go * add keycard methods to backend * add base/mock keycard backends * imports * export keycard methods in backend * update start/stop keycard implementation * add KeycardStarted signal * fix keycard started signal * rename to KeycardConnected signal * fix keycard signal renamed * add keycardgo in makefile tasks * add back build/.gitignore * fix .gitignore * fix .gitignore * Makefile: export keycard vars * add keycard lib to nimble file * use spaces instead of tabs in non-recipe sections of Makefile * use install_name_tool on libkeycard on macOS * in GHA ubuntu environment install libpcsclite-dev with apt at start of workflow * add Keycard exceptions * remove useless test * remove useless return * move keycard types to /types * reraise exception from status/keycard.nim * remove unused import * add keycard commands: opensecure channel, pair, verify pin, export key * fix last keycard commands * add exportKey params * update nim-keycard-go Co-authored-by: Michele Balistreri <michele@bitgamma.com> Co-authored-by: Michael Bradley, Jr <michaelsbradleyjr@gmail.com>
2021-10-04 21:21:07 +00:00
import keycard_go
import ../types/keycard
import ../backends/backend
include utils/json_utils
type KeycardModel* = ref object
backend*: Backend
proc newKeycardModel*(backend: Backend): KeycardModel =
result = KeycardModel()
result.backend = backend
proc start*(self: KeycardModel) =
try:
self.backend.keycardStart()
except:
raise
proc stop*(self: KeycardModel) =
try:
self.backend.keycardStop()
except:
raise
proc select*(self: KeycardModel): KeycardApplicationInfo =
try:
result = self.backend.keycardSelect()
except:
raise
proc pair*(self: KeycardModel, pairingPassword: string): KeycardPairingInfo =
try:
result = self.backend.keycardPair(pairingPassword)
except:
raise
proc openSecureChannel*(self: KeycardModel, index: int, key: string) =
try:
self.backend.keycardOpenSecureChannel(index, key)
except:
raise
proc verifyPin*(self: KeycardModel, pin: string) =
try:
self.backend.keycardVerifyPin(pin)
except:
raise
2021-10-06 08:59:16 +00:00
proc exportKey*(self: KeycardModel, derive: bool, makeCurrent: bool, onlyPublic: bool, path: string): KeycardExportedKey =
Keycard initial integration (#63) * add nim-keycard-go to makefile * fix keycard-go build * add keycard.nim * remove test make task * remove debug line from makefile * fix import keycard_go * add keycard-go to .PHONY * add keycard start/stop/select methods * use https url for submodule * add KeycardApplication info and return it from select * update nim-keycard-go version * fix select return type * actually return the result * update nim-keycard-go * add keycard methods to backend * add base/mock keycard backends * imports * export keycard methods in backend * update start/stop keycard implementation * add KeycardStarted signal * fix keycard started signal * rename to KeycardConnected signal * fix keycard signal renamed * add keycardgo in makefile tasks * add back build/.gitignore * fix .gitignore * fix .gitignore * Makefile: export keycard vars * add keycard lib to nimble file * use spaces instead of tabs in non-recipe sections of Makefile * use install_name_tool on libkeycard on macOS * in GHA ubuntu environment install libpcsclite-dev with apt at start of workflow * add Keycard exceptions * remove useless test * remove useless return * move keycard types to /types * reraise exception from status/keycard.nim * remove unused import * add keycard commands: opensecure channel, pair, verify pin, export key * fix last keycard commands * add exportKey params * update nim-keycard-go Co-authored-by: Michele Balistreri <michele@bitgamma.com> Co-authored-by: Michael Bradley, Jr <michaelsbradleyjr@gmail.com>
2021-10-04 21:21:07 +00:00
try:
result = self.backend.keycardExportKey(derive, makeCurrent, onlyPublic, path)
except:
raise
2021-10-05 09:35:07 +00:00
proc getStatusApplication*(self: KeycardModel): KeycardStatus =
try:
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