Skip to content

Commit

Permalink
erlang-mode comments and indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Jul 28, 2011
1 parent 08b2c40 commit d4cba1e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
20 changes: 10 additions & 10 deletions examples/hmac_api/hmac_api.hrl
Expand Up @@ -8,9 +8,9 @@
%%% %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-define(schema, "AWS").
% defines the prefix for headers to be included in the signature
%% defines the prefix for headers to be included in the signature
-define(headerprefix, "x-amz-").
% defines the date header
%% defines the date header
-define(dateheader, "x-amz-date").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand All @@ -20,14 +20,14 @@
%%% Only change these if you alter the canonicalisation %%%
%%% %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-define(schema, "MOCHIAPI").
%-define(headerprefix, "x-mochiapi-").
%-define(dateheader, "x-mochiapi-date").
%%-define(schema, "MOCHIAPI").
%%-define(headerprefix, "x-mochiapi-").
%%-define(dateheader, "x-mochiapi-date").

% a couple of keys for testing
% these are taken from the document
% % http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
% they are not valid keys!
%% a couple of keys for testing
%% these are taken from the document
%% % http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
%% they are not valid keys!
-define(publickey, "0PN5J17HBGZHT7JJ3X82").
-define(privatekey, "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o").

Expand All @@ -40,4 +40,4 @@
date,
headers,
resource
}).
}).
26 changes: 13 additions & 13 deletions examples/hmac_api/hmac_api_client.erl
Expand Up @@ -2,27 +2,27 @@

-export([
fire/0
]).
]).

-include("hmac_api.hrl").
-author("Hypernumbers Ltd <gordon@hypernumbers.com>").

fire() ->
URL = "http://127.0.0.1:8080/some/page/yeah/",
% Dates SHOULD conform to Section 3.3 of RFC2616
% the examples from the RFC are:
% Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
% Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
% Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
%% Dates SHOULD conform to Section 3.3 of RFC2616
%% the examples from the RFC are:
%% Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
%% Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
%% Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format

% Dates can be conveniently generated using dh_date.erl
% https://github.com/daleharvey/dh_date
% which is largely compatible with
% http://uk.php.net/date
%% Dates can be conveniently generated using dh_date.erl
%% https://github.com/daleharvey/dh_date
%% which is largely compatible with
%% http://uk.php.net/date

% You MIGHT find it convenient to insist on times in UTC only
% as it reduces the errors caused by summer time and other
% conversion issues
%% You MIGHT find it convenient to insist on times in UTC only
%% as it reduces the errors caused by summer time and other
%% conversion issues
Method = post,
Headers = [{"content-type", "application/json"},
{"date", "Sun, 10 Jul 2011 05:07:19"}],
Expand Down
34 changes: 17 additions & 17 deletions examples/hmac_api/hmac_api_lib.erl
Expand Up @@ -42,7 +42,7 @@ authorize_request(Req) ->
Date = get_header(Headers, "date"),
IncAuth = get_header(Headers, "authorization"),
{_Schema, _PublicKey, _Sig} = breakout(IncAuth),
% normally you would use the public key to look up the private key
%% normally you would use the public key to look up the private key
PrivateKey = ?privatekey,
Signature = #hmac_signature{method = Method,
contentmd5 = ContentMD5,
Expand Down Expand Up @@ -104,9 +104,9 @@ sign_data(PrivateKey, #hmac_signature{} = Signature) ->
Str = make_signature_string(Signature),
sign2(PrivateKey, Str).

% this fn is the entry point for a unit test which is why it is broken out...
% if yer encryption and utf8 and base45 doo-dahs don't work then
% yer Donald is well and truly Ducked so ye may as weel test it...
%% this fn is the entry point for a unit test which is why it is broken out...
%% if yer encryption and utf8 and base45 doo-dahs don't work then
%% yer Donald is well and truly Ducked so ye may as weel test it...
sign2(PrivateKey, Str) ->
Sign = xmerl_ucs:to_utf8(Str),
binary_to_list(base64:encode(crypto:sha_mac(PrivateKey, Sign))).
Expand All @@ -130,7 +130,7 @@ consolidate([{H1, K1}, {H2, K2} | Rest], Acc) ->

join(A, B) -> string:strip(A) ++ ";" ++ string:strip(B).

% removes line spacing as per RFC 2616 Section 4.2
%% removes line spacing as per RFC 2616 Section 4.2
rectify(String) ->
Re = "[\x20* | \t*]+",
re:replace(String, Re, " ", [{return, list}, global]).
Expand All @@ -154,7 +154,7 @@ c_res3(Tail) ->
0 -> URL;
N2 -> {U2, Q} = lists:split(N2, URL),
U2 ++ canonicalise_query(Q)
end,
end,
string:to_lower(U3).

canonicalise_query(List) ->
Expand All @@ -165,9 +165,9 @@ canonicalise_query(List) ->
%% if there's a header date take it and ditch the date
get_date([], Date) -> Date;
get_date([{K, _V} | T], Date) -> case string:to_lower(K) of
?dateheader -> [];
_ -> get_date(T, Date)
end.
?dateheader -> [];
_ -> get_date(T, Date)
end.

normalise(List) -> norm2(List, []).

Expand All @@ -189,26 +189,26 @@ get_header(Headers, Type) ->
%%% %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% taken from Amazon docs
% http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
% taken from Amazon docs
%% http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
hash_test1(_) ->
Sig = "DELETE\n\n\n\nx-amz-date:Tue, 27 Mar 2007 21:20:26 +0000\n/johnsmith/photos/puppy.jpg",
Key = ?privatekey,
Hash = sign2(Key, Sig),
Expected = "k3nL7gH3+PadhTEVn5Ip83xlYzk=",
?assertEqual(Expected, Hash).

% taken from Amazon docs
% http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
%% taken from Amazon docs
%% http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
hash_test2(_) ->
Sig = "GET\n\n\nTue, 27 Mar 2007 19:44:46 +0000\n/johnsmith/?acl",
Key = "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
Hash = sign2(Key, Sig),
Expected = "thdUi9VAkzhkniLj96JIrOPGi0g=",
?assertEqual(Expected, Hash).

% taken from Amazon docs
% http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
%% taken from Amazon docs
%% http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
hash_test3(_) ->
Sig = "GET\n\n\nWed, 28 Mar 2007 01:49:49 +0000\n/dictionary/"
++ "fran%C3%A7ais/pr%c3%a9f%c3%a8re",
Expand Down Expand Up @@ -422,11 +422,11 @@ unit_test_() ->
fun signature_test7/1,
fun signature_test8/1,
fun signature_test9/1
],
],

Series3 = [
fun amazon_test1/1
],
],

{setup, Setup, Cleanup, [
{with, [], Series1},
Expand Down

0 comments on commit d4cba1e

Please sign in to comment.