treasurechest/tests/profile/testLoad.cs

54 lines
1.7 KiB
C#
Raw Normal View History

2020-06-05 04:16:05 +00:00
using NUnit.Framework;
using chestcrypto.identity;
using chestcrypto;
using chestcrypto.profile;
2020-06-06 09:24:14 +00:00
using keyring;
2020-06-05 04:16:05 +00:00
using System;
using System.IO;
using System.Linq;
2020-06-06 09:24:14 +00:00
using System.Collections.Generic;
using System.Globalization;
using Sodium;
using CsvHelper;
2020-06-05 04:16:05 +00:00
namespace testProfileLoad
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void TestLoad(){
2020-06-06 09:24:14 +00:00
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);
2020-06-05 04:16:05 +00:00
}
}
}