Skip to content

Commit

Permalink
update/2017.11.06_updates-for-release (#17)
Browse files Browse the repository at this point in the history
* update mix.exs and CHANGELOG for release 0.7.1

* fix otp_has_rsa_gen_support/0 integer parse logic
- update style
  • Loading branch information
ntrepid8 authored Nov 6, 2017
1 parent e47a790 commit 1fdbffd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## v0.7.1
- Fixes
- fix `generate_key` compatibility with OTP 20
- fix README examples compatibility with Elixir v1.5
- Contributors (thanks!)
- [Narnach](https://github.com/Narnach)
- [denispeplin](https://github.com/denispeplin)

## v0.7.0
- Enhancements
- Add generate_key and pem_encode wrappers
Expand Down
31 changes: 24 additions & 7 deletions lib/ex_public_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ defmodule ExPublicKey do
Mostly wrappers Erlang' `:public_key` module, to help simplify using public/private key encryption in Elixir.
"""

# Erlang public_key v1.4.1 corresponds to Erlang/OTP 20.0
@otp_20_public_key_version [1, 4, 1]

defmacro __using__(_) do
quote do
import ExPublicKey
Expand Down Expand Up @@ -241,8 +244,16 @@ defmodule ExPublicKey do
def generate_key(bits, public_exp), do: generate_key(:rsa, bits, public_exp)
def generate_key(bits, public_exp), do: generate_key(:rsa, bits, public_exp)
def generate_key(:rsa, bits, public_exp), do: generate_key(:rsa, bits, public_exp, otp_has_rsa_gen_support())
def generate_key(:rsa, bits, public_exp, false), do: generate_rsa_openssl_fallback(bits) # Fallback support for OTP 18 & 19.
def generate_key(:rsa, bits, public_exp, true), do: {:ok, :public_key.generate_key({:rsa, bits, public_exp}) |> ExPublicKey.RSAPrivateKey.from_sequence }
def generate_key(:rsa, bits, public_exp, false) do
# Fallback support for OTP 18 & 19.
generate_rsa_openssl_fallback(bits)
end
def generate_key(:rsa, bits, public_exp, true) do
new_rsa_key =
:public_key.generate_key({:rsa, bits, public_exp})
|> ExPublicKey.RSAPrivateKey.from_sequence()
{:ok, new_rsa_key}
end

@doc """
Generate a new key.
Expand Down Expand Up @@ -314,13 +325,19 @@ defmodule ExPublicKey do
end

# Erlang public_key v1.4.1 corresponds to Erlang/OTP 20.0
defp otp_has_rsa_gen_support do
integer_list_version = Application.spec(:public_key, :vsn)
|> Kernel.to_string
defp otp_has_rsa_gen_support() do
Application.spec(:public_key, :vsn)
|> Kernel.to_string()
|> String.split(".")
|> Enum.map(&Integer.parse/1)
|> Enum.map(fn(i) ->
{i_int, _} = Integer.parse(i)
i_int
end)
|> otp_has_rsa_gen_support_z()
end

integer_list_version >= [1, 4, 1]
defp otp_has_rsa_gen_support_z(version_int_list) do
version_int_list >= @otp_20_public_key_version
end

defp generate_rsa_openssl_fallback(bits) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ExCrypto.Mixfile do

def project do
[app: :ex_crypto,
version: "0.7.0",
version: "0.7.1",
name: "ExCrypto",
elixir: ">= 1.4.2",
description: description(),
Expand Down

0 comments on commit 1fdbffd

Please sign in to comment.