diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2010-05-04 20:46:42 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2010-05-04 20:46:42 +0000 |
commit | d7d047f439880735377a4b8ea2ce2ef42921fff8 (patch) | |
tree | bfe733b55bcca11f6ccd30f9cea70e8800ca7b3c /src/couchdb/couch_file.erl | |
parent | 33b3524268195a0798993690b54cead286da28fb (diff) |
use crypto:md5 when available. thx fdmanana. Closes COUCHDB-757
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@941033 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_file.erl')
-rw-r--r-- | src/couchdb/couch_file.erl | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl index 4c6928a7..64a9ed7b 100644 --- a/src/couchdb/couch_file.erl +++ b/src/couchdb/couch_file.erl @@ -89,7 +89,7 @@ append_binary(Fd, Bin) -> append_binary_md5(Fd, Bin) -> Size = iolist_size(Bin), gen_server:call(Fd, {append_bin, - [<<1:1/integer,Size:31/integer>>, erlang:md5(Bin), Bin]}, infinity). + [<<1:1/integer,Size:31/integer>>, couch_util:md5(Bin), Bin]}, infinity). %%---------------------------------------------------------------------- @@ -124,7 +124,7 @@ pread_iolist(Fd, Pos) -> {ok, Md5List, ValPos} = read_raw_iolist(Fd, NextPos, 16), Md5 = iolist_to_binary(Md5List), {ok, IoList, _} = read_raw_iolist(Fd,ValPos,Len), - case erlang:md5(IoList) of + case couch_util:md5(IoList) of Md5 -> ok; _ -> throw(file_corruption) end, @@ -212,7 +212,7 @@ read_header(Fd) -> write_header(Fd, Data) -> Bin = term_to_binary(Data), - Md5 = erlang:md5(Bin), + Md5 = couch_util:md5(Bin), % now we assemble the final header binary and write to disk FinalBin = <<Md5/binary, Bin/binary>>, gen_server:call(Fd, {write_header, FinalBin}, infinity). @@ -314,7 +314,7 @@ handle_call({upgrade_old_header, Prefix}, _From, #file{fd=Fd}=File) -> {ok, Header} -> {ok, TailAppendBegin} = file:position(Fd, eof), Bin = term_to_binary(Header), - Md5 = erlang:md5(Bin), + Md5 = couch_util:md5(Bin), % now we assemble the final header binary and write to disk FinalBin = <<Md5/binary, Bin/binary>>, {reply, ok, _} = handle_call({write_header, FinalBin}, ok, File), @@ -395,7 +395,7 @@ extract_header(Prefix, Bin) -> case HeaderPrefix of Prefix -> % check the integrity signature - case erlang:md5(TermBin) == Sig of + case couch_util:md5(TermBin) == Sig of true -> Header = binary_to_term(TermBin), {ok, Header}; @@ -425,7 +425,7 @@ write_old_header(Fd, Prefix, Data) -> ok = file:sync(Fd), % pad out the header with zeros, then take the md5 hash PadZeros = <<0:(8*(?HEADER_SIZE - FilledSize2))>>, - Sig = erlang:md5([TermBin2, PadZeros]), + Sig = couch_util:md5([TermBin2, PadZeros]), % now we assemble the final header binary and write to disk WriteBin = <<Prefix/binary, TermBin2/binary, PadZeros/binary, Sig/binary>>, ?HEADER_SIZE = size(WriteBin), % sanity check @@ -465,7 +465,7 @@ load_header(Fd, Block) -> file:pread(Fd, (Block*?SIZE_BLOCK) + 5, TotalBytes), <<Md5Sig:16/binary, HeaderBin/binary>> = iolist_to_binary(remove_block_prefixes(1, RawBin)), - Md5Sig = erlang:md5(HeaderBin), + Md5Sig = couch_util:md5(HeaderBin), {ok, HeaderBin}. calculate_total_read_len(0, FinalLen) -> |