work on keyring
This commit is contained in:
parent
344a4c872e
commit
b678db282a
48
tests/keyring/add.cs
Normal file
48
tests/keyring/add.cs
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
24
treasurechest/chestcrypto/identity/ephemeralkey.cs
Normal file
24
treasurechest/chestcrypto/identity/ephemeralkey.cs
Normal 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){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
36
treasurechest/chestcrypto/identity/identity.cs
Normal file
36
treasurechest/chestcrypto/identity/identity.cs
Normal 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){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
18
treasurechest/keyring/file.cs
Normal file
18
treasurechest/keyring/file.cs
Normal 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){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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){
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user