csv serialization test added

This commit is contained in:
Kevin Froman 2020-06-06 04:24:14 -05:00
parent 7ee829b94d
commit 280955b8e0
5 changed files with 46 additions and 10 deletions

View File

@ -3,6 +3,7 @@ using System;
using chestcrypto;
using keyring;
using chestcrypto.identity;
using System.Linq;
using Sodium;
namespace keyringTests
@ -36,6 +37,10 @@ namespace keyringTests
PrivateIdentity iden2 = new PrivateIdentity(key2, "alice");
KeyRing ring = new KeyRing();
ring.addPrivateIdentity(iden);
foreach(PrivateIdentity id in ring.privateIdentities){
Assert.IsTrue(Enumerable.SequenceEqual(id.getPrivateKey().getRawDouble(), iden.getPrivateKey().getRawDouble()));
Assert.IsFalse(Enumerable.SequenceEqual(id.getPrivateKey().getRawDouble(), iden2.getPrivateKey().getRawDouble()));
}
Assert.IsTrue(ring.privateIdentities.Contains(iden));
Assert.IsFalse(ring.privateIdentities.Contains(iden2));

View File

@ -2,9 +2,14 @@ using NUnit.Framework;
using chestcrypto.identity;
using chestcrypto;
using chestcrypto.profile;
using keyring;
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using Sodium;
using CsvHelper;
namespace testProfileLoad
{
@ -17,7 +22,31 @@ namespace testProfileLoad
[Test]
public void TestLoad(){
RestoreKeyring restore = new RestoreKeyring("test.profile");
var temp = Path.GetTempPath();
var publicProfile = temp + "/public.keyring.csv";
var privateProfile = temp + "/private.keyring.csv";
DoublePrivateKey key = new DoublePrivateKey(PublicKeyAuth.GenerateKeyPair().PrivateKey, PublicKeyBox.GenerateKeyPair().PrivateKey);
PrivateIdentity iden = new PrivateIdentity(key, "bob");
DoublePrivateKey key2 = new DoublePrivateKey(PublicKeyAuth.GenerateKeyPair().PrivateKey, PublicKeyBox.GenerateKeyPair().PrivateKey);
PrivateIdentity iden2 = new PrivateIdentity(key2, "alice");
KeyRing ring = new KeyRing();
ring.addPrivateIdentity(iden);
using (var writer = new StreamWriter(privateProfile))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(ring.privateIdentities);
}
using (var writer = new StreamWriter(publicProfile))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(ring.publicIdentities);
}
KeyRing restored = new RestoreKeyring(temp);
Directory.Delete(privateProfile);
}

View File

@ -1,16 +1,18 @@
using chestcrypto;
using SimpleBase;
namespace chestcrypto.identity
{
public class PrivateIdentity{
/*
PrivateIdentity is a wrapper around a DoublePrivateKey providing associated metadata such as alias and note
*/
private DoublePrivateKey key { get; set; }
public string base85Key { get {
return getEncodedKey();
}}
public string name { get; set; }
public string comment { get; set; } // human's note
private DoublePrivateKey key;
private string name;
private string comment; // human's note
public PrivateIdentity(DoublePrivateKey doublePrivateKey, string alias){
key = doublePrivateKey;
@ -25,10 +27,12 @@ namespace chestcrypto.identity
}
public DoublePrivateKey getPrivateKey(){return key;}
public string getEncodedKey(){
return SimpleBase.Base85.Z85.Encode(key.getRawDouble());
}
public string getName(){return name;}
public string getNote(){return comment;}
}
}

View File

@ -1,5 +1,3 @@
using chestcrypto;
namespace chestcrypto.identity
{
@ -7,7 +5,6 @@ namespace chestcrypto.identity
/*
PublicIdentity is a wrapper around a DoublePublicKey providing associated metadata such as alias and note
*/
private DoublePublicKey key;
private string name;
private string comment; // human's note

View File

@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="15.0.5" />
<PackageReference Include="MessagePack" Version="2.1.115" />
<PackageReference Include="SimpleBase" Version="3.0.1" />
<PackageReference Include="Sodium.Core" Version="1.2.3" />