Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OTP 21 compatibility #4

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/gcs_signer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule GcsSigner do

@base_url "https://storage.googleapis.com"

@otp_greater_21? :erlang.system_info(:otp_release) >= '21'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to change single quote to double quote, since this project uses double quote as a convention?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:erlang.system_info(:otp_release) returns an erlang charlist, which in elixir is denoted by single quotes. If I were to compare with a Binary (double quotes), the result would always be false:

iex> '21' >= "21"
false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see! Thanks for the insight 😄


@type sign_url_opts :: [
verb: String.t,
md5_digest: String.t,
Expand Down Expand Up @@ -77,7 +79,19 @@ defmodule GcsSigner do
|> :public_key.pem_decode
|> (fn [x] -> x end).()
|> :public_key.pem_entry_decode
|> elem(3) # grab privateKey from the record tuple
|> (fn pk -> :public_key.der_decode(:RSAPrivateKey, pk) end).()
|> normalize_private_key
end

defp normalize_private_key(private_key) do
if @otp_greater_21? do
# From OTP 21, GCS keys are correctly decoded and do not need any
# extra treatment
private_key
else
# grab privateKey from the record tuple
private_key
|> elem(3)
|> (fn pk -> :public_key.der_decode(:RSAPrivateKey, pk) end).()
end
end
end