From a2d65ea700abcd58e65fbc231bc909e940371469 Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Wed, 28 Nov 2018 12:42:20 +0100 Subject: [PATCH] remove SelectNotInitialized --- cmd/status-hardware-wallet/initializer.go | 8 ++++++- lightwallet/actions/actions.go | 29 ----------------------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/cmd/status-hardware-wallet/initializer.go b/cmd/status-hardware-wallet/initializer.go index 6e193cd..aeccdfd 100644 --- a/cmd/status-hardware-wallet/initializer.go +++ b/cmd/status-hardware-wallet/initializer.go @@ -16,6 +16,8 @@ var ( errAppletNotInstalled = errors.New("applet not installed") errCardNotInitialized = errors.New("card not initialized") errCardAlreadyInitialized = errors.New("card already initialized") + + ErrNotInitialized = errors.New("card not initialized") ) // Initializer defines a struct with methods to install applets and initialize a card. @@ -87,11 +89,15 @@ func (i *Initializer) Init() (*lightwallet.Secrets, error) { } func (i *Initializer) Pair(pairingPass, pin string) (*lightwallet.PairingInfo, error) { - _, err := actions.SelectInitialized(i.c, lightwallet.WalletAID) + appInfo, err := actions.Select(i.c, lightwallet.WalletAID) if err != nil { return nil, err } + if !appInfo.Initialized { + return nil, ErrNotInitialized + } + return actions.Pair(i.c, pairingPass, pin) } diff --git a/lightwallet/actions/actions.go b/lightwallet/actions/actions.go index 63fd451..8f61da1 100644 --- a/lightwallet/actions/actions.go +++ b/lightwallet/actions/actions.go @@ -15,7 +15,6 @@ import ( var ( ErrAlreadyInitialized = errors.New("card already initialized") - ErrNotInitialized = errors.New("card not initialized") ErrWrongApplicationInfoTemplate = errors.New("wrong application info template") ErrApplicationStatusTemplateNotFound = errors.New("application status template not found") ) @@ -48,34 +47,6 @@ func Select(c globalplatform.Channel, aid []byte) (*lightwallet.ApplicationInfo, return parseApplicationInfo(resp.Data, info) } -func SelectNotInitialized(c globalplatform.Channel, aid []byte) ([]byte, error) { - sel := globalplatform.NewCommandSelect(aid) - resp, err := c.Send(sel) - if err = checkOKResponse(err, resp); err != nil { - return nil, err - } - - if resp.Data[0] != lightwallet.TagSelectResponsePreInitialized { - return nil, ErrAlreadyInitialized - } - - return resp.Data[2:], nil -} - -func SelectInitialized(c globalplatform.Channel, aid []byte) (*lightwallet.ApplicationInfo, error) { - sel := globalplatform.NewCommandSelect(aid) - resp, err := c.Send(sel) - if err = checkOKResponse(err, resp); err != nil { - return nil, err - } - - if resp.Data[0] == lightwallet.TagSelectResponsePreInitialized { - return nil, ErrNotInitialized - } - - return parseApplicationInfo(resp.Data, &lightwallet.ApplicationInfo{}) -} - func Init(c globalplatform.Channel, cardPubKey []byte, secrets *lightwallet.Secrets, aid []byte) error { secureChannel, err := lightwallet.NewSecureChannel(c, cardPubKey) if err != nil {