Skip to content

Commit

Permalink
Merge pull request #125 from cicku/patch-1
Browse files Browse the repository at this point in the history
Work around compiler warning and provide backward compatibility.
  • Loading branch information
nniclausse committed Sep 7, 2015
2 parents a1c8637 + e812d46 commit 36f3d5c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/oauth_hmac_sha1.erl
Original file line number Diff line number Diff line change
@@ -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 36f3d5c

Please sign in to comment.