Skip to content

Commit 148af1e

Browse files
authored
Merge pull request #7 from shugaoye/master
Release 1.2.3
2 parents 6af1612 + 316d757 commit 148af1e

File tree

14 files changed

+482
-61
lines changed

14 files changed

+482
-61
lines changed

KPCLib.nuspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>KPCLib</id>
5-
<version>1.2.2.8</version>
5+
<version>1.2.3.0</version>
66
<authors>Roger Ye</authors>
77
<owners>Roger Ye</owners>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>
99
<license type="expression">LGPL-3.0-or-later</license>
1010
<projectUrl>https://github.com/passxyz/KPCLib</projectUrl>
1111
<description>This is the build of KeePassLib in Xamarin Portable Class Library. Three platforms, UWP, Android and iOS, are supported and tested.</description>
12-
<releaseNotes>-Support Markdown in Notes field
13-
- Support PassXYZ data format</releaseNotes>
14-
<copyright>Dominik Reichl is the author of the original KeePassLib on Windows platform. Roger Ye created this for UWP, Android and iOS platforms.</copyright>
12+
<releaseNotes>- Support OTP</releaseNotes>
13+
<copyright>Dominik Reichl is the author of the original KeePassLib on Windows platform. Roger Ye updated and enhanced this library for .NET Standard.</copyright>
1514
<repository url="https://github.com/passxyz/KPCLib" />
1615
<dependencies>
1716
<group targetFramework=".NETStandard2.0">
1817
<dependency id="SkiaSharp" version="1.68.0" exclude="Build,Analyzers" />
18+
<dependency id="PureOtp" version="1.0.0.8" exclude="Build,Analyzers" />
1919
</group>
2020
</dependencies>
21-
<summary>A library to be built as .NET Standard Library to be used for Android, iOS and UWP</summary>
21+
<summary>KeePassLib built as .NET Standard Library</summary>
2222
</metadata>
2323
<files>
2424
<file src="PassXYZLib/bin/Release/netstandard2.0/KPCLib.dll" target="lib/netstandard2.0/KPCLib.dll" />

KPCLib.xunit/PassXYZLibTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,48 @@ public void IsOpenDbTest()
6262
Assert.True((passxyz.PxDb.IsOpen));
6363
}
6464

65+
[Fact]
66+
public void ListItemsTests()
67+
{
68+
PwGroup pg = passxyz.PxDb.RootGroup;
69+
foreach (var item in pg.Items)
70+
{
71+
if(item.IsGroup)
72+
{
73+
Debug.WriteLine($"{item.Description}\t{item.Name}/");
74+
}
75+
else
76+
{
77+
Debug.WriteLine($"{item.Description}\t{item.Name}");
78+
}
79+
}
80+
}
81+
82+
[Fact (Skip = "test manually")]
83+
/// <summary>
84+
/// This test computes a token using a secret.
85+
/// The result can be verified at the below website:
86+
/// https://totp.danhersam.com/
87+
/// </summary>
88+
public void TokenGenerateTests()
89+
{
90+
var entry = new PwEntry();
91+
if (entry.Totp == null)
92+
{
93+
entry.UpdateOtpUrl("otpauth://totp/Google%3Apxentry_test%40gmail.com?secret=JBSWY3DPEHPK3PXP&issuer=Google");
94+
var Totp = entry.Totp;
95+
Debug.WriteLine($"Token={entry.Token}\tProgress={entry.Progress}");
96+
Assert.NotNull(Totp);
97+
}
98+
99+
int i = 0;
100+
for (i = 0; i < 30; i++)
101+
{
102+
Debug.WriteLine($"Token={entry.Token}\tProgress={entry.Progress}");
103+
System.Threading.Thread.Sleep(3000);
104+
}
105+
}
106+
65107
[Fact]
66108
public void CurrentGroupTests()
67109
{

KPCLib.xunit/PxDatabaseTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void ListGroupsTests()
6767
}
6868
}
6969

70+
7071
[Fact]
7172
public void ListEntriesTests()
7273
{

KPCLib.xunit/PxEntryTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
using Xunit;
9+
10+
using PureOtp;
11+
using PassXYZLib;
12+
13+
namespace KPCLib.xunit
14+
{
15+
public class PxEntryTests
16+
{
17+
[Fact]
18+
public void PxEntryInitTests()
19+
{
20+
var entry = new PxEntry();
21+
Assert.NotNull(entry);
22+
}
23+
}
24+
}

KPCLib/KPCLib.csproj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<OutputType>Library</OutputType>
77
<StartupObject />
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
9-
<Version>1.2.2.9</Version>
10-
<PackageLicenseUrl>https://github.com/passxyz/KPCLib/blob/master/LICENSE</PackageLicenseUrl>
9+
<Version>1.2.3.0</Version>
1110
<PackageProjectUrl>https://github.com/passxyz/KPCLib</PackageProjectUrl>
1211
<RepositoryUrl>https://github.com/passxyz/KPCLib</RepositoryUrl>
1312
<Description>This is the build of KeePassLib in Xamarin Portable Class Library. Three platforms, UWP, Android and iOS, are supported and tested.</Description>
1413
<Copyright>Dominik Reichl is the author of the original KeePassLib on Windows platform. Roger Ye created this for UWP, Android and iOS platforms.</Copyright>
1514
<Authors>Roger Ye</Authors>
1615
<Company>PassXYZ Inc.</Company>
17-
<PackageReleaseNotes>1.2.2 - Release PassXYZLib
16+
<PackageReleaseNotes>1.2.3 - OTP support
17+
1.2.2 - Release PassXYZLib
1818
1.2.0 - Enhanced KeePassLib
1919
1.1.9 - Removed dependency Xamarin.Forms
2020
1.1.8 - Replaced Splat with SkiaSharp.
@@ -23,8 +23,8 @@
2323

2424
1.1.6 - KPCLib has been tested on all three platforms (Android, iOS and UWP).</PackageReleaseNotes>
2525
<NeutralLanguage>en-US</NeutralLanguage>
26-
<AssemblyVersion>1.2.2.9</AssemblyVersion>
27-
<FileVersion>1.2.2.9</FileVersion>
26+
<AssemblyVersion>1.2.3.0</AssemblyVersion>
27+
<FileVersion>1.2.3.0</FileVersion>
2828
</PropertyGroup>
2929

3030
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -36,7 +36,12 @@
3636
</PropertyGroup>
3737

3838
<ItemGroup>
39+
<PackageReference Include="PureOtp" Version="1.0.0.8" />
3940
<PackageReference Include="SkiaSharp" Version="1.68.0" />
4041
</ItemGroup>
4142

43+
<ItemGroup>
44+
<Folder Include="PassXYZLib\" />
45+
</ItemGroup>
46+
4247
</Project>

KPCLib/PassXYZLib/Item.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.ComponentModel;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
8+
namespace KeePassLib
9+
{
10+
/// <summary>
11+
/// A class representing an item. An item can be an entry or a group.
12+
/// Each item has a unique ID (UUID).
13+
/// </summary>
14+
public abstract class Item : INotifyPropertyChanged
15+
{
16+
private PwUuid m_uuid = PwUuid.Zero;
17+
18+
public abstract string Name { get; set; }
19+
20+
public abstract string Description { get;}
21+
22+
public abstract bool IsGroup { get; }
23+
24+
/// <summary>
25+
/// UUID of this item.
26+
/// </summary>
27+
public PwUuid Uuid
28+
{
29+
get { return m_uuid; }
30+
set
31+
{
32+
if (value == null) { Debug.Assert(false); throw new ArgumentNullException("value"); }
33+
m_uuid = value;
34+
}
35+
}
36+
37+
38+
#region INotifyPropertyChanged
39+
protected bool SetProperty<T>(ref T backingStore, T value,
40+
[CallerMemberName] string propertyName = "",
41+
Action onChanged = null)
42+
{
43+
if (EqualityComparer<T>.Default.Equals(backingStore, value))
44+
return false;
45+
46+
backingStore = value;
47+
onChanged?.Invoke();
48+
OnPropertyChanged(propertyName);
49+
return true;
50+
}
51+
52+
public event PropertyChangedEventHandler PropertyChanged;
53+
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
54+
{
55+
var changed = PropertyChanged;
56+
if (changed == null)
57+
return;
58+
59+
changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
60+
}
61+
#endregion
62+
}
63+
}

KPCLib/PassXYZLib/PxEntry.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Text;
5+
6+
using PureOtp;
7+
8+
using KeePassLib;
9+
using KeePassLib.Interfaces;
10+
11+
namespace PassXYZLib
12+
{
13+
public class PxEntry : PwEntry, IDeepCloneable<PxEntry>
14+
{
15+
public PxEntry() : base()
16+
{ }
17+
18+
/// <summary>
19+
/// Construct a new, empty password entry. Member variables will be initialized
20+
/// to their default values.
21+
/// </summary>
22+
/// <param name="bCreateNewUuid">If <c>true</c>, a new UUID will be created
23+
/// for this entry. If <c>false</c>, the UUID is zero and you must set it
24+
/// manually later.</param>
25+
/// <param name="bSetTimes">If <c>true</c>, the creation, last modification
26+
/// and last access times will be set to the current system time.</param>
27+
public PxEntry(bool bCreateNewUuid, bool bSetTimes) : base(bCreateNewUuid, bSetTimes) { }
28+
29+
public PxEntry(PwEntry entry)
30+
{
31+
Uuid = entry.Uuid; // PwUuid is immutable
32+
ParentGroup = entry.ParentGroup;
33+
LocationChanged = entry.LocationChanged;
34+
35+
Strings = entry.Strings.CloneDeep();
36+
Binaries = entry.Binaries.CloneDeep();
37+
AutoType = entry.AutoType.CloneDeep();
38+
History = entry.History.CloneDeep();
39+
40+
IconId = entry.IconId;
41+
CustomIconUuid = entry.CustomIconUuid;
42+
43+
ForegroundColor = entry.ForegroundColor;
44+
BackgroundColor = entry.BackgroundColor;
45+
46+
CreationTime = entry.CreationTime;
47+
LastModificationTime = entry.LastModificationTime;
48+
LastAccessTime = entry.LastAccessTime;
49+
ExpiryTime = entry.ExpiryTime;
50+
Expires = entry.Expires;
51+
UsageCount = entry.UsageCount;
52+
53+
OverrideUrl = entry.OverrideUrl;
54+
55+
Tags = new List<string>(entry.Tags);
56+
57+
CustomData = entry.CustomData.CloneDeep();
58+
}
59+
60+
#if DEBUG
61+
// For display in debugger
62+
public override string ToString()
63+
{
64+
return ("PxEntry '" + Strings.ReadSafe(PwDefs.TitleField) + "'");
65+
}
66+
#endif
67+
68+
/// <summary>
69+
/// Clone the current entry. The returned entry is an exact value copy
70+
/// of the current entry (including UUID and parent group reference).
71+
/// All mutable members are cloned.
72+
/// </summary>
73+
/// <returns>Exact value clone. All references to mutable values changed.</returns>
74+
public new PxEntry CloneDeep()
75+
{
76+
PxEntry peNew = new PxEntry(false, false);
77+
78+
peNew.Uuid = Uuid; // PwUuid is immutable
79+
peNew.ParentGroup = ParentGroup;
80+
peNew.LocationChanged = LocationChanged;
81+
82+
peNew.Strings = Strings.CloneDeep();
83+
peNew.Binaries = Binaries.CloneDeep();
84+
peNew.AutoType = AutoType.CloneDeep();
85+
peNew.History = History.CloneDeep();
86+
87+
peNew.IconId = IconId;
88+
peNew.CustomIconUuid = CustomIconUuid;
89+
90+
peNew.ForegroundColor = ForegroundColor;
91+
peNew.BackgroundColor = BackgroundColor;
92+
93+
peNew.CreationTime = CreationTime;
94+
peNew.LastModificationTime = LastModificationTime;
95+
peNew.LastAccessTime = LastAccessTime;
96+
peNew.ExpiryTime = ExpiryTime;
97+
peNew.Expires = Expires;
98+
peNew.UsageCount = UsageCount;
99+
100+
peNew.OverrideUrl = OverrideUrl;
101+
102+
peNew.Tags = new List<string>(Tags);
103+
104+
peNew.CustomData = CustomData.CloneDeep();
105+
106+
return peNew;
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)