mirror of
https://github.com/moparisthebest/keepass2android
synced 2025-01-30 06:30:20 -05:00
Strictly for experimentation. When saving a databse, it will be saved in protocol buffer format. Opening will work for either xml or protocol buffers.
This commit is contained in:
parent
0b1f372a02
commit
41e9c80456
@ -47,6 +47,9 @@
|
||||
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="protobuf-net">
|
||||
<HintPath>..\ProtoBuf\protobuf-net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
@ -126,6 +129,7 @@
|
||||
<Compile Include="Serialization\KdbxFile.Write.cs" />
|
||||
<Compile Include="Serialization\IOConnectionInfo.cs" />
|
||||
<Compile Include="Serialization\OldFormatException.cs" />
|
||||
<Compile Include="Serialization\ProtoBuf\KdbpFile.cs" />
|
||||
<Compile Include="Translation\KPControlCustomization.cs" />
|
||||
<Compile Include="Translation\KPFormCustomization.cs" />
|
||||
<Compile Include="Translation\KPStringTable.cs" />
|
||||
|
@ -127,8 +127,34 @@ namespace KeePassLib.Serialization
|
||||
}
|
||||
else m_randomStream = null; // No random stream for plain-text files
|
||||
|
||||
ReadXmlStreamed(readerStream, hashedStream);
|
||||
// ReadXmlDom(readerStream);
|
||||
// Test: read to memory
|
||||
var stopWatch = Stopwatch.StartNew();
|
||||
var memStream = new MemoryStream((int)hashedStream.Length);
|
||||
CopyStream(readerStream, memStream);
|
||||
readerStream.Close();
|
||||
readerStream = memStream;
|
||||
System.Diagnostics.Debug.WriteLine(String.Format("Copy input stream: {0}ms", stopWatch.ElapsedMilliseconds));
|
||||
|
||||
var isXml = memStream.ReadByte() == '<';
|
||||
memStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
if (isXml)
|
||||
{
|
||||
stopWatch.Restart();
|
||||
|
||||
ReadXmlStreamed(readerStream, hashedStream);
|
||||
System.Diagnostics.Debug.WriteLine(String.Format("ReadXmlStreamed: {0}ms", stopWatch.ElapsedMilliseconds));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
stopWatch.Restart();
|
||||
|
||||
KdbpFile.ReadDocument(m_pwDatabase, readerStream, m_pbProtectedStreamKey, m_pbHashOfHeader);
|
||||
|
||||
System.Diagnostics.Debug.WriteLine(String.Format("KdbpFile.ReadDocument: {0}ms", stopWatch.ElapsedMilliseconds));
|
||||
|
||||
}
|
||||
|
||||
readerStream.Close();
|
||||
// GC.KeepAlive(br);
|
||||
@ -141,6 +167,17 @@ namespace KeePassLib.Serialization
|
||||
finally { CommonCleanUpRead(sSource, hashedStream); }
|
||||
}
|
||||
|
||||
public static void CopyStream(Stream input, Stream output)
|
||||
{
|
||||
byte[] buffer = new byte[4096];
|
||||
int read;
|
||||
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
output.Write(buffer, 0, read);
|
||||
}
|
||||
output.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
private void CommonCleanUpRead(Stream sSource, HashingStreamEx hashedStream)
|
||||
{
|
||||
hashedStream.Close();
|
||||
|
@ -122,11 +122,16 @@ namespace KeePassLib.Serialization
|
||||
writerStream = hashedStream;
|
||||
else { Debug.Assert(false); throw new FormatException("KdbFormat"); }
|
||||
|
||||
/*
|
||||
m_xmlWriter = new XmlTextWriter(writerStream, encNoBom);
|
||||
WriteDocument(pgDataSource);
|
||||
|
||||
m_xmlWriter.Flush();
|
||||
m_xmlWriter.Close();
|
||||
*/
|
||||
|
||||
KdbpFile.WriteDocument(m_pwDatabase, writerStream, m_pbProtectedStreamKey, m_pbHashOfHeader);
|
||||
|
||||
writerStream.Close();
|
||||
}
|
||||
finally { CommonCleanUpWrite(sSaveTo, hashedStream); }
|
||||
|
1425
src/KeePassLib2Android/Serialization/ProtoBuf/KdbpFile.cs
Normal file
1425
src/KeePassLib2Android/Serialization/ProtoBuf/KdbpFile.cs
Normal file
File diff suppressed because it is too large
Load Diff
BIN
src/ProtoBuf/protobuf-net.dll
Normal file
BIN
src/ProtoBuf/protobuf-net.dll
Normal file
Binary file not shown.
BIN
src/ProtoBuf/protobuf-net.pdb
Normal file
BIN
src/ProtoBuf/protobuf-net.pdb
Normal file
Binary file not shown.
2747
src/ProtoBuf/protobuf-net.xml
Normal file
2747
src/ProtoBuf/protobuf-net.xml
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user