treasurechest/tests/keyring/add.cs

48 lines
1.3 KiB
C#
Raw Normal View History

2020-05-16 03:48:05 +00:00
using NUnit.Framework;
using System;
using System.IO;
using Sodium;
using System.Collections.Generic;
using keyring;
using chestcrypto;
namespace KeyRingTests
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void TestKeyRingStore()
{
string tempFile = Path.GetTempFileName();
KeyRing keyRing = new KeyRing();
byte[] signingKey = PublicKeyAuth.GenerateKeyPair().PublicKey;
byte[] encryptionKey = PublicKeyBox.GenerateKeyPair().PublicKey;
byte[] combinedKey = new byte[signingKey.Length + encryptionKey.Length];
Buffer.BlockCopy(signingKey, 0, combinedKey, 0, signingKey.Length);
Buffer.BlockCopy(encryptionKey, 0, combinedKey, signingKey.Length, encryptionKey.Length);
DoublePublicKey combo = new DoublePublicKey(signingKey, encryptionKey);
keyRing.addPublicKey(combo);
List<byte[]> storedKeys = keyRing.getIdentityPublicKeys();
bool success = false;
storedKeys.ForEach(delegate(byte[] key)
{
if (key.Equals(combinedKey)){
success = true;
}
});
if (! success){
Assert.Fail();
}
}
}
}