Skip to content

Commit a386efa

Browse files
authored
Merge pull request #81 from DefactoSoftware/rick/support-OTP24-crypto-hmac
Support OTP24 by checking if new or old crypto API should be used
2 parents a73b22d + fccc636 commit a386efa

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/lti.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule LTI do
2929
%LaunchParams{} = launch_params
3030
) do
3131
:sha
32-
|> :crypto.hmac(
32+
|> hmac_fun(
3333
encode_secret(secret),
3434
base_string(creds, oauth_params, launch_params)
3535
)
@@ -120,4 +120,10 @@ defmodule LTI do
120120
|> :crypto.strong_rand_bytes()
121121
|> Base.encode64()
122122
end
123+
124+
if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do
125+
def hmac_fun(digest, key, data), do: :crypto.mac(:hmac, digest, key, data)
126+
else
127+
def hmac_fun(digest, key, data), do: :crypto.hmac(digest, key, data)
128+
end
123129
end

lib/lti_result.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule LTIResult do
4545

4646
defp generate_signature(secret, basestring) do
4747
:sha
48-
|> :crypto.hmac(
48+
|> LTI.hmac_fun(
4949
percent_encode(secret) <> "&",
5050
basestring
5151
)

0 commit comments

Comments
 (0)