Skip to content

Commit

Permalink
Work around compiler warning and provide backward compatibility.
Browse files Browse the repository at this point in the history
While compiling this using erlc, warning thrown:

`Warning: crypto:sha_mac/2 is deprecated and will be removed in in a future release; use crypto:hmac/3`

In order to support older OTP releases it's better to have crypto:sha_mac there but for new OTPs we should use crypto:hmac instead.
  • Loading branch information
cicku committed Sep 3, 2015
1 parent bb804e8 commit e812d46
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/oauth_hmac_sha1.erl
@@ -1,4 +1,5 @@
%% Copyright (c) 2008-2009 Tim Fletcher <http://tfletcher.com/>
%% Copyright (c) 2015 Christoher Meng <http://cicku.me/>
%%
%% Permission is hereby granted, free of charge, to any person
%% obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -28,7 +29,15 @@
-spec signature(string(), string(), string()) -> string().
signature(BaseString, CS, TS) ->
Key = oauth_uri:calate("&", [CS, TS]),
base64:encode_to_string(crypto:sha_mac(Key, BaseString)).
base64:encode_to_string(sha2hmac(Key, BaseString)).

sha2hmac(Key, Data) ->
case erlang:function_exported(crypto, hmac, 3) of
true ->
crypto:hmac(sha, Key, Data);
false ->
crypto:sha_mac(Key, Data)
end.

-spec verify(string(), string(), string(), string()) -> boolean().
verify(Signature, BaseString, CS, TS) ->
Expand Down

0 comments on commit e812d46

Please sign in to comment.