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

[couchdb] 01/01: Update usage of couch_hash:md5 shim

This is an automated email from the ASF dual-hosted git repository.

willholley pushed a commit to branch couch_hash_update
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit d7fa94e98b74da147a2b9d6630ffdce7ecea68a6
Author: Will Holley <wi...@gmail.com>
AuthorDate: Mon Dec 2 08:01:57 2019 +0000

    Update usage of couch_hash:md5 shim
    
    https://github.com/apache/couchdb/pull/1445 introduced a shim to
    enable CouchDB to be compiled to use the Erlang MD5 function.
    This allows CouchDB to run in FIPS environments where the crypto
    module is restricted such that `crypto:hash(md5,..)` is blocked
    (fails with `notsup` error).
    
    This commit replaces usage of `crypto:hash(md5, ..)` introduced since
    the original PR with the shim function.
---
 src/couch_mrview/test/eunit/couch_mrview_purge_docs_tests.erl | 2 +-
 src/couch_pse_tests/src/cpse_test_purge_docs.erl              | 4 ++--
 src/couch_pse_tests/src/cpse_test_purge_seqs.erl              | 2 +-
 src/couch_pse_tests/src/cpse_util.erl                         | 4 ++--
 src/dreyfus/src/dreyfus_index.erl                             | 4 ++--
 src/fabric/test/eunit/fabric_rpc_purge_tests.erl              | 2 +-
 6 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/couch_mrview/test/eunit/couch_mrview_purge_docs_tests.erl b/src/couch_mrview/test/eunit/couch_mrview_purge_docs_tests.erl
index 1020607..d62dae7 100644
--- a/src/couch_mrview/test/eunit/couch_mrview_purge_docs_tests.erl
+++ b/src/couch_mrview/test/eunit/couch_mrview_purge_docs_tests.erl
@@ -139,7 +139,7 @@ test_purge_partial(Db) ->
         FDI1 = couch_db:get_full_doc_info(Db, <<"1">>), Rev1 = get_rev(FDI1),
         Update = {[
             {'_id', <<"1">>},
-            {'_rev', couch_doc:rev_to_str({1, [crypto:hash(md5, <<"1.2">>)]})},
+            {'_rev', couch_doc:rev_to_str({1, [couch_hash:md5(<<"1.2">>)]})},
             {'val', 1.2}
         ]},
         {ok, [_Rev2]} = save_docs(Db, [Update], [replicated_changes]),
diff --git a/src/couch_pse_tests/src/cpse_test_purge_docs.erl b/src/couch_pse_tests/src/cpse_test_purge_docs.erl
index 1788eec..3e3af44 100644
--- a/src/couch_pse_tests/src/cpse_test_purge_docs.erl
+++ b/src/couch_pse_tests/src/cpse_test_purge_docs.erl
@@ -253,7 +253,7 @@ cpse_purge_partial_revs(DbName) ->
     {ok, Rev1} = cpse_util:save_doc(DbName, {[{'_id', foo}, {vsn, <<"1.1">>}]}),
     Update = {[
         {'_id', foo},
-        {'_rev', couch_doc:rev_to_str({1, [crypto:hash(md5, <<"1.2">>)]})},
+        {'_rev', couch_doc:rev_to_str({1, [couch_hash:md5(<<"1.2">>)]})},
         {vsn, <<"1.2">>}
     ]},
     {ok, [_Rev2]} = cpse_util:save_docs(DbName, [Update], [replicated_changes]),
@@ -392,7 +392,7 @@ cpse_purge_repeated_revisions(DbName) ->
     {ok, Rev1} = cpse_util:save_doc(DbName, {[{'_id', foo}, {vsn, <<"1.1">>}]}),
     Update = {[
         {'_id', foo},
-        {'_rev', couch_doc:rev_to_str({1, [crypto:hash(md5, <<"1.2">>)]})},
+        {'_rev', couch_doc:rev_to_str({1, [couch_hash:md5(<<"1.2">>)]})},
         {vsn, <<"1.2">>}
     ]},
     {ok, [Rev2]} = cpse_util:save_docs(DbName, [Update], [replicated_changes]),
diff --git a/src/couch_pse_tests/src/cpse_test_purge_seqs.erl b/src/couch_pse_tests/src/cpse_test_purge_seqs.erl
index f363b76..2c8bd61 100644
--- a/src/couch_pse_tests/src/cpse_test_purge_seqs.erl
+++ b/src/couch_pse_tests/src/cpse_test_purge_seqs.erl
@@ -101,7 +101,7 @@ cpse_increment_purge_seq_on_partial_purge(DbName) ->
     {ok, Rev1} = cpse_util:save_doc(DbName, {[{'_id', foo1}, {vsn, <<"1.1">>}]}),
     Update = {[
         {'_id', foo1},
-        {'_rev', couch_doc:rev_to_str({1, [crypto:hash(md5, <<"1.2">>)]})},
+        {'_rev', couch_doc:rev_to_str({1, [couch_hash:md5(<<"1.2">>)]})},
         {vsn, <<"1.2">>}
     ]},
     {ok, [_Rev2]} = cpse_util:save_docs(DbName, [Update], [replicated_changes]),
diff --git a/src/couch_pse_tests/src/cpse_util.erl b/src/couch_pse_tests/src/cpse_util.erl
index f8f6a19..bd9279d 100644
--- a/src/couch_pse_tests/src/cpse_util.erl
+++ b/src/couch_pse_tests/src/cpse_util.erl
@@ -371,11 +371,11 @@ gen_write(Db, {Action, {DocId, Body, Atts}}) ->
 
 
 gen_rev(A, DocId, {Pos, Rev}, Body, Atts) when A == update; A == delete ->
-    NewRev = crypto:hash(md5, term_to_binary({DocId, Rev, Body, Atts})),
+    NewRev = couch_hash:md5(term_to_binary({DocId, Rev, Body, Atts})),
     {Pos + 1, [NewRev, Rev]};
 gen_rev(conflict, DocId, _, Body, Atts) ->
     UUID = couch_uuids:random(),
-    NewRev = crypto:hash(md5, term_to_binary({DocId, UUID, Body, Atts})),
+    NewRev = couch_hash:md5(term_to_binary({DocId, UUID, Body, Atts})),
     {1, [NewRev]}.
 
 
diff --git a/src/dreyfus/src/dreyfus_index.erl b/src/dreyfus/src/dreyfus_index.erl
index e33a208..b21145c 100644
--- a/src/dreyfus/src/dreyfus_index.erl
+++ b/src/dreyfus/src/dreyfus_index.erl
@@ -197,7 +197,7 @@ handle_info({'EXIT', FromPid, {updated, NewSeq}},
                 nil;
             false ->
                 spawn_link(fun() ->
-                    dreyfus_index_updater:update(IndexPid, Index) 
+                    dreyfus_index_updater:update(IndexPid, Index)
                 end)
         end,
         {noreply, State#state{index=Index,
@@ -274,7 +274,7 @@ design_doc_to_index(#doc{id=Id,body={Fields}}, IndexName) ->
                 undefined ->
                     {error, InvalidDDocError};
                 Def ->
-                    Sig = ?l2b(couch_util:to_hex(crypto:hash(md5,
+                    Sig = ?l2b(couch_util:to_hex(couch_hash:md5(
                         term_to_binary({Analyzer, Def})))),
                     {ok, #index{
                         analyzer=Analyzer,
diff --git a/src/fabric/test/eunit/fabric_rpc_purge_tests.erl b/src/fabric/test/eunit/fabric_rpc_purge_tests.erl
index 4eafb2b..de0c7c8 100644
--- a/src/fabric/test/eunit/fabric_rpc_purge_tests.erl
+++ b/src/fabric/test/eunit/fabric_rpc_purge_tests.erl
@@ -241,7 +241,7 @@ create_update(Doc, NewVsn) ->
         body = {Props}
     } = Doc,
     NewProps = lists:keyreplace(<<"vsn">>, 1, Props, {<<"vsn">>, NewVsn}),
-    NewRev = crypto:hash(md5, term_to_binary({DocId, Rev, {NewProps}})),
+    NewRev = couch_hash:md5(term_to_binary({DocId, Rev, {NewProps}})),
     Doc#doc{
         revs = {Pos + 1, [NewRev | Revs]},
         body = {NewProps}