added serial inferface and testPublic
parent
c156ce8213
commit
77db2af0e6
@ -0,0 +1,14 @@
|
||||
namespace serial{
|
||||
|
||||
public class SerialCommands{
|
||||
public enum Commands{
|
||||
AddIdentity,
|
||||
RemoveIdentity,
|
||||
EncryptToIdentity,
|
||||
DecryptFromIdentity,
|
||||
UnknownCommand,
|
||||
Exit
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\treasurechest\treasurechest.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,63 @@
|
||||
using NUnit.Framework;
|
||||
using chestcrypto.identity;
|
||||
using chestcrypto;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Sodium;
|
||||
|
||||
namespace PrivateIndentityTest
|
||||
{
|
||||
public class Tests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrivateIdentityGetDoublePrivateKey(){
|
||||
byte[] signingKey = PublicKeyAuth.GenerateKeyPair().PrivateKey;
|
||||
byte[] encryptionKey = PublicKeyBox.GenerateKeyPair().PrivateKey;
|
||||
|
||||
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);
|
||||
|
||||
DoublePrivateKey combinedLoad = new chestcrypto.DoublePrivateKey(combinedKey);
|
||||
|
||||
PrivateIdentity iden = new PrivateIdentity(combinedLoad, "Picard");
|
||||
|
||||
Assert.IsTrue(Enumerable.SequenceEqual(iden.getPrivateKey().getRawDouble(), combinedLoad.getRawDouble()));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrivateIdentityConstructor()
|
||||
{
|
||||
byte[] signingKey = PublicKeyAuth.GenerateKeyPair().PrivateKey;
|
||||
byte[] encryptionKey = PublicKeyBox.GenerateKeyPair().PrivateKey;
|
||||
|
||||
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);
|
||||
|
||||
DoublePrivateKey combinedLoad = new chestcrypto.DoublePrivateKey(combinedKey);
|
||||
|
||||
PrivateIdentity iden = new PrivateIdentity(combinedLoad, "Picard");
|
||||
Assert.AreEqual(iden.getName(), "Picard");
|
||||
Assert.AreEqual(iden.getNote(), "");
|
||||
|
||||
PrivateIdentity iden2 = new PrivateIdentity(combinedLoad, "Picard2", "test");
|
||||
Assert.AreEqual(iden2.getName(), "Picard2");
|
||||
Assert.AreEqual(iden2.getNote(), "test");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrivateIdenToPublic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using chestcrypto;
|
||||
|
||||
namespace chestcrypto.identity
|
||||
{
|
||||
|
||||
public class PublicIdentity{
|
||||
/*
|
||||
PublicIdentity is a wrapper around a DoublePublicKey providing associated metadata such as alias and note
|
||||
*/
|
||||
|
||||
private DoublePublicKey key;
|
||||
private string name;
|
||||
private string comment; // human's note
|
||||
|
||||
public PublicIdentity(DoublePublicKey doublePrivateKey, string alias){
|
||||
key = doublePrivateKey;
|
||||
name = alias;
|
||||
comment = "";
|
||||
}
|
||||
|
||||
public PublicIdentity(DoublePublicKey doublePrivateKey, string alias, string note){
|
||||
key = doublePrivateKey;
|
||||
name = alias;
|
||||
comment = note;
|
||||
}
|
||||
|
||||
public DoublePublicKey getPrivateKey(){return key;}
|
||||
public string getName(){return name;}
|
||||
public string getNote(){return comment;}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue