Browse Source

Use crypto:mac/4 for OTP 22+

Tim Fletcher 4 years ago
parent
commit
4c6cd78e51
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/oauth.erl

+ 7 - 1
src/oauth.erl

@@ -15,6 +15,12 @@
 
 -include_lib("public_key/include/public_key.hrl").
 
+-if(?OTP_RELEASE >= 22).
+-define(HMAC_SHA1(Key, Data), crypto:mac(hmac, sha, Key, Data)).
+-else.
+-define(HMAC_SHA1(Key, Data), crypto:hmac(sha, Key, Data)).
+-endif.
+
 get(URL, ExtraParams, Consumer) ->
   get(URL, ExtraParams, Consumer, "", "").
 
@@ -128,7 +134,7 @@ hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret) ->
 
 hmac_sha1_signature(BaseString, Consumer, TokenSecret) ->
   Key = uri_join([consumer_secret(Consumer), TokenSecret]),
-  base64:encode_to_string(crypto:hmac(sha, Key, BaseString)).
+  base64:encode_to_string(?HMAC_SHA1(Key, BaseString)).
 
 hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
   verify_in_constant_time(Signature, hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret)).