Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Continue to support older OTP releases which don't have crypto:hmac/3

  • Loading branch information...
commit 118e9f7284c81cb72e131e20bcecf5872a5cbe97 1 parent e206c0a
@tim authored
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/oauth.erl
View
10 src/oauth.erl
@@ -128,7 +128,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_sha(Key, BaseString)).
hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
verify_in_constant_time(Signature, hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret)).
@@ -136,6 +136,14 @@ hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
hmac_sha1_verify(Signature, BaseString, Consumer, TokenSecret) ->
verify_in_constant_time(Signature, hmac_sha1_signature(BaseString, Consumer, TokenSecret)).
+hmac_sha(Key, Data) ->
+ case erlang:function_exported(crypto, hmac, 3) of
+ true ->
+ crypto:hmac(sha, Key, Data);
+ false ->
+ crypto:sha_mac(Key, Data)
+ end.
+
rsa_sha1_signature(HttpMethod, URL, Params, Consumer) ->
BaseString = signature_base_string(HttpMethod, URL, Params),
rsa_sha1_signature(BaseString, Consumer).
Please sign in to comment.
Something went wrong with that request. Please try again.