aboutsummaryrefslogtreecommitdiffstats
path: root/accounts
diff options
context:
space:
mode:
Diffstat (limited to 'accounts')
-rw-r--r--accounts/account_manager.go1
-rw-r--r--accounts/key_store_passphrase.go5
-rw-r--r--accounts/key_store_test.go4
-rw-r--r--accounts/presale.go3
4 files changed, 6 insertions, 7 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index dc9f40048..2489d29a0 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -38,6 +38,7 @@ import (
var (
ErrLocked = errors.New("account is locked")
ErrNoMatch = errors.New("no key for given address or file")
+ ErrDecrypt = errors.New("could not decrypt key with given passphrase")
)
type Account struct {
diff --git a/accounts/key_store_passphrase.go b/accounts/key_store_passphrase.go
index 0cc598bbc..87c7cb98f 100644
--- a/accounts/key_store_passphrase.go
+++ b/accounts/key_store_passphrase.go
@@ -31,7 +31,6 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
- "errors"
"fmt"
"io/ioutil"
"path/filepath"
@@ -214,7 +213,7 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt
calculatedMAC := crypto.Keccak256(derivedKey[16:32], cipherText)
if !bytes.Equal(calculatedMAC, mac) {
- return nil, nil, errors.New("Decryption failed: MAC mismatch")
+ return nil, nil, ErrDecrypt
}
plainText, err := aesCTRXOR(derivedKey[:16], cipherText, iv)
@@ -248,7 +247,7 @@ func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byt
calculatedMAC := crypto.Keccak256(derivedKey[16:32], cipherText)
if !bytes.Equal(calculatedMAC, mac) {
- return nil, nil, errors.New("Decryption failed: MAC mismatch")
+ return nil, nil, ErrDecrypt
}
plainText, err := aesCBCDecrypt(crypto.Keccak256(derivedKey[:16])[:16], cipherText, iv)
diff --git a/accounts/key_store_test.go b/accounts/key_store_test.go
index 01bf1b50a..b0417c87e 100644
--- a/accounts/key_store_test.go
+++ b/accounts/key_store_test.go
@@ -94,8 +94,8 @@ func TestKeyStorePassphraseDecryptionFail(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if _, err = ks.GetKey(k1.Address, account.File, "bar"); err == nil {
- t.Fatal("no error for invalid passphrase")
+ if _, err = ks.GetKey(k1.Address, account.File, "bar"); err != ErrDecrypt {
+ t.Fatalf("wrong error for invalid passphrase\ngot %q\nwant %q", err, ErrDecrypt)
}
}
diff --git a/accounts/presale.go b/accounts/presale.go
index 86bfc519c..bb82821b9 100644
--- a/accounts/presale.go
+++ b/accounts/presale.go
@@ -22,7 +22,6 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
- "errors"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
@@ -106,7 +105,7 @@ func aesCBCDecrypt(key, cipherText, iv []byte) ([]byte, error) {
decrypter.CryptBlocks(paddedPlaintext, cipherText)
plaintext := pkcs7Unpad(paddedPlaintext)
if plaintext == nil {
- err = errors.New("Decryption failed: PKCS7Unpad failed after AES decryption")
+ return nil, ErrDecrypt
}
return plaintext, err
}