work on keyring identity storage
This commit is contained in:
parent
4a4eb1cc61
commit
4aab4420a7
45
tests/keyring/deletePublic.cs
Normal file
45
tests/keyring/deletePublic.cs
Normal 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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
23
treasurechest/chestcrypto/identity/exceptions.cs
Normal file
23
treasurechest/chestcrypto/identity/exceptions.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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){
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user