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:
parent
97e1442e8d
commit
54355f16e7
1 changed files with 6 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue