ntrepid8 / ex_crypto

Wrapper around the Erlang crypto module for Elixir.
MIT License
144 stars 48 forks source link

Return errors from decode_payload #45

Open KiKoS0 opened 2 years ago

KiKoS0 commented 2 years ago

Making the return type compatible with the method's typespec, also stopping exceptions from raising when base64 decoding fails or in case the decoded payload is too small. Preventing smaller input to pass too:

iex(5)> payload = Base.url_encode64("AAAAAAAAAAAAAAAA") |> ExCrypto.decode_payload
{:ok, {"AAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAA"}}

Before this change we need to try-rescue every time decode_payload is called with arbitrary data as argument.

darwin67 commented 2 years ago

@KiKoS0 test? :)