resolve bug with syncing on FTP

This commit is contained in:
Philipp Crocoll 2013-11-22 21:58:32 +01:00
parent 6c7802ab9c
commit 13eedf662a

View File

@ -200,10 +200,16 @@ namespace keepass2android.Io
public MemoryStream GetRemoteDataAndHash(IOConnectionInfo ioc, out string hash)
{
MemoryStream remoteData = new MemoryStream();
using (
HashingStreamEx hashingRemoteStream = new HashingStreamEx(_cachedStorage.OpenFileForRead(ioc), false,
new SHA256Managed()))
using (var remoteStream =_cachedStorage.OpenFileForRead(ioc))
{
//note: directly copying to remoteData and hashing causes NullReferenceExceptions in FTP and with Digest auth
// -> use the temp data approach:
MemoryStream tempData = new MemoryStream();
remoteStream.CopyTo(tempData);
tempData.Position = 0;
HashingStreamEx hashingRemoteStream = new HashingStreamEx(tempData, false, new SHA256Managed());
hashingRemoteStream.CopyTo(remoteData);
hashingRemoteStream.Close();
hash = MemUtil.ByteArrayToHexString(hashingRemoteStream.Hash);