-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Error string in decryptPrivKey. Use errors.As in IsErrWrongPassword. #1289
Conversation
…s.As in IsErrWrongPassword. See the PR. Signed-off-by: Jeff Thompson <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1289 +/- ##
==========================================
+ Coverage 47.89% 47.90% +0.01%
==========================================
Files 372 372
Lines 62990 62990
==========================================
+ Hits 30166 30175 +9
+ Misses 30363 30354 -9
Partials 2461 2461
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix 🙏
Thanks for the approval, @zivkovicmilos . Does this PR need more approvals before merging? |
We try to keep at least a minimum of 2 reviewers per PR, even for small changes like this. I've pinged @ajnavarro to take a look as well, so we should have it merged in soon 🚀 |
…ord. (gnolang#1289) This PR fixes bugs with error handling: * `decryptPrivKey` checks if `DecryptSymmetric` [returns the error "Ciphertext decryption failed"](https://github.com/gnolang/gno/blob/a3bdd2bb25b76b17176c3c59a1ce2522f8a75e53/tm2/pkg/crypto/keys/armor/armor.go#L131) and converts it to `ErrWrongPassword`. The problem is that `DecryptSymmetric` [returns "ciphertext decryption failed"](https://github.com/gnolang/gno/blob/a3bdd2bb25b76b17176c3c59a1ce2522f8a75e53/tm2/pkg/crypto/xsalsa20symmetric/symmetric.go#L53C27-L53C55) (spelled differently). This PR fixes the string in the error check. * `IsErrWrongPassword` checks if the [error type is `keybaseError`](https://github.com/gnolang/gno/blob/a3bdd2bb25b76b17176c3c59a1ce2522f8a75e53/tm2/pkg/crypto/keys/keyerror/errors.go#L75C24-L75C36) . But the error can be wrapped as it is [in `signAndBroadcastTxCommit`](https://github.com/gnolang/gno/blob/60e05e83f57558843c0808f78500b6a51b2a22c1/gno.land/pkg/gnoclient/client_txs.go#L104). Therefore, instead of a simple error type check, this PR updates `IsErrWrongPassword` (and `IsErrKeyNotFound`) to use `errors.As` to check the error type (which unwraps the error if needed). Signed-off-by: Jeff Thompson <[email protected]>
…ord. (gnolang#1289) This PR fixes bugs with error handling: * `decryptPrivKey` checks if `DecryptSymmetric` [returns the error "Ciphertext decryption failed"](https://github.com/gnolang/gno/blob/a3bdd2bb25b76b17176c3c59a1ce2522f8a75e53/tm2/pkg/crypto/keys/armor/armor.go#L131) and converts it to `ErrWrongPassword`. The problem is that `DecryptSymmetric` [returns "ciphertext decryption failed"](https://github.com/gnolang/gno/blob/a3bdd2bb25b76b17176c3c59a1ce2522f8a75e53/tm2/pkg/crypto/xsalsa20symmetric/symmetric.go#L53C27-L53C55) (spelled differently). This PR fixes the string in the error check. * `IsErrWrongPassword` checks if the [error type is `keybaseError`](https://github.com/gnolang/gno/blob/a3bdd2bb25b76b17176c3c59a1ce2522f8a75e53/tm2/pkg/crypto/keys/keyerror/errors.go#L75C24-L75C36) . But the error can be wrapped as it is [in `signAndBroadcastTxCommit`](https://github.com/gnolang/gno/blob/60e05e83f57558843c0808f78500b6a51b2a22c1/gno.land/pkg/gnoclient/client_txs.go#L104). Therefore, instead of a simple error type check, this PR updates `IsErrWrongPassword` (and `IsErrKeyNotFound`) to use `errors.As` to check the error type (which unwraps the error if needed). Signed-off-by: Jeff Thompson <[email protected]>
This PR fixes bugs with error handling:
decryptPrivKey
checks ifDecryptSymmetric
returns the error "Ciphertext decryption failed" and converts it toErrWrongPassword
. The problem is thatDecryptSymmetric
returns "ciphertext decryption failed" (spelled differently). This PR fixes the string in the error check.IsErrWrongPassword
checks if the error type iskeybaseError
. But the error can be wrapped as it is insignAndBroadcastTxCommit
. Therefore, instead of a simple error type check, this PR updatesIsErrWrongPassword
(andIsErrKeyNotFound
) to useerrors.As
to check the error type (which unwraps the error if needed).