From 5e24a8571d74a5300922b12706f3e50088532e16 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 25 Oct 2021 08:41:53 +0300 Subject: [PATCH] implement delete flow --- flow.go | 46 ++++++++++++++++++++++++++++++++++++++++++++-- flow_commands.go | 20 ++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/flow.go b/flow.go index bc2e357..1ec469d 100644 --- a/flow.go +++ b/flow.go @@ -382,9 +382,51 @@ func (f *KeycardFlow) unpairThisFlow(kc *keycardContext) (FlowStatus, error) { } func (f *KeycardFlow) unpairOthersFlow(kc *keycardContext) (FlowStatus, error) { - return nil, errors.New("not implemented yet") + err := f.openSCAndAuthenticate(kc, true) + + if err != nil { + return nil, err + } + + for i := 0; i < maxFreeSlots; i++ { + if i == kc.cmdSet.PairingInfo.Index { + continue + } + + err = f.unpair(kc, i) + + if err != nil { + return nil, err + } + + f.cardInfo.freeSlots++ + } + + return FlowStatus{InstanceUID: f.cardInfo.instanceUID, FreeSlots: f.cardInfo.freeSlots}, nil } func (f *KeycardFlow) deleteUnpairFlow(kc *keycardContext) (FlowStatus, error) { - return nil, errors.New("not implemented yet") + err := f.openSCAndAuthenticate(kc, true) + + if err != nil { + return nil, err + } + + err = f.removeKey(kc) + + if err != nil { + return nil, err + } + + f.cardInfo.keyUID = "" + + err = f.unpairCurrent(kc) + + if err != nil { + return nil, err + } + + f.cardInfo.freeSlots++ + + return FlowStatus{InstanceUID: f.cardInfo.instanceUID, KeyUID: f.cardInfo.keyUID, FreeSlots: f.cardInfo.freeSlots}, nil } diff --git a/flow_commands.go b/flow_commands.go index 4e42854..c7233ec 100644 --- a/flow_commands.go +++ b/flow_commands.go @@ -250,6 +250,26 @@ func (f *KeycardFlow) unpairCurrent(kc *keycardContext) error { return err } +func (f *KeycardFlow) unpair(kc *keycardContext, idx int) error { + err := kc.unpair(uint8(idx)) + + if isSCardError(err) { + return restartErr() + } + + return err +} + +func (f *KeycardFlow) removeKey(kc *keycardContext) error { + err := kc.removeKey() + + if isSCardError(err) { + return restartErr() + } + + return err +} + func (f *KeycardFlow) exportKey(kc *keycardContext, path string, onlyPublic bool) (*KeyPair, error) { keyPair, err := kc.exportKey(true, false, onlyPublic, path)