ntrepid8 / ex_crypto

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

reproduce possible decrypt bug #34

Closed joustava closed 4 years ago

joustava commented 5 years ago

I'm running on

⟩ elixir --version
Erlang/OTP 21 [erts-10.2.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

Elixir 1.8.1 (compiled with Erlang/OTP 21)

When I pass arbitrary data to decrypt like: ExCrypto.decrypt(aes_256_key, iv, "asdasdasdads")

I receive the following error:

** (MatchError) no match of right hand side value: %MatchError{term: {:error, "argument error"}}
    (ex_crypto) lib/ex_crypto.ex:28: ExCrypto.normalize_error/3

Now, I'm not completely sure if this is intended or if this is a bug (Elixir beginner) but it seems to me that Exception.normalize/3 doesn't map this particular error as expected. My usecase is such that it might be possible that arbitrary data comes into the decrypt, which might not be best solution however I'd expect it to inform the caller with an error tuple and not throw.

In this PR I added a test to reproduce this. Also in ex_crypto.ex I added a cond clause to 'catch' and normalize this error.

ntrepid8 commented 5 years ago

Thanks for looking at this. I'll check it out and see what I can find out.