ntrepid8 / ex_crypto

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

Add type specifications to all public functions #33

Open dragonwasrobot opened 5 years ago

dragonwasrobot commented 5 years ago

It would be nice if all public functions had a @spec type specification so it becomes more obvious from the documentation what types can be given to a function without reading the actual code.

This would also make it possible for dialyzer to do type inference on the code, e.g. I just came across an issue where a RSAPrivateKey was given to ExPublicKey.encrypt_public but the code ended up failing inside ExPublicKey.RSAPublicKey (https://github.com/ntrepid8/ex_crypto/blob/master/lib/ex_public_key/ex_rsa_public_key.ex#L31) with the error

  ** (Protocol.UndefinedError) protocol String.Chars not implemented for #ExPublicKey.RSAPrivateKey<fingerprint_sha256=....>. This protocol is implemented for: Ecto.Time, Ecto.DateTime, Ecto.Date, Decimal, Version, Atom, Integer, Version.Requirement, NaiveDateTime, URI, Date, DateTime, BitString, List, Float, Time

because the line

{:error, "invalid ExPublicKey.RSAPublicKey: #{rsa_public_key}"}

did not use #{inspect rsa_public_key}.