From fa7d4926c504ba273c1f22c2e1c4838dbd8b4e5f Mon Sep 17 00:00:00 2001 From: Kenneth Mburu Date: Tue, 17 May 2022 05:13:35 +0300 Subject: [PATCH] Use :crypto.mac/4 when available --- lib/aws_auth/utils.ex | 6 +++++- mix.exs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/aws_auth/utils.ex b/lib/aws_auth/utils.ex index bd188ce..0e3acee 100644 --- a/lib/aws_auth/utils.ex +++ b/lib/aws_auth/utils.ex @@ -49,7 +49,11 @@ defmodule AWSAuth.Utils do end def hmac_sha256(key, data) do - :crypto.hmac(:sha256, key, data) + if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do + :crypto.mac(:hmac, :sha256, key, data) + else + :crypto.hmac(:sha256, key, data) + end end def bytes_to_string(bytes) do diff --git a/mix.exs b/mix.exs index 68628e0..e4918b9 100644 --- a/mix.exs +++ b/mix.exs @@ -14,7 +14,7 @@ defmodule AWSAuth.Mixfile do end def application do - [applications: [:logger]] + [applications: [:logger, :crypto]] end defp deps do