THe whole set of bindigns.
This commit is contained in:
3027
SpaceWizards.Sodium.Interop/Generated/Methods.cs
Normal file
3027
SpaceWizards.Sodium.Interop/Generated/Methods.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
/// <summary>Defines the base type of a struct as it was in the native signature.</summary>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
|
||||
[Conditional("DEBUG")]
|
||||
internal sealed partial class NativeInheritanceAttribute : Attribute
|
||||
{
|
||||
private readonly string _name;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="NativeInheritanceAttribute" /> class.</summary>
|
||||
/// <param name="name">The name of the base type that was inherited from in the native signature.</param>
|
||||
public NativeInheritanceAttribute(string name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/// <summary>Gets the name of the base type that was inherited from in the native signature.</summary>
|
||||
public string Name => _name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
/// <summary>Defines the type of a member as it was used in the native signature.</summary>
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)]
|
||||
[Conditional("DEBUG")]
|
||||
internal sealed partial class NativeTypeNameAttribute : Attribute
|
||||
{
|
||||
private readonly string _name;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="NativeTypeNameAttribute" /> class.</summary>
|
||||
/// <param name="name">The name of the type that was used in the native signature.</param>
|
||||
public NativeTypeNameAttribute(string name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/// <summary>Gets the name of the type that was used in the native signature.</summary>
|
||||
public string Name => _name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
/// <summary>Specifies that the given method sets the last system error and it can be retrieved via <see cref="Marshal.GetLastSystemError" />.</summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
[Conditional("DEBUG")]
|
||||
internal sealed partial class SetsLastSystemErrorAttribute : Attribute
|
||||
{
|
||||
/// <summary>Initializes a new instance of the <see cref="SetsLastSystemErrorAttribute" /> class.</summary>
|
||||
public SetsLastSystemErrorAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
23
SpaceWizards.Sodium.Interop/Generated/VtblIndexAttribute.cs
Normal file
23
SpaceWizards.Sodium.Interop/Generated/VtblIndexAttribute.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
/// <summary>Defines the vtbl index of a method as it was in the native signature.</summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
[Conditional("DEBUG")]
|
||||
internal sealed partial class VtblIndexAttribute : Attribute
|
||||
{
|
||||
private readonly uint _index;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="VtblIndexAttribute" /> class.</summary>
|
||||
/// <param name="index">The vtbl index of a method as it was in the native signature.</param>
|
||||
public VtblIndexAttribute(uint index)
|
||||
{
|
||||
_index = index;
|
||||
}
|
||||
|
||||
/// <summary>Gets the vtbl index of a method as it was in the native signature.</summary>
|
||||
public uint Index => _index;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public unsafe partial struct crypto_aead_aes256gcm_state
|
||||
{
|
||||
[NativeTypeName("unsigned char [512]")]
|
||||
public fixed byte opaque[512];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public partial struct crypto_auth_hmacsha256_state
|
||||
{
|
||||
public crypto_hash_sha256_state ictx;
|
||||
|
||||
public crypto_hash_sha256_state octx;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public partial struct crypto_auth_hmacsha512256_state
|
||||
{
|
||||
public crypto_hash_sha512_state ictx;
|
||||
|
||||
public crypto_hash_sha512_state octx;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public unsafe partial struct crypto_generichash_blake2b_state
|
||||
{
|
||||
[NativeTypeName("unsigned char [384]")]
|
||||
public fixed byte opaque[384];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public unsafe partial struct crypto_hash_sha256_state
|
||||
{
|
||||
[NativeTypeName("uint32_t [8]")]
|
||||
public fixed uint state[8];
|
||||
|
||||
[NativeTypeName("uint64_t")]
|
||||
public ulong count;
|
||||
|
||||
[NativeTypeName("uint8_t [64]")]
|
||||
public fixed byte buf[64];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public unsafe partial struct crypto_hash_sha512_state
|
||||
{
|
||||
[NativeTypeName("uint64_t [8]")]
|
||||
public fixed ulong state[8];
|
||||
|
||||
[NativeTypeName("uint64_t [2]")]
|
||||
public fixed ulong count[2];
|
||||
|
||||
[NativeTypeName("uint8_t [128]")]
|
||||
public fixed byte buf[128];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public unsafe partial struct crypto_onetimeauth_poly1305_state
|
||||
{
|
||||
[NativeTypeName("unsigned char [256]")]
|
||||
public fixed byte opaque[256];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public unsafe partial struct crypto_secretstream_xchacha20poly1305_state
|
||||
{
|
||||
[NativeTypeName("unsigned char [32]")]
|
||||
public fixed byte k[32];
|
||||
|
||||
[NativeTypeName("unsigned char [12]")]
|
||||
public fixed byte nonce[12];
|
||||
|
||||
[NativeTypeName("unsigned char [8]")]
|
||||
public fixed byte _pad[8];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public partial struct crypto_sign_ed25519ph_state
|
||||
{
|
||||
public crypto_hash_sha512_state hs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace SpaceWizards.Sodium.Interop
|
||||
{
|
||||
public unsafe partial struct randombytes_implementation
|
||||
{
|
||||
[NativeTypeName("const char *(*)()")]
|
||||
public delegate* unmanaged[Cdecl]<sbyte*> implementation_name;
|
||||
|
||||
[NativeTypeName("uint32_t (*)()")]
|
||||
public delegate* unmanaged[Cdecl]<uint> random;
|
||||
|
||||
[NativeTypeName("void (*)()")]
|
||||
public delegate* unmanaged[Cdecl]<void> stir;
|
||||
|
||||
[NativeTypeName("uint32_t (*)(const uint32_t)")]
|
||||
public delegate* unmanaged[Cdecl]<uint, uint> uniform;
|
||||
|
||||
[NativeTypeName("void (*)(void *const, const size_t)")]
|
||||
public delegate* unmanaged[Cdecl]<void*, nuint, void> buf;
|
||||
|
||||
[NativeTypeName("int (*)()")]
|
||||
public delegate* unmanaged[Cdecl]<int> close;
|
||||
}
|
||||
}
|
||||
11
SpaceWizards.Sodium.Interop/Methods.Manual.cs
Normal file
11
SpaceWizards.Sodium.Interop/Methods.Manual.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace SpaceWizards.Sodium.Interop;
|
||||
|
||||
public partial class Methods
|
||||
{
|
||||
public static ulong sodium_base64_ENCODED_LEN(ulong BIN_LEN, ulong VARIANT)
|
||||
{
|
||||
return (((BIN_LEN) / 3U) * 4U +
|
||||
((((BIN_LEN) - ((BIN_LEN) / 3U) * 3U) | (((BIN_LEN) - ((BIN_LEN) / 3U) * 3U) >> 1)) & 1U) *
|
||||
(4U - (~((((VARIANT) & 2U) >> 1) - 1U) & (3U - ((BIN_LEN) - ((BIN_LEN) / 3U) * 3U)))) + 1U);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Generated" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="libsodium" Version="1.0.18.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace SpaceWizards.Sodium.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// WARNING: This type MUST be aligned to a 16-byte boundary.
|
||||
/// .NET does not currently have a method of specifying this at the type level,
|
||||
/// so you need to manage this yourself when allocating space or such.
|
||||
/// </summary>
|
||||
public unsafe partial struct crypto_aead_aes256gcm_state
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace SpaceWizards.Sodium.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// WARNING: This type MUST be aligned to a 64-byte boundary.
|
||||
/// .NET does not currently have a method of specifying this at the type level,
|
||||
/// so you need to manage this yourself when allocating space or such.
|
||||
/// </summary>
|
||||
public unsafe partial struct crypto_generichash_blake2b_state
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace SpaceWizards.Sodium.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// WARNING: This type MUST be aligned to a 16-byte boundary.
|
||||
/// .NET does not currently have a method of specifying this at the type level,
|
||||
/// so you need to manage this yourself when allocating space or such.
|
||||
/// </summary>
|
||||
public unsafe partial struct crypto_onetimeauth_poly1305_state
|
||||
{
|
||||
}
|
||||
36
SpaceWizards.Sodium.Tests/SecretBoxTest.cs
Normal file
36
SpaceWizards.Sodium.Tests/SecretBoxTest.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Security.Cryptography;
|
||||
using NUnit.Framework;
|
||||
using static SpaceWizards.Sodium.Interop.Methods;
|
||||
|
||||
namespace SpaceWizards.Sodium.Tests;
|
||||
|
||||
[TestFixture]
|
||||
public sealed class SecretBoxTest
|
||||
{
|
||||
[Test]
|
||||
public unsafe void Test()
|
||||
{
|
||||
var message = RandomNumberGenerator.GetBytes(1024);
|
||||
var cipher = RandomNumberGenerator.GetBytes((int)(1024 + crypto_secretbox_MACBYTES));
|
||||
|
||||
var key = stackalloc byte[(int)crypto_secretbox_KEYBYTES];
|
||||
var nonce = stackalloc byte[(int)crypto_secretbox_NONCEBYTES];
|
||||
|
||||
crypto_secretbox_keygen(key);
|
||||
randombytes_buf(nonce, crypto_secretbox_NONCEBYTES);
|
||||
fixed (byte* mPtr = message)
|
||||
fixed (byte* cPtr = cipher)
|
||||
{
|
||||
crypto_secretbox_easy(cPtr, mPtr, (ulong)message.Length, nonce, key);
|
||||
}
|
||||
|
||||
var decrypted = new byte[message.Length];
|
||||
fixed (byte* dPtr = decrypted)
|
||||
fixed (byte* cPtr = cipher)
|
||||
{
|
||||
crypto_secretbox_open_easy(dPtr, cPtr, (ulong)cipher.Length, nonce, key);
|
||||
}
|
||||
|
||||
Assert.That(decrypted, Is.EquivalentTo(message));
|
||||
}
|
||||
}
|
||||
26
SpaceWizards.Sodium.Tests/SpaceWizards.Sodium.Tests.csproj
Normal file
26
SpaceWizards.Sodium.Tests/SpaceWizards.Sodium.Tests.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SpaceWizards.Sodium.Interop\SpaceWizards.Sodium.Interop.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -12,6 +12,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution
|
||||
LICENSE.txt = LICENSE.txt
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpaceWizards.Sodium.Interop", "SpaceWizards.Sodium.Interop\SpaceWizards.Sodium.Interop.csproj", "{4565084B-3F40-44EA-B0B8-75DBFB9398EB}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{7F6778F9-368B-4F4E-BC12-88AA25F85329}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Scripts\GenBindings.rsp = Scripts\GenBindings.rsp
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpaceWizards.Sodium.Tests", "SpaceWizards.Sodium.Tests\SpaceWizards.Sodium.Tests.csproj", "{5E1C1FFF-6F86-4D33-9038-CF314CF1320B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -25,5 +34,16 @@ Global
|
||||
{52EC2D2E-B57B-45E3-944A-247C750731C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{52EC2D2E-B57B-45E3-944A-247C750731C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{52EC2D2E-B57B-45E3-944A-247C750731C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4565084B-3F40-44EA-B0B8-75DBFB9398EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4565084B-3F40-44EA-B0B8-75DBFB9398EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4565084B-3F40-44EA-B0B8-75DBFB9398EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4565084B-3F40-44EA-B0B8-75DBFB9398EB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5E1C1FFF-6F86-4D33-9038-CF314CF1320B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5E1C1FFF-6F86-4D33-9038-CF314CF1320B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5E1C1FFF-6F86-4D33-9038-CF314CF1320B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5E1C1FFF-6F86-4D33-9038-CF314CF1320B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{7F6778F9-368B-4F4E-BC12-88AA25F85329} = {40BDE6AC-8B1C-4E85-960E-B3D9EA0FEC6C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user