work on keyring identity storage

This commit is contained in:
Kevin Froman 2020-05-18 23:59:38 -05:00
parent 4a4eb1cc61
commit 4aab4420a7
3 changed files with 92 additions and 1 deletions

View File

@ -0,0 +1,45 @@
using NUnit.Framework;
using System;
using System.IO;
using Sodium;
using System.Collections.Generic;
using keyring;
using chestcrypto;
using chestcrypto.exceptions;
namespace KeyRingTests
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void TestDeleteIdentityByPublicKey(){
string tempFile = Path.GetTempFileName();
DoublePublicKey getKey(){
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);
return combo;
}
DoublePublicKey combo = getKey();
KeyRing keyRing = new KeyRing();
keyRing.addPublicKey(combo);
Assert.IsTrue(keyRing.getIdentityCount() == 1);
keyRing.removeIdentityByPubkey(combo);
Assert.IsTrue(keyRing.getIdentityCount() == 0);
}
}
}

View File

@ -0,0 +1,23 @@
using System;
namespace chestcrypto{
namespace exceptions{
public class NoIdentityException : Exception
{
public NoIdentityException()
{
}
public NoIdentityException(string message)
: base(message)
{
}
public NoIdentityException(string message, Exception inner)
: base(message, inner)
{
}
}
}
}

View File

@ -22,11 +22,34 @@ namespace keyring{
return success;
}
private int getIdentityListPosition(Identity iden){
int counter = 0;
bool success = false;
identities.ForEach(delegate(Identity ident)
{
if (ident.getDoublePublicKey().Equals(iden.getDoublePublicKey())){
success = true;
return;
}
counter += 1;
});
if (success){
return counter;
}
throw new NoIdentityException();
}
public KeyRing(string storageFile){
}
public KeyRing(){}
public int getIdentityCount(){return identities.Count;}
public int getIdentityInstance(DoublePublicKey){
}
public List<byte[]> getIdentityPublicKeys(){
List<byte[]> pubKeys = new List<byte[]>();
identities.ForEach(delegate(Identity identity){
@ -48,7 +71,7 @@ namespace keyring{
}
public void deletePublicKey(DoublePublicKey key){
public void removeIdentityByPubkey(DoublePublicKey key){
}
}