Skip to content

Commit

Permalink
Continue to support older OTP releases which don't have crypto:hmac/3
Browse files Browse the repository at this point in the history
  • Loading branch information
tim committed Jul 21, 2013
1 parent e206c0a commit 118e9f7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/oauth.erl
Expand Up @@ -128,14 +128,22 @@ 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)).

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).
Expand Down

0 comments on commit 118e9f7

Please sign in to comment.