implement delete flow

This commit is contained in:
Michele Balistreri 2021-10-25 08:41:53 +03:00
parent 28232c5ed3
commit 5e24a8571d
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
2 changed files with 64 additions and 2 deletions

46
flow.go
View File

@ -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
}

View File

@ -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)