treasurechest/tests/keyringTest.cs

50 lines
2.0 KiB
C#
Raw Normal View History

2020-06-05 04:16:05 +00:00
using NUnit.Framework;
using System;
using chestcrypto;
using keyring;
using chestcrypto.identity;
2020-06-06 09:24:14 +00:00
using System.Linq;
2020-06-05 04:16:05 +00:00
using Sodium;
namespace keyringTests
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void TestKeyringAddPublic()
{
DoublePublicKey key = new DoublePublicKey(PublicKeyAuth.GenerateKeyPair().PublicKey, PublicKeyBox.GenerateKeyPair().PublicKey);
PublicIdentity iden = new PublicIdentity(key, "bob");
DoublePublicKey key2 = new DoublePublicKey(PublicKeyAuth.GenerateKeyPair().PublicKey, PublicKeyBox.GenerateKeyPair().PublicKey);
PublicIdentity iden2 = new PublicIdentity(key2, "alice");
KeyRing ring = new KeyRing();
ring.addPublicIdentity(iden);
Assert.IsTrue(ring.publicIdentities.Contains(iden));
Assert.IsFalse(ring.publicIdentities.Contains(iden2));
}
[Test]
public void TestKeyringAddPrivate(){
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);
2020-06-06 09:24:14 +00:00
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()));
}
2020-06-05 04:16:05 +00:00
Assert.IsTrue(ring.privateIdentities.Contains(iden));
Assert.IsFalse(ring.privateIdentities.Contains(iden2));
}
}
}