mirror of
https://github.com/status-im/status-keycard-go.git
synced 2025-03-03 07:20:56 +00:00
distinguish pcsc errors
This commit is contained in:
parent
bba2be219a
commit
5bfafd14e6
35
error.go
35
error.go
@ -1,15 +1,24 @@
|
|||||||
package statuskeycardgo
|
package statuskeycardgo
|
||||||
|
|
||||||
import "fmt"
|
const (
|
||||||
|
ErrorKey = "error"
|
||||||
type keycardError struct {
|
ErrorOK = "ok"
|
||||||
message string
|
ErrorCancel = "cancel"
|
||||||
}
|
ErrorConnection = "connection-error"
|
||||||
|
ErrorUnknownFlow = "unknown-flow"
|
||||||
func (e *keycardError) Error() string {
|
ErrorNotAKeycard = "not-a-keycard"
|
||||||
return fmt.Sprintf("keycard-error: %s", e.message)
|
ErrorNoKeys = "no-keys"
|
||||||
}
|
ErrorHasKeys = "has-keys"
|
||||||
|
ErrorRequireInit = "require-init"
|
||||||
func newKeycardError(message string) *keycardError {
|
ErrorPairing = "pairing"
|
||||||
return &keycardError{message}
|
ErrorUnblocking = "unblocking"
|
||||||
}
|
ErrorSigning = "signing"
|
||||||
|
ErrorExporting = "exporting"
|
||||||
|
ErrorChanging = "changing-credentials"
|
||||||
|
ErrorLoading = "loading-keys"
|
||||||
|
ErrorStoreMeta = "storing-metadata"
|
||||||
|
ErrorNoData = "no-data"
|
||||||
|
ErrorPCSC = "no-pcsc"
|
||||||
|
ErrorReaderList = "no-reader-list"
|
||||||
|
ErrorNoReader = "no-reader-found"
|
||||||
|
)
|
||||||
|
2
flow.go
2
flow.go
@ -188,7 +188,7 @@ func (f *KeycardFlow) connect() (*keycardContext, error) {
|
|||||||
kc, err := startKeycardContext()
|
kc, err := startKeycardContext()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(ErrorConnection)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
t := time.NewTimer(150 * time.Millisecond)
|
t := time.NewTimer(150 * time.Millisecond)
|
||||||
|
@ -67,26 +67,6 @@ const (
|
|||||||
EnterWallets = "keycard.action.enter-wallets"
|
EnterWallets = "keycard.action.enter-wallets"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
ErrorKey = "error"
|
|
||||||
ErrorOK = "ok"
|
|
||||||
ErrorCancel = "cancel"
|
|
||||||
ErrorConnection = "connection-error"
|
|
||||||
ErrorUnknownFlow = "unknown-flow"
|
|
||||||
ErrorNotAKeycard = "not-a-keycard"
|
|
||||||
ErrorNoKeys = "no-keys"
|
|
||||||
ErrorHasKeys = "has-keys"
|
|
||||||
ErrorRequireInit = "require-init"
|
|
||||||
ErrorPairing = "pairing"
|
|
||||||
ErrorUnblocking = "unblocking"
|
|
||||||
ErrorSigning = "signing"
|
|
||||||
ErrorExporting = "exporting"
|
|
||||||
ErrorChanging = "changing-credentials"
|
|
||||||
ErrorLoading = "loading-keys"
|
|
||||||
ErrorStoreMeta = "storing-metadata"
|
|
||||||
ErrorNoData = "no-data"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AppInfo = "application-info"
|
AppInfo = "application-info"
|
||||||
InstanceUID = "instance-uid"
|
InstanceUID = "instance-uid"
|
||||||
|
@ -2,7 +2,7 @@ package statuskeycardgo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"fmt"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ebfe/scard"
|
"github.com/ebfe/scard"
|
||||||
@ -46,7 +46,7 @@ func startKeycardContext() (*keycardContext, error) {
|
|||||||
func (kc *keycardContext) start() error {
|
func (kc *keycardContext) start() error {
|
||||||
cardCtx, err := scard.EstablishContext()
|
cardCtx, err := scard.EstablishContext()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = newKeycardError("no pcsc service")
|
err = errors.New(ErrorPCSC)
|
||||||
l(err.Error())
|
l(err.Error())
|
||||||
close(kc.connected)
|
close(kc.connected)
|
||||||
return err
|
return err
|
||||||
@ -55,7 +55,7 @@ func (kc *keycardContext) start() error {
|
|||||||
l("listing readers")
|
l("listing readers")
|
||||||
readers, err := cardCtx.ListReaders()
|
readers, err := cardCtx.ListReaders()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = newKeycardError("cannot get readers")
|
err = errors.New(ErrorReaderList)
|
||||||
l(err.Error())
|
l(err.Error())
|
||||||
close(kc.connected)
|
close(kc.connected)
|
||||||
_ = cardCtx.Release()
|
_ = cardCtx.Release()
|
||||||
@ -65,8 +65,7 @@ func (kc *keycardContext) start() error {
|
|||||||
kc.readers = readers
|
kc.readers = readers
|
||||||
|
|
||||||
if len(readers) == 0 {
|
if len(readers) == 0 {
|
||||||
l("no smartcard reader found")
|
err = errors.New(ErrorNoReader)
|
||||||
err = newKeycardError("no smartcard reader found")
|
|
||||||
l(err.Error())
|
l(err.Error())
|
||||||
close(kc.connected)
|
close(kc.connected)
|
||||||
_ = cardCtx.Release()
|
_ = cardCtx.Release()
|
||||||
@ -83,7 +82,7 @@ func (kc *keycardContext) stop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := kc.cardCtx.Release(); err != nil {
|
if err := kc.cardCtx.Release(); err != nil {
|
||||||
err = newKeycardError(fmt.Sprintf("error releasing card context %v", err))
|
err = errors.New(ErrorConnection)
|
||||||
l(err.Error())
|
l(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -262,7 +261,7 @@ func (kc *keycardContext) generateKey() ([]byte, error) {
|
|||||||
|
|
||||||
if appStatus.KeyInitialized {
|
if appStatus.KeyInitialized {
|
||||||
l("generateKey failed - already generated - %+v", err)
|
l("generateKey failed - already generated - %+v", err)
|
||||||
return nil, newKeycardError("key already generated")
|
return nil, errors.New("key already generated")
|
||||||
}
|
}
|
||||||
|
|
||||||
keyUID, err := kc.cmdSet.GenerateKey()
|
keyUID, err := kc.cmdSet.GenerateKey()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user