ntrepid8 / ex_crypto

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

ExPublicKey.generate_key compatibility with OTP 20.0 #15

Closed Narnach closed 6 years ago

Narnach commented 6 years ago

The initial ExCrypto implementation of generate_key by @barttenbrinke was tested against Erlang/OTP 20.1, which has slightly different internal library versions than Erlang/OTP 20.0, which introduced the generate_key feature it was built on. This PR aims to make the feature work on both versions.

I've lowered the version requirement for Erlang public_key from 1.5 to 1.4.1 (which matches OTP 20.0) and switched to Version.match?() to do proper version checking.

The internal data format for RSAPrivateKey was not consistently handled in OTP 20.0, generating version 0, but when encoding it as PEM and parsing it back, the version it returned was :"two-prime". Based on some searching, 0 is the internal name of two-prime, and 20.1 smooths this out but 20.0 still gives the raw value.

I've considered editing .travis.yml to add OTP release 20.0 as a test target as well, but I'm not sure what the policy is for editing that file. My versions when testing were these:

# elixir --version
Erlang/OTP 20 [erts-9.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Elixir 1.5.1
ntrepid8 commented 6 years ago

Thanks for the PR! See my comments in the code and let me know what you think. Once we get that sorted out I'll get it merged and released to hex.pm.

Narnach commented 6 years ago

I've updated the PR with a List of integers comparison to replace Version.match?. Locally it works, and I see that this time CI liked the changes as well :-)

ntrepid8 commented 6 years ago

Thanks!

ntrepid8 commented 6 years ago

Published on hex.pm as release 0.7.1. Thanks again!

Narnach commented 6 years ago

Awesome, thanks for accepting the changes!