Browse Source

Merge pull request #32 from narugami/master

Replace deprecated functions
Tim Fletcher 8 years ago
parent
commit
e5e07e7041
2 changed files with 2 additions and 12 deletions
  1. 0 2
      .travis.yml
  2. 2 10
      src/oauth.erl

+ 0 - 2
.travis.yml

@@ -3,5 +3,3 @@ otp_release:
   - 18.0
   - 17.5
   - R16B03
-  - R15B03
-  - R14B04

+ 2 - 10
src/oauth.erl

@@ -77,7 +77,7 @@ signature_params(Consumer, Params, Token) ->
 
 signature_params(Consumer, Params) ->
   Timestamp = unix_timestamp(),
-  Nonce = base64:encode_to_string(crypto:rand_bytes(32)), % cf. ruby-oauth
+  Nonce = base64:encode_to_string(crypto:strong_rand_bytes(32)), % cf. ruby-oauth
   [ {"oauth_version", "1.0"}
   , {"oauth_nonce", Nonce}
   , {"oauth_timestamp", integer_to_list(Timestamp)}
@@ -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(hmac_sha(Key, BaseString)).
+  base64:encode_to_string(crypto: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,14 +136,6 @@ 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).