Skip to content

Commit ed4d320

Browse files
author
Geoffroy BONNEVILLE
committed
Populated readme file
Removed version check for XML writes
1 parent 2239169 commit ed4d320

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

ModernKeePassLib.Test/ModernKeePassLib.Test.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>
20-
<PackageReference Include="Splat" Version="3.0.0" />
21-
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
2220
</ItemGroup>
2321

2422
<ItemGroup>

ModernKeePassLib.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernKeePassLib.Test", "Mo
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernKeePassLib", "ModernKeePassLib\ModernKeePassLib.csproj", "{85C3EA08-C9C4-4A8E-AB52-BE8A6475B787}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2390E567-E65A-43C1-9D07-6680296D1BE0}"
11+
ProjectSection(SolutionItems) = preProject
12+
.gitignore = .gitignore
13+
README.md = README.md
14+
EndProjectSection
15+
EndProject
1016
Global
1117
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1218
Debug|Any CPU = Debug|Any CPU

ModernKeePassLib/ModernKeePassLib.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard1.2</TargetFramework>
55
<Description>Portable KeePass Password Management Library that targets .Net Standard and WinRT. Allows reading, editing and writing to KeePass 2.x databases.</Description>
6-
<Version>2.44.2</Version>
6+
<Version>2.44.3</Version>
77
<Authors>Geoffroy Bonneville</Authors>
88
<Company>wismna</Company>
99
<PackageProjectUrl>https://github.com/wismna/ModernKeePass</PackageProjectUrl>
@@ -55,7 +55,7 @@
5555
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
5656
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0005" />
5757
<PackageReference Include="Splat" Version="3.0.0" />
58-
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.3.0" />
58+
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
5959
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
6060
</ItemGroup>
6161

ModernKeePassLib/Serialization/KdbxFile.Write.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void Save(Stream sSaveTo, PwGroup pgDataSource, KdbxFormat fmt,
204204
throw new ArgumentOutOfRangeException("fmt");
205205
}
206206

207-
m_xmlWriter = XmlUtilEx.CreateXmlWriter(sXml, m_uFileVersion >= FileVersion32_4);
207+
m_xmlWriter = XmlUtilEx.CreateXmlWriter(sXml);
208208

209209
WriteDocument(pgRoot);
210210

ModernKeePassLib/Utility/XmlUtilEx.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public static XmlDocument CreateXmlDocument()
3434
{
3535
XmlDocument d = new XmlDocument();
3636

37-
// .NET 4.5.2 and newer do not resolve external XML resources
38-
// by default; for older .NET versions, we explicitly
39-
// prevent resolving
37+
// .NET 4.5.2 and newer do not resolve external XML resources
38+
// by default; for older .NET versions, we explicitly
39+
// prevent resolving
4040
#if !ModernKeePassLib
41-
d.XmlResolver = null; // Default in old .NET: XmlUrlResolver object
41+
d.XmlResolver = null; // Default in old .NET: XmlUrlResolver object
4242
#endif
4343

4444
return d;
@@ -74,28 +74,24 @@ public static XmlReader CreateXmlReader(Stream s)
7474
return XmlReader.Create(s, CreateXmlReaderSettings());
7575
}
7676

77-
public static XmlWriterSettings CreateXmlWriterSettings(bool isVersionGreaterThan4 = false)
77+
public static XmlWriterSettings CreateXmlWriterSettings()
7878
{
7979
XmlWriterSettings xws = new XmlWriterSettings();
8080

81-
xws.CloseOutput = isVersionGreaterThan4;
81+
xws.CloseOutput = false;
8282
xws.Encoding = StrUtil.Utf8;
8383
xws.Indent = true;
8484
xws.IndentChars = "\t";
8585
xws.NewLineOnAttributes = false;
86-
#if ModernKeePassLib
87-
// This is needed for Argon2Kdf write
88-
xws.Async = true;
89-
#endif
9086

9187
return xws;
9288
}
9389

94-
public static XmlWriter CreateXmlWriter(Stream s, bool isVersionGreaterThan4 = false)
90+
public static XmlWriter CreateXmlWriter(Stream s)
9591
{
9692
if(s == null) { Debug.Assert(false); throw new ArgumentNullException("s"); }
9793

98-
return XmlWriter.Create(s, CreateXmlWriterSettings(isVersionGreaterThan4));
94+
return XmlWriter.Create(s, CreateXmlWriterSettings());
9995
}
10096

10197
public static void Serialize<T>(Stream s, T t)

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
## ModernKeePassLib
22

3-
[![Build status](https://dev.azure.com/geogeob/ModernKeePass/_apis/build/status/Builds/ModernKeePassLib)](https://dev.azure.com/geogeob/ModernKeePass/_build/latest?definitionId=6)
3+
[![Build status](https://dev.azure.com/geogeob/ModernKeePass/_apis/build/status/Builds/ModernKeePassLib)](https://dev.azure.com/geogeob/ModernKeePass/_build/latest?definitionId=6)
4+
5+
# What is this ?
6+
7+
ModernKeePassLib is a port of KeePassLib to .netstandard 1.2, distributed as a nuget package.
8+
The aim was to change as little as possible the original library. However, some workarounds have to be made as .netstandard misses quite a few features of the full .net framework.
9+
Main changes:
10+
- Removed the dependency on the filesystem
11+
- Added a dependency on Windows (I'm working on tring to find a way to remove it altogether)
12+
- Some features are handled by external nuget packages (cryptography, colors, etc.), so it may introduce small differences
13+
14+
# Usage
15+
16+
1. Create a IOConnectionInfo from a byte array:
17+
`var ioConnection = IOConnectionInfo.FromByteArray(file);`
18+
2. Create a composite key and add credential information:
19+
`var compositeKey = new CompositeKey();
20+
// Password
21+
compositeKey.AddUserKey(new KcpPassword("Password"));`
22+
// Key file
23+
compositeKey.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromByteArray(KeyFileContents)));`
24+
3. Use it to open the database:
25+
// You may use whatever logger you choose (here, I use nullstatuslogger)
26+
`PwDatabase.Open(ioConnection, compositeKey, new NullStatusLogger());`
27+
4. Do stuff in you database (create entries, groups, ...)
28+
5. Save your changes:
29+
`PwDatabase.Save(new NullStatusLogger());`
30+
6. At this point, nothing is commited to disk, so you need to retrieve the byte array:
31+
`var contents = PwDatabase.IOConnectionInfo.Bytes;`
32+
7. Write the byte array to a file, to a stream, whatever !

0 commit comments

Comments
 (0)