Skip to content

Commit

Permalink
Merge pull request #3 from berty/chore/cherry-pick-PR-1289
Browse files Browse the repository at this point in the history
chore: Cherry pick PR 1289 for error handling
  • Loading branch information
jefft0 authored Oct 24, 2023
2 parents a3bdd2b + edea16a commit c0cef2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tm2/pkg/crypto/keys/armor/armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func decryptPrivKey(saltBytes []byte, encBytes []byte, passphrase string) (privK
}
key = crypto.Sha256(key) // Get 32 bytes
privKeyBytes, err := xsalsa20symmetric.DecryptSymmetric(encBytes, key)
if err != nil && err.Error() == "Ciphertext decryption failed" {
if err != nil && err.Error() == "ciphertext decryption failed" {
return privKey, keyerror.NewErrWrongPassword()
} else if err != nil {
return privKey, err
Expand Down
7 changes: 5 additions & 2 deletions tm2/pkg/crypto/keys/keyerror/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keyerror

import (
"errors"
"fmt"
)

Expand Down Expand Up @@ -40,7 +41,8 @@ func IsErrKeyNotFound(err error) bool {
if err == nil {
return false
}
if keyErr, ok := err.(keybaseError); ok {
var keyErr keybaseError
if errors.As(err, &keyErr) {
if keyErr.Code() == codeKeyNotFound {
return true
}
Expand Down Expand Up @@ -72,7 +74,8 @@ func IsErrWrongPassword(err error) bool {
if err == nil {
return false
}
if keyErr, ok := err.(keybaseError); ok {
var keyErr keybaseError
if errors.As(err, &keyErr) {
if keyErr.Code() == codeWrongPassword {
return true
}
Expand Down

0 comments on commit c0cef2f

Please sign in to comment.