Write-mode is finally working!!!

Lib uses BouncyCastle crypto
This commit is contained in:
2017-09-26 14:32:15 +02:00
parent 22ea657885
commit 27aaa8023a
22 changed files with 133 additions and 178 deletions

View File

@@ -129,7 +129,7 @@ namespace ModernKeePassLibPCL.Serialization
try
{
if(s == null) return null;
using (var sr = new StreamReader(s.AsStream(), StrUtil.Utf8))
using (var sr = new StreamReader(s, StrUtil.Utf8))
{
string str = sr.ReadToEnd();
if (str == null)
@@ -179,7 +179,7 @@ namespace ModernKeePassLibPCL.Serialization
{
byte[] pbFile = StrUtil.Utf8.GetBytes(sb.ToString());
if (s == null) throw new IOException(iocLockFile.GetDisplayName());
s.WriteAsync(pbFile.AsBuffer()).GetAwaiter().GetResult();
s.WriteAsync(pbFile, 0, pbFile.Length).GetAwaiter().GetResult();
}
return lfi;

View File

@@ -79,7 +79,7 @@ namespace ModernKeePassLibPCL.Serialization
else m_iocTemp = m_iocBase;
}
public IRandomAccessStream OpenWrite()
public Stream OpenWrite()
{
if(!m_bTransacted) m_bMadeUnhidden = UrlUtil.UnhideFile(m_iocTemp.Path);
else // m_bTransacted
@@ -100,7 +100,7 @@ namespace ModernKeePassLibPCL.Serialization
}
}
private async void CommitWriteTransaction()
private void CommitWriteTransaction()
{
bool bMadeUnhidden = UrlUtil.UnhideFile(m_iocBase.Path);

View File

@@ -422,7 +422,7 @@ namespace ModernKeePassLibPCL.Serialization
new Uri(ioc.Path)));
}
#else
public static IRandomAccessStream OpenRead(IOConnectionInfo ioc)
public static Stream OpenRead(IOConnectionInfo ioc)
{
RaiseIOAccessPreEvent(ioc, IOAccessType.Read);
@@ -430,9 +430,9 @@ namespace ModernKeePassLibPCL.Serialization
}
#endif
private static IRandomAccessStream OpenReadLocal(IOConnectionInfo ioc)
private static Stream OpenReadLocal(IOConnectionInfo ioc)
{
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetAwaiter().GetResult();
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetAwaiter().GetResult().AsStream();
}
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
@@ -458,7 +458,7 @@ namespace ModernKeePassLibPCL.Serialization
return IocStream.WrapIfRequired(s);
}
#else
public static IRandomAccessStream OpenWrite(IOConnectionInfo ioc)
public static Stream OpenWrite(IOConnectionInfo ioc)
{
RaiseIOAccessPreEvent(ioc, IOAccessType.Write);
@@ -466,9 +466,9 @@ namespace ModernKeePassLibPCL.Serialization
}
#endif
private static IRandomAccessStream OpenWriteLocal(IOConnectionInfo ioc)
private static Stream OpenWriteLocal(IOConnectionInfo ioc)
{
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetAwaiter().GetResult();
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetAwaiter().GetResult().AsStream();
}
public static bool FileExists(IOConnectionInfo ioc)
@@ -546,7 +546,7 @@ namespace ModernKeePassLibPCL.Serialization
#endif
public static byte[] ReadFile(IOConnectionInfo ioc)
{
IRandomAccessStream sIn = null;
Stream sIn = null;
MemoryStream ms = null;
try
{
@@ -555,7 +555,7 @@ namespace ModernKeePassLibPCL.Serialization
ms = new MemoryStream();
MemUtil.CopyStream(sIn.AsStream(), ms);
MemUtil.CopyStream(sIn, ms);
return ms.ToArray();
}

View File

@@ -71,7 +71,7 @@ namespace ModernKeePassLibPCL.Serialization
/// a KDBX stream.</param>
/// <param name="kdbFormat">Format specifier.</param>
/// <param name="slLogger">Status logger (optional).</param>
public void Load(IRandomAccessStream sSource, KdbxFormat kdbFormat, IStatusLogger slLogger)
public void Load(Stream sSource, KdbxFormat kdbFormat, IStatusLogger slLogger)
{
Debug.Assert(sSource != null);
if(sSource == null) throw new ArgumentNullException("sSource");
@@ -79,7 +79,7 @@ namespace ModernKeePassLibPCL.Serialization
m_format = kdbFormat;
m_slLogger = slLogger;
HashingStreamEx hashedStream = new HashingStreamEx(sSource.AsStream(), false, null);
HashingStreamEx hashedStream = new HashingStreamEx(sSource, false, null);
UTF8Encoding encNoBom = StrUtil.Utf8;
try
@@ -165,7 +165,7 @@ namespace ModernKeePassLibPCL.Serialization
finally { CommonCleanUpRead(sSource, hashedStream); }
}
private void CommonCleanUpRead(IRandomAccessStream sSource, HashingStreamEx hashedStream)
private void CommonCleanUpRead(Stream sSource, HashingStreamEx hashedStream)
{
hashedStream.Dispose();
m_pbHashOfFileOnDisk = hashedStream.Hash;
@@ -376,7 +376,7 @@ namespace ModernKeePassLibPCL.Serialization
}
[Obsolete]
public static List<PwEntry> ReadEntries(PwDatabase pwDatabase, IRandomAccessStream msData)
public static List<PwEntry> ReadEntries(PwDatabase pwDatabase, Stream msData)
{
return ReadEntries(msData);
}
@@ -386,7 +386,7 @@ namespace ModernKeePassLibPCL.Serialization
/// </summary>
/// <param name="msData">Input stream to read the entries from.</param>
/// <returns>Extracted entries.</returns>
public static List<PwEntry> ReadEntries(IRandomAccessStream msData)
public static List<PwEntry> ReadEntries(Stream msData)
{
/* KdbxFile f = new KdbxFile(pwDatabase);
f.m_format = KdbxFormat.PlainXml;

View File

@@ -77,7 +77,7 @@ namespace ModernKeePassLibPCL.Serialization
/// be written.</param>
/// <param name="format">Format of the file to create.</param>
/// <param name="slLogger">Logger that recieves status information.</param>
public void Save(IRandomAccessStream sSaveTo, PwGroup pgDataSource, KdbxFormat format,
public void Save(Stream sSaveTo, PwGroup pgDataSource, KdbxFormat format,
IStatusLogger slLogger)
{
Debug.Assert(sSaveTo != null);
@@ -86,7 +86,7 @@ namespace ModernKeePassLibPCL.Serialization
m_format = format;
m_slLogger = slLogger;
HashingStreamEx hashedStream = new HashingStreamEx(sSaveTo.AsStream(), true, null);
HashingStreamEx hashedStream = new HashingStreamEx(sSaveTo, true, null);
UTF8Encoding encNoBom = StrUtil.Utf8;
CryptoRandom cr = CryptoRandom.Instance;
@@ -146,7 +146,7 @@ namespace ModernKeePassLibPCL.Serialization
finally { CommonCleanUpWrite(sSaveTo, hashedStream); }
}
private void CommonCleanUpWrite(IRandomAccessStream sSaveTo, HashingStreamEx hashedStream)
private void CommonCleanUpWrite(Stream sSaveTo, HashingStreamEx hashedStream)
{
hashedStream.Dispose();
m_pbHashOfFileOnDisk = hashedStream.Hash;
@@ -836,7 +836,7 @@ namespace ModernKeePassLibPCL.Serialization
}
[Obsolete]
public static bool WriteEntries(IRandomAccessStream msOutput, PwDatabase pwDatabase,
public static bool WriteEntries(Stream msOutput, PwDatabase pwDatabase,
PwEntry[] vEntries)
{
return WriteEntries(msOutput, vEntries);
@@ -849,7 +849,7 @@ namespace ModernKeePassLibPCL.Serialization
/// <param name="vEntries">Entries to serialize.</param>
/// <returns>Returns <c>true</c>, if the entries were written successfully
/// to the stream.</returns>
public static bool WriteEntries(IRandomAccessStream msOutput, PwEntry[] vEntries)
public static bool WriteEntries(Stream msOutput, PwEntry[] vEntries)
{
/* KdbxFile f = new KdbxFile(pwDatabase);
f.m_format = KdbxFormat.PlainXml;