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.
This commit is contained in:
Josh Rickmar 2014-01-17 10:29:44 -05:00
parent 97e1442e8d
commit 54355f16e7

View file

@ -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