better error handling in GetMetadata

This commit is contained in:
Michele Balistreri 2022-08-09 08:50:39 +02:00
parent 2cfb537259
commit b6b29bc497
2 changed files with 15 additions and 4 deletions

View File

@ -2,8 +2,10 @@ package statuskeycardgo
import (
"errors"
"io"
"strings"
"github.com/status-im/keycard-go/apdu"
"github.com/status-im/keycard-go/derivationpath"
ktypes "github.com/status-im/keycard-go/types"
)
@ -298,13 +300,21 @@ func (f *KeycardFlow) removeKey(kc *keycardContext) error {
func (f *KeycardFlow) getMetadata(kc *keycardContext) (*Metadata, error) {
m, err := kc.getMetadata()
if isSCardError(err) {
if err == nil {
return toMetadata(m), nil
} else if isSCardError(err) {
return nil, restartErr()
} else if err != nil {
} else if serr, ok := err.(*apdu.ErrBadResponse); ok {
if serr.Sw == 0x6d00 {
return nil, errors.New(ErrorNoKeys)
} else {
return nil, err
}
} else if err == io.EOF {
return nil, errors.New(ErrorNoData)
} else {
return nil, err
}
return toMetadata(m), nil
}
func (f *KeycardFlow) storeMetadata(kc *keycardContext) error {

View File

@ -84,6 +84,7 @@ const (
ErrorChanging = "changing-credentials"
ErrorLoading = "loading-keys"
ErrorStoreMeta = "storing-metadata"
ErrorNoData = "no-data"
)
const (