Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2027B10ACE for ; Thu, 13 Feb 2014 16:07:25 +0000 (UTC) Received: (qmail 1981 invoked by uid 500); 13 Feb 2014 16:06:34 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 1326 invoked by uid 500); 13 Feb 2014 16:06:14 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 592 invoked by uid 99); 13 Feb 2014 16:05:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Feb 2014 16:05:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 600D0925CD6; Thu, 13 Feb 2014 16:05:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: benoitc@apache.org To: commits@couchdb.apache.org Date: Thu, 13 Feb 2014 16:06:08 -0000 Message-Id: <142b02e6b10a4c79841f0477163085d6@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Tue Jul 16 11:06:56 2013 -0400 Committer: Fred Hebert 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), + <>. + +-spec decrypt_data(binary(), binary()) -> binary(). +decrypt_data(<>, 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").