Skip to content
Open
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
8 changes: 7 additions & 1 deletion lib/json_web_token/algorithm/hmac.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule JsonWebToken.Algorithm.Hmac do
"""
def sign(sha_bits, shared_key, signing_input) do
validate_params(sha_bits, shared_key)
:crypto.hmac(sha_bits, shared_key, signing_input)
hmac(sha_bits, shared_key, signing_input)
end

@doc """
Expand Down Expand Up @@ -48,4 +48,10 @@ defmodule JsonWebToken.Algorithm.Hmac do

defp weak_key(true), do: raise "Key size smaller than the hash output size"
defp weak_key(_), do: :ok

if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do
defp hmac(digest, key, payload), do: :crypto.mac(:hmac, digest, key, payload)
else
defp hmac(digest, key, payload), do: :crypto.hmac(digest, key, payload)
end
end