Skip to content

Commit

Permalink
Add support for OTP 24 (#24)
Browse files Browse the repository at this point in the history
:crypto.hmac/3 was removed in favor of :crypto.mac/4 which was introduced in OTP 22.1.

Co-authored-by: Tobias Schwab <tobstarr@gmail.com>
Co-authored-by: Aleksei Magusev <248290+lexmag@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 27, 2021
1 parent b3faf0c commit b5ad3bd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/oauther.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ defmodule OAuther do
end

def signature(verb, url, params, %Credentials{method: :hmac_sha1} = creds) do
:sha
|> :crypto.hmac(compose_key(creds), base_string(verb, url, params))
creds
|> compose_key()
|> hmac_sha(base_string(verb, url, params))
|> Base.encode64()
end

Expand All @@ -71,6 +72,17 @@ defmodule OAuther do
|> Base.encode64()
end

# TODO: Remove this once we require at minimum OTP 22.
if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do
defp hmac_sha(key, data) do
:crypto.mac(:hmac, :sha, key, data)
end
else
defp hmac_sha(key, data) do
:crypto.hmac(:sha, key, data)
end
end

defp protocol_param?({key, _value}) do
String.starts_with?(key, "oauth_")
end
Expand Down

0 comments on commit b5ad3bd

Please sign in to comment.