Handle crypto for different OTP versions better in media proxy

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-06-07 16:39:14 +02:00
parent c3e586af6e
commit 95913ba28b
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -58,7 +58,19 @@ defmodule Mobilizon.Web.MediaProxy do
end end
defp signed_url(url) do defp signed_url(url) do
:crypto.mac(:hmac, :sha, Config.get([Web.Endpoint, :secret_key_base]), url) sha_hmac(Config.get([Web.Endpoint, :secret_key_base]), url)
end
@compile {:no_warn_undefined, {:crypto, :mac, 4}}
@compile {:no_warn_undefined, {:crypto, :hmac, 3}}
defp sha_hmac(key, url) do
# :crypto.hmac was removed in OTP24, but :crypto.mac was added in OTP 22.1
# TODO: Remove me when we don't support OTP 21/22 anymore
if function_exported?(:crypto, :mac, 4) do
:crypto.mac(:hmac, :sha, key, url)
else
:crypto.hmac(:sha, key, url)
end
end end
def filename(url_or_path) do def filename(url_or_path) do