From b93bd7a84637cdb3e9858ef72516b66d80669e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Almir=20Saraj=C4=8Di=C4=87?= Date: Thu, 15 Jul 2021 11:42:47 +0200 Subject: [PATCH] Support Erlang 24 --- lib/json_web_token/algorithm/hmac.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/json_web_token/algorithm/hmac.ex b/lib/json_web_token/algorithm/hmac.ex index 42952d7..90c6b66 100644 --- a/lib/json_web_token/algorithm/hmac.ex +++ b/lib/json_web_token/algorithm/hmac.ex @@ -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 """ @@ -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