mirror of
https://github.com/status-im/status-keycard-go.git
synced 2025-03-02 15:00:40 +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
|
||||
|
||||
import "fmt"
|
||||
|
||||
type keycardError struct {
|
||||
message string
|
||||
}
|
||||
|
||||
func (e *keycardError) Error() string {
|
||||
return fmt.Sprintf("keycard-error: %s", e.message)
|
||||
}
|
||||
|
||||
func newKeycardError(message string) *keycardError {
|
||||
return &keycardError{message}
|
||||
}
|
||||
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"
|
||||
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()
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.New(ErrorConnection)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
t := time.NewTimer(150 * time.Millisecond)
|
||||
|
@ -67,26 +67,6 @@ const (
|
||||
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 (
|
||||
AppInfo = "application-info"
|
||||
InstanceUID = "instance-uid"
|
||||
|
@ -2,7 +2,7 @@ package statuskeycardgo
|
||||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"fmt"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/ebfe/scard"
|
||||
@ -46,7 +46,7 @@ func startKeycardContext() (*keycardContext, error) {
|
||||
func (kc *keycardContext) start() error {
|
||||
cardCtx, err := scard.EstablishContext()
|
||||
if err != nil {
|
||||
err = newKeycardError("no pcsc service")
|
||||
err = errors.New(ErrorPCSC)
|
||||
l(err.Error())
|
||||
close(kc.connected)
|
||||
return err
|
||||
@ -55,7 +55,7 @@ func (kc *keycardContext) start() error {
|
||||
l("listing readers")
|
||||
readers, err := cardCtx.ListReaders()
|
||||
if err != nil {
|
||||
err = newKeycardError("cannot get readers")
|
||||
err = errors.New(ErrorReaderList)
|
||||
l(err.Error())
|
||||
close(kc.connected)
|
||||
_ = cardCtx.Release()
|
||||
@ -65,8 +65,7 @@ func (kc *keycardContext) start() error {
|
||||
kc.readers = readers
|
||||
|
||||
if len(readers) == 0 {
|
||||
l("no smartcard reader found")
|
||||
err = newKeycardError("no smartcard reader found")
|
||||
err = errors.New(ErrorNoReader)
|
||||
l(err.Error())
|
||||
close(kc.connected)
|
||||
_ = cardCtx.Release()
|
||||
@ -83,7 +82,7 @@ func (kc *keycardContext) stop() error {
|
||||
}
|
||||
|
||||
if err := kc.cardCtx.Release(); err != nil {
|
||||
err = newKeycardError(fmt.Sprintf("error releasing card context %v", err))
|
||||
err = errors.New(ErrorConnection)
|
||||
l(err.Error())
|
||||
return err
|
||||
}
|
||||
@ -262,7 +261,7 @@ func (kc *keycardContext) generateKey() ([]byte, error) {
|
||||
|
||||
if appStatus.KeyInitialized {
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user