Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Combine oauth_hmac and oauth_plaintext into oauth_crypto.
  • Loading branch information
Tim Fletcher committed Nov 7, 2008
1 parent 94a3455 commit 419e63197b6d3f563f0a59ad32b8576da20b4c3a
Showing 5 changed files with 18 additions and 22 deletions.
@@ -1,5 +1,5 @@
-define(plaintext_signature_test(ConsumerSecret, TokenSecret, ExpectedSignature),
?_assertEqual(ExpectedSignature, oauth_plaintext:signature(ConsumerSecret, TokenSecret))
?_assertEqual(ExpectedSignature, oauth_crypto:plaintext_signature(ConsumerSecret, TokenSecret))
).

-define(normalize_test(ExpectedString, Params),
@@ -11,5 +11,5 @@
end).

-define(hmac_signature_test(ExpectedSignature, ConsumerSecret, TokenSecret, BaseString), fun() ->
?assertEqual(ExpectedSignature, oauth_hmac:signature(string:join(BaseString, []), ConsumerSecret, TokenSecret))
?assertEqual(ExpectedSignature, oauth_crypto:hmac_signature(string:join(BaseString, []), ConsumerSecret, TokenSecret))
end).
@@ -0,0 +1,14 @@
-module(oauth_crypto).

-export([plaintext_signature/2, hmac_signature/3]).


plaintext_signature(ConsumerSecret, TokenSecret) ->
Encoded = oauth_util:esprintf("%s&%s", [ConsumerSecret, TokenSecret]),
fmt:percent_encode(Encoded).

hmac_signature(BaseString, ConsumerSecret, TokenSecret) ->
CS = fmt:percent_encode(ConsumerSecret),
TS = fmt:percent_encode(TokenSecret),
Key = fmt:sprintf("%s&%s", [CS, TS]),
base64:encode_to_string(crypto:sha_mac(Key, BaseString)).

This file was deleted.

This file was deleted.

@@ -40,10 +40,10 @@ signature(Params, Request, Consumer, TokenSecret) ->
ConsumerSecret = oauth_consumer:secret(Consumer),
case oauth_consumer:signature_method(Consumer) of
"PLAINTEXT" ->
oauth_plaintext:signature(ConsumerSecret, TokenSecret);
oauth_crypto:plaintext_signature(ConsumerSecret, TokenSecret);
"HMAC-SHA1" ->
BaseString = oauth_base:string(method(Request), url(Request), Params),
oauth_hmac:signature(BaseString, ConsumerSecret, TokenSecret)
oauth_crypto:hmac_signature(BaseString, ConsumerSecret, TokenSecret)
end.

oauth_params(Request, Consumer, Token) ->

0 comments on commit 419e631

Please sign in to comment.