Keats / jsonwebtoken

JWT lib in rust
MIT License
1.69k stars 271 forks source link

`map_err(|_| ...)` is an anti-pattern #164

Closed arniu closed 2 years ago

arniu commented 3 years ago

map_err(|_| ...) is an anti-pattern, which lose detail about the failure.

Keats commented 3 years ago

But in more practical terms about this repo?

arniu commented 3 years ago

There are two cases in the repo, which convert different failures to simple InvalidRsaKey errors. As a result, it's difficult to debug. For example, #151 .

https://github.com/Keats/jsonwebtoken/blob/90b97007484e782994120587e751108819b7aa50/src/crypto/rsa.rs#L42

Parse key every signing! Maybe move to EncodingKey?

https://github.com/Keats/jsonwebtoken/blob/90b97007484e782994120587e751108819b7aa50/src/crypto/rsa.rs#L48

InvalidRsaKey here is weired.

Keats commented 3 years ago

ah I see, that should be easy to fix in the v8 branch. It was probably copied from the ring docs example.