work on keyring

This commit is contained in:
Kevin Froman 2020-05-15 22:48:05 -05:00
parent 344a4c872e
commit b678db282a
9 changed files with 144 additions and 1 deletions

48
tests/keyring/add.cs Normal file
View File

@ -0,0 +1,48 @@
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();
}
}
}
}

View File

@ -0,0 +1,24 @@
namespace chestcrypto{
namespace identity{
internal class EphemeralKey{
private int epochTime;
private int secondsToExpire;
private byte[] key = new byte[32];
private bool isPrivate;
private Identity identity;
public EphemeralKey(Identity user){
identity = user;
}
public EphemeralKey(Identity identity, byte[] key, int secondsToExpire){
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Collections.Generic;
namespace chestcrypto{
namespace identity {
internal class Identity {
private DoublePrivateKey privateKey;
private DoublePublicKey publicKey;
private List<EphemeralKey> ephemeralKeys = new List<EphemeralKey>();
public DoublePublicKey getDoublePublicKey(){return publicKey;}
public Identity(){}
public Identity (List<EphemeralKey> ephemeralKeys){
}
public Identity(DoublePublicKey publicKey){
}
public Identity(DoublePrivateKey privateKey){
}
public Identity(DoublePrivateKey privateKey, List<EphemeralKey> ephemeralKeys){
}
public Identity(DoublePublicKey publicKey, List<EphemeralKey> ephemeralKeys){
}
}
}
}

View File

@ -0,0 +1,18 @@
using chestcrypto;
namespace keyring{
internal class KeyRingFile
{
private string storageFile = null;
internal KeyRingFile(string filePath){
storageFile = filePath;
}
internal void write(byte[] data){
}
}
}

View File

@ -1,19 +1,36 @@
using chestcrypto;
using chestcrypto.identity;
using System.Collections.Generic;
namespace keyring{
public class KeyRing
{
private string storageFile = null;
private List<Identity> identities = new List<Identity>();
public KeyRing(string storageFile){
}
public KeyRing(){}
public List<byte[]> getIdentityPublicKeys(){
List<byte[]> pubKeys;
identities.ForEach(delegate(Identity identity){
pubKeys.Add(identity.getDoublePublicKey().getRawDouble());
});
}
public void addPublicKey(DoublePublicKey key){
// Create an Identity with a public key if it does not exist already
Identity newIdentity = new Identity(key);
}
public void deleteKey(DoublePrivateKey key){
public void deletePublicKey(DoublePublicKey key){
}
}