mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 03:32:57 +00:00
cipher
This commit is contained in:
parent
81f9f92755
commit
8ab0e811bd
32
Esiur.Generator/AES.cs
Normal file
32
Esiur.Generator/AES.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Esiur.Security.Cryptography
|
||||||
|
{
|
||||||
|
public class AES : ISymetricCipher
|
||||||
|
{
|
||||||
|
Aes aes = Aes.Create();
|
||||||
|
|
||||||
|
public ushort Identifier => 1;
|
||||||
|
|
||||||
|
public byte[] Decrypt(byte[] data)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] Encrypt(byte[] data)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] SetKey(byte[] key)
|
||||||
|
{
|
||||||
|
//aes.Key = key;
|
||||||
|
//aes.IV = key;
|
||||||
|
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
Esiur.Generator/ECDH.cs
Normal file
49
Esiur.Generator/ECDH.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using Esiur.Security.Cryptography;
|
||||||
|
using Esiur.Data;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Esiur.Security.Cryptography
|
||||||
|
{
|
||||||
|
public class ECDH : IKeyExchanger
|
||||||
|
{
|
||||||
|
public ushort Identifier => 1;
|
||||||
|
|
||||||
|
ECDiffieHellman ecdh = ECDiffieHellman.Create(ECCurve.NamedCurves.brainpoolP256r1);
|
||||||
|
|
||||||
|
public byte[] ComputeSharedKey(byte[] key)
|
||||||
|
{
|
||||||
|
var x = key.Clip(0, (uint)key.Length / 2);
|
||||||
|
var y = key.Clip((uint)key.Length / 2, (uint)key.Length / 2);
|
||||||
|
|
||||||
|
ECParameters parameters = new ECParameters
|
||||||
|
{
|
||||||
|
Curve = ECCurve.NamedCurves.brainpoolP256r1,
|
||||||
|
Q = {
|
||||||
|
X = x,
|
||||||
|
Y = y,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
byte[] derivedKey;
|
||||||
|
using (ECDiffieHellman peer = ECDiffieHellman.Create(parameters))
|
||||||
|
using (ECDiffieHellmanPublicKey peerPublic = peer.PublicKey)
|
||||||
|
{
|
||||||
|
return derivedKey = ecdh.DeriveKeyMaterial(peerPublic);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] GetPublicKey()
|
||||||
|
{
|
||||||
|
var kp = ecdh.PublicKey.ExportParameters();
|
||||||
|
|
||||||
|
var key = DC.Combine(kp.Q.X, 0, (uint)kp.Q.X.Length, kp.Q.Y, 0, (uint)kp.Q.Y.Length);
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
Esiur.Generator/Esiur.Security.Cryptography.csproj
Normal file
12
Esiur.Generator/Esiur.Security.Cryptography.csproj
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Esiur\Esiur.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -9,7 +9,7 @@
|
|||||||
<Product>Esiur Entity Framework Extension</Product>
|
<Product>Esiur Entity Framework Extension</Product>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<PackageId>Esiur.Stores.EntityCore</PackageId>
|
<PackageId>Esiur.Stores.EntityCore</PackageId>
|
||||||
<Version>1.3.3</Version>
|
<Version>1.3.4</Version>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@ -22,7 +22,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
|
||||||
<PackageReference Include="System.Collections" Version="4.3.0" />
|
<PackageReference Include="System.Collections" Version="4.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -11,14 +11,14 @@
|
|||||||
<PackageProjectUrl>http://www.esiur.com</PackageProjectUrl>
|
<PackageProjectUrl>http://www.esiur.com</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/esiur/esiur-dotnet/</RepositoryUrl>
|
<RepositoryUrl>https://github.com/esiur/esiur-dotnet/</RepositoryUrl>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<Version>1.5.5</Version>
|
<Version>1.5.6</Version>
|
||||||
<PackageId>Esiur.Stores.MongoDB</PackageId>
|
<PackageId>Esiur.Stores.MongoDB</PackageId>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MongoDB.Bson" Version="2.12.3" />
|
<PackageReference Include="MongoDB.Bson" Version="2.24.0" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.12.3" />
|
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -51,15 +51,15 @@ public class MongoDBStore : IStore
|
|||||||
KeyList<string, WeakReference> resources = new KeyList<string, WeakReference>();
|
KeyList<string, WeakReference> resources = new KeyList<string, WeakReference>();
|
||||||
|
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public event ResourceEventHandler<IResource> ResourceAdded;
|
public event ResourceEventHandler<IResource> ResourceAdded;
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public event ResourceEventHandler<IResource> ResourceRemoved;
|
public event ResourceEventHandler<IResource> ResourceRemoved;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public virtual int Count
|
public virtual int Count
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -109,7 +109,7 @@ public class MongoDBStore : IStore
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public bool Remove(IResource resource)
|
public bool Remove(IResource resource)
|
||||||
{
|
{
|
||||||
var objectId = resource.Instance.Variables["objectId"].ToString();
|
var objectId = resource.Instance.Variables["objectId"].ToString();
|
||||||
|
@ -35,7 +35,7 @@ namespace Esiur.Stores.MongoDB
|
|||||||
{
|
{
|
||||||
public class MongoDBStore<T> : MongoDBStore where T:IResource
|
public class MongoDBStore<T> : MongoDBStore where T:IResource
|
||||||
{
|
{
|
||||||
[Public]
|
[Export]
|
||||||
public async AsyncReply<T> New(string name = null, object properties = null)
|
public async AsyncReply<T> New(string name = null, object properties = null)
|
||||||
{
|
{
|
||||||
var resource = await Warehouse.New<T>(name, this, null, null, null, properties);
|
var resource = await Warehouse.New<T>(name, this, null, null, null, properties);
|
||||||
@ -43,7 +43,7 @@ namespace Esiur.Stores.MongoDB
|
|||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public async AsyncReply<IResource[]> Slice(int index, int limit)
|
public async AsyncReply<IResource[]> Slice(int index, int limit)
|
||||||
{
|
{
|
||||||
var list = await this.Instance.Children<IResource>();
|
var list = await this.Instance.Children<IResource>();
|
||||||
|
@ -10,6 +10,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Stores.EntityCore", "
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{331F82B6-6B90-4533-9718-F7C8090D8F19}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{331F82B6-6B90-4533-9718-F7C8090D8F19}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Esiur.Security.Cryptography", "Esiur.Generator\Esiur.Security.Cryptography.csproj", "{C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -32,6 +34,10 @@ Global
|
|||||||
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Release|Any CPU.Build.0 = Release|Any CPU
|
{331F82B6-6B90-4533-9718-F7C8090D8F19}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -39,4 +45,4 @@ Global
|
|||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {C584421D-5EC0-4821-B7D8-2633D8D405F2}
|
SolutionGuid = {C584421D-5EC0-4821-B7D8-2633D8D405F2}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
|
||||||
<Description>Distributed Resources Platform</Description>
|
<Description>Distributed Resources Platform</Description>
|
||||||
<Copyright>Ahmed Kh. Zamil</Copyright>
|
<Copyright>Ahmed Kh. Zamil</Copyright>
|
||||||
<PackageProjectUrl>http://www.esiur.com</PackageProjectUrl>
|
<PackageProjectUrl>http://www.esiur.com</PackageProjectUrl>
|
||||||
@ -18,6 +17,7 @@
|
|||||||
<Product>Esiur</Product>
|
<Product>Esiur</Product>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
@ -83,10 +83,10 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||||
<!-- Package the Newtonsoft.Json dependency alongside the generator assembly -->
|
<!-- Package the Newtonsoft.Json dependency alongside the generator assembly -->
|
||||||
<None Include="$(PkgSystem_Text_Json)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
<None Include="$(PkgSystem_Text_Json)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||||
<None Include="Tools/*" Pack="true" PackagePath="tools/" />
|
<None Include="Tools/*" Pack="true" PackagePath="tools/" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
@ -228,10 +228,10 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
|||||||
{
|
{
|
||||||
var dmn = DC.ToBytes(session.LocalAuthentication.Domain);
|
var dmn = DC.ToBytes(session.LocalAuthentication.Domain);
|
||||||
|
|
||||||
if (session.Encrypted)
|
if (session.KeyExchanger != null)
|
||||||
{
|
{
|
||||||
// create key
|
// create key
|
||||||
//var ecdh = System.Security.Cryptography.ECAlgorithm.ECDiffieHellman.Create();
|
var key = session.KeyExchanger.GetPublicKey();
|
||||||
|
|
||||||
if (session.LocalAuthentication.Method == AuthenticationMethod.Credentials)
|
if (session.LocalAuthentication.Method == AuthenticationMethod.Credentials)
|
||||||
{
|
{
|
||||||
@ -240,9 +240,12 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
|||||||
var un = DC.ToBytes(session.LocalAuthentication.Username);
|
var un = DC.ToBytes(session.LocalAuthentication.Username);
|
||||||
|
|
||||||
SendParams()
|
SendParams()
|
||||||
.AddUInt8(0x60)
|
.AddUInt8(0x60 | 0x2)
|
||||||
.AddUInt8((byte)dmn.Length)
|
.AddUInt8((byte)dmn.Length)
|
||||||
.AddUInt8Array(dmn)
|
.AddUInt8Array(dmn)
|
||||||
|
.AddUInt16(session.KeyExchanger.Identifier)
|
||||||
|
.AddUInt16((ushort)key.Length)
|
||||||
|
.AddUInt8Array(key)
|
||||||
.AddUInt8Array(localNonce)
|
.AddUInt8Array(localNonce)
|
||||||
.AddUInt8((byte)un.Length)
|
.AddUInt8((byte)un.Length)
|
||||||
.AddUInt8Array(un)
|
.AddUInt8Array(un)
|
||||||
@ -252,9 +255,12 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
|||||||
{
|
{
|
||||||
|
|
||||||
SendParams()
|
SendParams()
|
||||||
.AddUInt8(0x70)
|
.AddUInt8(0x70 | 0x2)
|
||||||
.AddUInt8((byte)dmn.Length)
|
.AddUInt8((byte)dmn.Length)
|
||||||
.AddUInt8Array(dmn)
|
.AddUInt8Array(dmn)
|
||||||
|
.AddUInt16(session.KeyExchanger.Identifier)
|
||||||
|
.AddUInt16((ushort)key.Length)
|
||||||
|
.AddUInt8Array(key)
|
||||||
.AddUInt8Array(localNonce)
|
.AddUInt8Array(localNonce)
|
||||||
.AddUInt64(session.LocalAuthentication.TokenIndex)
|
.AddUInt64(session.LocalAuthentication.TokenIndex)
|
||||||
.Done();//, dmn, localNonce, token
|
.Done();//, dmn, localNonce, token
|
||||||
@ -262,10 +268,14 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
|||||||
}
|
}
|
||||||
else if (session.LocalAuthentication.Method == AuthenticationMethod.None)
|
else if (session.LocalAuthentication.Method == AuthenticationMethod.None)
|
||||||
{
|
{
|
||||||
|
// @REVIEW: MITM Attack can still occure
|
||||||
SendParams()
|
SendParams()
|
||||||
.AddUInt8(0x40)
|
.AddUInt8(0x40 | 0x2)
|
||||||
.AddUInt8((byte)dmn.Length)
|
.AddUInt8((byte)dmn.Length)
|
||||||
.AddUInt8Array(dmn)
|
.AddUInt8Array(dmn)
|
||||||
|
.AddUInt16(session.KeyExchanger.Identifier)
|
||||||
|
.AddUInt16((ushort)key.Length)
|
||||||
|
.AddUInt8Array(key)
|
||||||
.Done();//, dmn, localNonce, token
|
.Done();//, dmn, localNonce, token
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -30,6 +30,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Esiur.Security.Cryptography;
|
||||||
|
|
||||||
namespace Esiur.Security.Authority;
|
namespace Esiur.Security.Authority;
|
||||||
public class Session
|
public class Session
|
||||||
@ -50,7 +51,9 @@ public class Session
|
|||||||
Authentication localAuth, remoteAuth;
|
Authentication localAuth, remoteAuth;
|
||||||
//string domain;
|
//string domain;
|
||||||
|
|
||||||
public bool Encrypted { get; set; }
|
|
||||||
|
public IKeyExchanger KeyExchanger { get; set; } = null;
|
||||||
|
public ISymetricCipher SymetricCipher { get; set; } = null;
|
||||||
|
|
||||||
|
|
||||||
public Session(Authentication localAuthentication, Authentication remoteAuthentication)
|
public Session(Authentication localAuthentication, Authentication remoteAuthentication)
|
||||||
|
14
Esiur/Security/Cryptography/IKeyExchanger.cs
Normal file
14
Esiur/Security/Cryptography/IKeyExchanger.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Esiur.Security.Cryptography
|
||||||
|
{
|
||||||
|
public interface IKeyExchanger
|
||||||
|
{
|
||||||
|
public ushort Identifier { get; }
|
||||||
|
public byte[] GetPublicKey();
|
||||||
|
public byte[] ComputeSharedKey(byte[] key);
|
||||||
|
}
|
||||||
|
}
|
14
Esiur/Security/Cryptography/ISymetricCipher.cs
Normal file
14
Esiur/Security/Cryptography/ISymetricCipher.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Esiur.Security.Cryptography
|
||||||
|
{
|
||||||
|
public interface ISymetricCipher
|
||||||
|
{
|
||||||
|
public ushort Identifier { get; }
|
||||||
|
public byte[] Encrypt(byte[] data);
|
||||||
|
public byte[] Decrypt(byte[] data);
|
||||||
|
public byte[] SetKey(byte[] key);
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Test
|
namespace Test
|
||||||
{
|
{
|
||||||
[Public]
|
[Export]
|
||||||
public class MyChildRecord : MyRecord
|
public class MyChildRecord : MyRecord
|
||||||
{
|
{
|
||||||
public string ChildName { get; set; }
|
public string ChildName { get; set; }
|
||||||
|
@ -10,11 +10,11 @@ namespace Test
|
|||||||
[Resource]
|
[Resource]
|
||||||
public partial class MyChildResource : MyResource
|
public partial class MyChildResource : MyResource
|
||||||
{
|
{
|
||||||
[Public] string childName;
|
[Export] string childName;
|
||||||
[Public("Hell2o")] public int ChildMethod(string childName) => 111;
|
[Export("Hell2o")] public int ChildMethod(string childName) => 111;
|
||||||
[Public] public new string Hello() => "Hi from Child";
|
[Export] public new string Hello() => "Hi from Child";
|
||||||
|
|
||||||
[Public] public string HelloChild() => "Hi from Child";
|
[Export] public string HelloChild() => "Hi from Child";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,10 @@ namespace Test
|
|||||||
{
|
{
|
||||||
public class MyGenericRecord<T> : IRecord where T : IResource
|
public class MyGenericRecord<T> : IRecord where T : IResource
|
||||||
{
|
{
|
||||||
[Public] public int Start { get; set; }
|
[Export] public int Start { get; set; }
|
||||||
[Public] public int Needed { get; set; }
|
[Export] public int Needed { get; set; }
|
||||||
[Public] public int Total { get; set; }
|
[Export] public int Total { get; set; }
|
||||||
[Public] public T[] Results { get; set; }
|
[Export] public T[] Results { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Test
|
namespace Test
|
||||||
{
|
{
|
||||||
[Public]
|
[Export]
|
||||||
public class MyRecord:IRecord
|
public class MyRecord:IRecord
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
@ -12,12 +12,12 @@ namespace Test
|
|||||||
[Annotation("A", "B", "C", "D")]
|
[Annotation("A", "B", "C", "D")]
|
||||||
public partial class MyResource
|
public partial class MyResource
|
||||||
{
|
{
|
||||||
[Public][Annotation("Comment")] string description;
|
[Export][Annotation("Comment")] string description;
|
||||||
[Public] int categoryId;
|
[Export] int categoryId;
|
||||||
|
|
||||||
[Public] public string Hello() => "Hi";
|
[Export] public string Hello() => "Hi";
|
||||||
|
|
||||||
[Public] public string HelloParent() => "Hi from Parent";
|
[Export] public string HelloParent() => "Hi from Parent";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,73 +25,73 @@ public enum SizeEnum:short
|
|||||||
public partial class MyService
|
public partial class MyService
|
||||||
{
|
{
|
||||||
|
|
||||||
[Public] public event ResourceEventHandler<string> StringEvent;
|
[Export] public event ResourceEventHandler<string> StringEvent;
|
||||||
[Public] public event ResourceEventHandler<object[]> ArrayEvent;
|
[Export] public event ResourceEventHandler<object[]> ArrayEvent;
|
||||||
|
|
||||||
[Public] bool boolean = true;
|
[Export] bool boolean = true;
|
||||||
[Public] bool[] booleanArray = new bool[] { true, false, true, false, true };
|
[Export] bool[] booleanArray = new bool[] { true, false, true, false, true };
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public MyGenericRecord<MyResource> GetGenericRecord()
|
public MyGenericRecord<MyResource> GetGenericRecord()
|
||||||
{
|
{
|
||||||
return new MyGenericRecord<MyResource>() { Needed = 3, Start = 10, Results = new MyResource[0], Total = 102 };
|
return new MyGenericRecord<MyResource>() { Needed = 3, Start = 10, Results = new MyResource[0], Total = 102 };
|
||||||
}
|
}
|
||||||
|
|
||||||
[Public] public static string staticFunction(string name) => $"Hello {name}";
|
[Export] public static string staticFunction(string name) => $"Hello {name}";
|
||||||
|
|
||||||
[Public] byte uInt8Test = 8;
|
[Export] byte uInt8Test = 8;
|
||||||
[Public] byte? uInt8Null = null;
|
[Export] byte? uInt8Null = null;
|
||||||
[Public] byte[] uInt8Array = new byte[] { 0, 1, 2, 3, 4, 5 };
|
[Export] byte[] uInt8Array = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||||
[Public] byte?[] uInt8ArrayNull = new byte?[] { 0, null, 2, null, 4, null };
|
[Export] byte?[] uInt8ArrayNull = new byte?[] { 0, null, 2, null, 4, null };
|
||||||
|
|
||||||
[Public] sbyte int8 = -8;
|
[Export] sbyte int8 = -8;
|
||||||
[Public] sbyte[] int8Array = new sbyte[] { -3, -2, -1, 0, 1, 2 };
|
[Export] sbyte[] int8Array = new sbyte[] { -3, -2, -1, 0, 1, 2 };
|
||||||
|
|
||||||
[Public] char char16 = 'ح';
|
[Export] char char16 = 'ح';
|
||||||
[Public] char[] char16Array = new char[] { 'م', 'ر', 'ح', 'ب', 'ا' };
|
[Export] char[] char16Array = new char[] { 'م', 'ر', 'ح', 'ب', 'ا' };
|
||||||
|
|
||||||
[Public] short int16 = -16;
|
[Export] short int16 = -16;
|
||||||
[Public] short[] int16Array = new short[] { -3, -2, -1, 0, 1, 2 };
|
[Export] short[] int16Array = new short[] { -3, -2, -1, 0, 1, 2 };
|
||||||
|
|
||||||
[Public] ushort uInt16 = 16;
|
[Export] ushort uInt16 = 16;
|
||||||
[Public] ushort[] uInt16Array = new ushort[] { 0, 1, 2, 3, 4, 5 };
|
[Export] ushort[] uInt16Array = new ushort[] { 0, 1, 2, 3, 4, 5 };
|
||||||
|
|
||||||
|
|
||||||
[Public] int int32Prop = -32;
|
[Export] int int32Prop = -32;
|
||||||
[Public] int[] int32Array = new int[] { -3, -2, -1, 0, 1, 2 };
|
[Export] int[] int32Array = new int[] { -3, -2, -1, 0, 1, 2 };
|
||||||
|
|
||||||
[Public] uint uInt32 = 32;
|
[Export] uint uInt32 = 32;
|
||||||
[Public] uint[] uInt32Array = new uint[] { 0, 1, 2, 3, 4, 5 };
|
[Export] uint[] uInt32Array = new uint[] { 0, 1, 2, 3, 4, 5 };
|
||||||
|
|
||||||
[Public] long int64 = 323232323232;
|
[Export] long int64 = 323232323232;
|
||||||
[Public] long[] int64Array = new long[] { -3, -2, -1, 0, 1, 2 };
|
[Export] long[] int64Array = new long[] { -3, -2, -1, 0, 1, 2 };
|
||||||
|
|
||||||
[Public] ulong uInt64;
|
[Export] ulong uInt64;
|
||||||
[Public] ulong[] uInt64Array = new ulong[] { 0, 1, 2, 3, 4, 5 };
|
[Export] ulong[] uInt64Array = new ulong[] { 0, 1, 2, 3, 4, 5 };
|
||||||
|
|
||||||
[Public] float float32 = 32.32f;
|
[Export] float float32 = 32.32f;
|
||||||
[Public] float[] float32Array = new float[] { -3.3f, -2.2f, -1.1f, 0, 1.1f, 2.2f };
|
[Export] float[] float32Array = new float[] { -3.3f, -2.2f, -1.1f, 0, 1.1f, 2.2f };
|
||||||
|
|
||||||
[Public] double float64 = 32.323232;
|
[Export] double float64 = 32.323232;
|
||||||
[Public] double[] float64Array = new double[] { -3.3, -2.2, -1.1, 0, 1.1, 2.2 };
|
[Export] double[] float64Array = new double[] { -3.3, -2.2, -1.1, 0, 1.1, 2.2 };
|
||||||
|
|
||||||
[Public] decimal float128 = 3232.323232323232m;
|
[Export] decimal float128 = 3232.323232323232m;
|
||||||
[Public] decimal[] float128Array = new decimal[] { -3.3m, -2.2m, -1.1m, 0, 1.1m, 2.2m };
|
[Export] decimal[] float128Array = new decimal[] { -3.3m, -2.2m, -1.1m, 0, 1.1m, 2.2m };
|
||||||
|
|
||||||
[Public("Text")] string stringTest = "Hello World";
|
[Export("Text")] string stringTest = "Hello World";
|
||||||
[Public] string[] stringArray = new string[] { "Hello", "World" };
|
[Export] string[] stringArray = new string[] { "Hello", "World" };
|
||||||
|
|
||||||
[Public] DateTime time = DateTime.Now;
|
[Export] DateTime time = DateTime.Now;
|
||||||
|
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
Map<string, object> stringMap = new Map<string, object>()
|
Map<string, object> stringMap = new Map<string, object>()
|
||||||
{
|
{
|
||||||
["int"] = 33,
|
["int"] = 33,
|
||||||
["string"] = "Hello World"
|
["string"] = "Hello World"
|
||||||
};
|
};
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
Map<int, string> intStringMap = new()
|
Map<int, string> intStringMap = new()
|
||||||
{
|
{
|
||||||
[4] = "Abcd",
|
[4] = "Abcd",
|
||||||
@ -99,11 +99,11 @@ public partial class MyService
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
[Public("Object")] object objectTest = "object";
|
[Export("Object")] object objectTest = "object";
|
||||||
|
|
||||||
[Public] object[] objectArray = new object[] { 1, 1.2f, Math.PI, "Hello World" };
|
[Export] object[] objectArray = new object[] { 1, 1.2f, Math.PI, "Hello World" };
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public DistributedPropertyContext<int> PropertyContext
|
public DistributedPropertyContext<int> PropertyContext
|
||||||
{
|
{
|
||||||
get => new DistributedPropertyContext<int>((sender) => sender.RemoteEndPoint.Port);
|
get => new DistributedPropertyContext<int>((sender) => sender.RemoteEndPoint.Port);
|
||||||
@ -113,38 +113,38 @@ public partial class MyService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Public] public SizeEnum Enum => SizeEnum.Medium;
|
[Export] public SizeEnum Enum => SizeEnum.Medium;
|
||||||
|
|
||||||
|
|
||||||
[Public] public MyRecord Record => new MyRecord() { Id = 33, Name = "Test", Score = 99.33 };
|
[Export] public MyRecord Record => new MyRecord() { Id = 33, Name = "Test", Score = 99.33 };
|
||||||
|
|
||||||
[Public] public List<int> IntList => new List<int>() { 1, 2, 3, 4, 5 };
|
[Export] public List<int> IntList => new List<int>() { 1, 2, 3, 4, 5 };
|
||||||
|
|
||||||
[Public] public IRecord[] RecordsArray => new IRecord[] { new MyRecord() { Id = 22, Name = "Test", Score = 22.1 } };
|
[Export] public IRecord[] RecordsArray => new IRecord[] { new MyRecord() { Id = 22, Name = "Test", Score = 22.1 } };
|
||||||
[Public] public List<MyRecord> RecordsList => new() { new MyRecord() { Id = 22, Name = "Test", Score = 22.1 } };
|
[Export] public List<MyRecord> RecordsList => new() { new MyRecord() { Id = 22, Name = "Test", Score = 22.1 } };
|
||||||
|
|
||||||
|
|
||||||
[Public] public MyResource[] myResources;
|
[Export] public MyResource[] myResources;
|
||||||
|
|
||||||
[Public] public MyResource Resource { get; set; }
|
[Export] public MyResource Resource { get; set; }
|
||||||
[Public] public MyChildResource ChildResource { get; set; }
|
[Export] public MyChildResource ChildResource { get; set; }
|
||||||
|
|
||||||
[Public] public MyChildRecord ChildRecord { get; set; } = new MyChildRecord() { ChildName = "Child", Id = 12, Name = "Parent", Score = 12.2 };
|
[Export] public MyChildRecord ChildRecord { get; set; } = new MyChildRecord() { ChildName = "Child", Id = 12, Name = "Parent", Score = 12.2 };
|
||||||
|
|
||||||
[Public] public IResource[] Resources { get; set; }
|
[Export] public IResource[] Resources { get; set; }
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public void Void() =>
|
public void Void() =>
|
||||||
Console.WriteLine("Void()");
|
Console.WriteLine("Void()");
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public void InvokeEvents(string msg)
|
public void InvokeEvents(string msg)
|
||||||
{
|
{
|
||||||
StringEvent?.Invoke(msg);
|
StringEvent?.Invoke(msg);
|
||||||
ArrayEvent?.Invoke(new object[] { DateTime.UtcNow, "Event", msg });
|
ArrayEvent?.Invoke(new object[] { DateTime.UtcNow, "Event", msg });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public double Optional(object a1, int a2, string a3 = "Hello", string a4 = "World")
|
public double Optional(object a1, int a2, string a3 = "Hello", string a4 = "World")
|
||||||
{
|
{
|
||||||
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
||||||
@ -152,7 +152,7 @@ public partial class MyService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public AsyncReply<List<Map<int, string?>?>> AsyncHello()
|
public AsyncReply<List<Map<int, string?>?>> AsyncHello()
|
||||||
{
|
{
|
||||||
var rt = new List<Map<int, string?>?>();
|
var rt = new List<Map<int, string?>?>();
|
||||||
@ -160,32 +160,32 @@ public partial class MyService
|
|||||||
return new AsyncReply<List<Map<int, string?>?>>(rt);
|
return new AsyncReply<List<Map<int, string?>?>>(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public void Connection(object a1, int a2, DistributedConnection a3) =>
|
public void Connection(object a1, int a2, DistributedConnection a3) =>
|
||||||
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
||||||
|
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public void ConnectionOptional(object a1, int a2, string a3 = "sss", DistributedConnection a4 = null) =>
|
public void ConnectionOptional(object a1, int a2, string a3 = "sss", DistributedConnection a4 = null) =>
|
||||||
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public (int, string) GetTuple2(int a1, string a2) => (a1, a2);
|
public (int, string) GetTuple2(int a1, string a2) => (a1, a2);
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public (int, string, double) GetTuple3(int a1, string a2, double a3) => (a1, a2, a3);
|
public (int, string, double) GetTuple3(int a1, string a2, double a3) => (a1, a2, a3);
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public (int, string, double, bool) GetTuple4(int a1, string a2, double a3, bool a4) => (a1, a2, a3, a4);
|
public (int, string, double, bool) GetTuple4(int a1, string a2, double a3, bool a4) => (a1, a2, a3, a4);
|
||||||
|
|
||||||
[Public]
|
[Export]
|
||||||
public MyRecord SendRecord(MyRecord record)
|
public MyRecord SendRecord(MyRecord record)
|
||||||
{
|
{
|
||||||
Console.WriteLine(record.ToString());
|
Console.WriteLine(record.ToString());
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Public] public const double PI = Math.PI;
|
[Export] public const double PI = Math.PI;
|
||||||
|
|
||||||
[Public] public MyService Me => this;
|
[Export] public MyService Me => this;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,8 @@ using System.Collections.Generic;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Esiur.Security.Cryptography;
|
||||||
|
|
||||||
namespace Test
|
namespace Test
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -53,6 +54,19 @@ namespace Test
|
|||||||
{
|
{
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var a = new ECDH();
|
||||||
|
var b = new ECDH();
|
||||||
|
|
||||||
|
var apk = a.GetPublicKey();
|
||||||
|
var bpk = b.GetPublicKey();
|
||||||
|
|
||||||
|
var ska = a.ComputeSharedKey(bpk);
|
||||||
|
var skb = b.ComputeSharedKey(apk);
|
||||||
|
|
||||||
|
Console.WriteLine(ska.ToHex());
|
||||||
|
Console.WriteLine(skb.ToHex());
|
||||||
|
|
||||||
// Create stores to keep objects.
|
// Create stores to keep objects.
|
||||||
var system = await Warehouse.Put("sys", new MemoryStore());
|
var system = await Warehouse.Put("sys", new MemoryStore());
|
||||||
var server = await Warehouse.Put("sys/server", new DistributedServer());
|
var server = await Warehouse.Put("sys/server", new DistributedServer());
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Esiur.Generator\Esiur.Security.Cryptography.csproj" />
|
||||||
<ProjectReference Include="..\Esiur\Esiur.csproj" OutputItemType="Analyzer" />
|
<ProjectReference Include="..\Esiur\Esiur.csproj" OutputItemType="Analyzer" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user