From 54355f16e752e2741c2877b1398660d7b40d602e Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 17 Jan 2014 10:29:44 -0500 Subject: [PATCH] Return meaningful errors for locked wallets. This change adds a check for a valid (32-byte length) secret before attempting to encrypt or decrypt any addresses. If the check fails, a meaningful error (ErrWalletLocked) is returned to the caller, rather than an error out of the aes package. --- wallet/wallet.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wallet/wallet.go b/wallet/wallet.go index b08f6bd..66237ae 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -885,6 +885,9 @@ func (w *Wallet) extendKeypool(n uint, bs *BlockStamp) error { if !ok { return errors.New("expected last chained address not found") } + if len(w.secret) != 32 { + return ErrWalletLocked + } privkey, err := addr.unlock(w.secret) if err != nil { return err @@ -971,6 +974,9 @@ func (w *Wallet) createMissingPrivateKeys() error { return errors.New("missing previous chained address") } prevAddr := w.addrMap[*apkh] + if len(w.secret) != 32 { + return ErrWalletLocked + } prevPrivKey, err := prevAddr.unlock(w.secret) if err != nil { return err