You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by be...@apache.org on 2014/02/13 17:06:08 UTC

[13/50] mochiweb commit: updated refs/heads/import-upstream to 8eb1f22

Get rid of crypto warnings

Also should be backwards compatible options back to R14 based on
compile macros in rebar


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/6e06bd60
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/6e06bd60
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/6e06bd60

Branch: refs/heads/import-upstream
Commit: 6e06bd60897c018af9951f4549d8d279952b19db
Parents: 680dba8
Author: Fred Hebert <mo...@ferd.ca>
Authored: Tue Jul 16 11:06:56 2013 -0400
Committer: Fred Hebert <mo...@ferd.ca>
Committed: Tue Jul 16 12:52:41 2013 -0400

----------------------------------------------------------------------
 rebar.config             |  3 ++-
 src/mochiweb_session.erl | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/6e06bd60/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index 101930a..0ae370c 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,6 +1,7 @@
 % -*- mode: erlang -*-
 {erl_opts, [debug_info,
-            {platform_define, "R15", 'gen_tcp_r15b_workaround'}]}.
+            {platform_define, "R15", 'gen_tcp_r15b_workaround'},
+            {platform_define, "(R14|R15|R16B-)", 'crypto_compatibility'}]}.
 {cover_enabled, true}.
 {eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
 {dialyzer_opts, [{warnings, [no_return,

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/6e06bd60/src/mochiweb_session.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_session.erl b/src/mochiweb_session.erl
index ac5d66b..bd78606 100644
--- a/src/mochiweb_session.erl
+++ b/src/mochiweb_session.erl
@@ -100,6 +100,7 @@ ensure_binary(B) when is_binary(B) ->
 ensure_binary(L) when is_list(L) ->
     iolist_to_binary(L).
 
+-ifdef(crypto_compatibility).
 -spec encrypt_data(binary(), binary()) -> binary().
 encrypt_data(Data, Key) ->
     IV = crypto:rand_bytes(16),
@@ -118,6 +119,26 @@ gen_key(ExpirationTime, ServerKey)->
 gen_hmac(ExpirationTime, Data, SessionKey, Key) ->
     crypto:sha_mac(Key, [ExpirationTime, Data, SessionKey]).
 
+-else.
+-spec encrypt_data(binary(), binary()) -> binary().
+encrypt_data(Data, Key) ->
+    IV = crypto:rand_bytes(16),
+    Crypt = crypto:block_encrypt(aes_cfb128, Key, IV, Data),
+    <<IV/binary, Crypt/binary>>.
+
+-spec decrypt_data(binary(), binary()) -> binary().
+decrypt_data(<<IV:16/binary, Crypt/binary>>, Key) ->
+    crypto:block_decrypt(aes_cfb128, Key, IV, Crypt).
+
+-spec gen_key(iolist(), iolist()) -> binary().
+gen_key(ExpirationTime, ServerKey)->
+    crypto:hmac(md5, ServerKey, [ExpirationTime]).
+
+-spec gen_hmac(iolist(), binary(), iolist(), binary()) -> binary().
+gen_hmac(ExpirationTime, Data, SessionKey, Key) ->
+    crypto:hmac(sha, Key, [ExpirationTime, Data, SessionKey]).
+
+-endif.
 
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").