Skip to content

Commit

Permalink
Use :crypto.mac/4
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-hanna authored and chulkilee committed May 23, 2021
1 parent 82af9a8 commit 4ca3da8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/ex_force/oauth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,15 @@ defmodule ExForce.OAuth do
|> DateTime.to_unix(:millisecond)
|> Integer.to_string()

:sha256
|> :crypto.hmac(client_secret, id <> issued_at_raw)
hmac_fun(client_secret, id <> issued_at_raw)
|> Base.encode64()
end

# :crypto.mac/4 was defined in OTP 22 and :crypto.hmac/3 was removed in OTP 24,
# this ensures backwards compatibility between erlang versions
if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do
defp hmac_fun(key, data), do: :crypto.mac(:hmac, :sha256, key, data)
else
defp hmac_fun(key, data), do: :crypto.hmac(:sha256, key, data)
end
end

0 comments on commit 4ca3da8

Please sign in to comment.