mirror of
https://github.com/status-im/status-keycard-go.git
synced 2025-01-19 02:42:50 +00:00
better error handling in GetMetadata
This commit is contained in:
parent
2cfb537259
commit
b6b29bc497
@ -2,8 +2,10 @@ package statuskeycardgo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/status-im/keycard-go/apdu"
|
||||||
"github.com/status-im/keycard-go/derivationpath"
|
"github.com/status-im/keycard-go/derivationpath"
|
||||||
ktypes "github.com/status-im/keycard-go/types"
|
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) {
|
func (f *KeycardFlow) getMetadata(kc *keycardContext) (*Metadata, error) {
|
||||||
m, err := kc.getMetadata()
|
m, err := kc.getMetadata()
|
||||||
|
|
||||||
if isSCardError(err) {
|
if err == nil {
|
||||||
|
return toMetadata(m), nil
|
||||||
|
} else if isSCardError(err) {
|
||||||
return nil, restartErr()
|
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 nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return toMetadata(m), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *KeycardFlow) storeMetadata(kc *keycardContext) error {
|
func (f *KeycardFlow) storeMetadata(kc *keycardContext) error {
|
||||||
|
@ -84,6 +84,7 @@ const (
|
|||||||
ErrorChanging = "changing-credentials"
|
ErrorChanging = "changing-credentials"
|
||||||
ErrorLoading = "loading-keys"
|
ErrorLoading = "loading-keys"
|
||||||
ErrorStoreMeta = "storing-metadata"
|
ErrorStoreMeta = "storing-metadata"
|
||||||
|
ErrorNoData = "no-data"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user