Update README

This commit is contained in:
2025-03-18 12:54:14 +13:00
parent 93108d7032
commit 4b78d0619b
14 changed files with 2 additions and 3304 deletions

View File

@@ -1,14 +1,3 @@
# SpaceWizards.Sodium [![Nuget](https://img.shields.io/nuget/v/SpaceWizards.Sodium)](https://www.nuget.org/packages/SpaceWizards.Sodium/)
# CSSUDII.Sodium
A .NET [libsodium](https://libsodium.gitbook.io/doc/) binding that doesn't suck. Actually exposes the native API so you don't have to cry yourself to sleep in unnecessary allocations or OOP nonsense.
Currently depends on the ["libsodium" NuGet package](https://www.nuget.org/packages/libsodium/) provided by [Sodium.Core](https://github.com/ektrah/libsodium-core) for the native library. They say you shouldn't depend on it directly but I am too lazy to compile them myself so deal with it.
# API Shape
There is a low-level API in `SpaceWizards.Sodium.Interop`. This is a raw P/Invoke binding, hope you like pointers.
The high-level API in `SpaceWizards.Sodium` generally has two variants: span with return code, or `byte[]` with exceptions. Note that the former still throws exceptions if you pass spans that are too small, but otherwise failing return codes from libsodium are passed through so you can handle them. This is just what I decided to settle on to keep API size down.
Also, if it wasn't obvious, the only API wrapped is the ones I needed at the moment. PRs welcome I guess.
.NET 8 [libsodium](https://libsodium.gitbook.io/doc/) bindings.

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +0,0 @@
using System;
using System.Diagnostics;
namespace CSSUDII.Sodium.Interop
{
/// <summary>Defines the annotation found in a native declaration.</summary>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
[Conditional("DEBUG")]
internal sealed partial class NativeAnnotationAttribute : Attribute
{
private readonly string _annotation;
/// <summary>Initializes a new instance of the <see cref="NativeAnnotationAttribute" /> class.</summary>
/// <param name="annotation">The annotation that was used in the native declaration.</param>
public NativeAnnotationAttribute(string annotation)
{
_annotation = annotation;
}
/// <summary>Gets the annotation that was used in the native declaration.</summary>
public string Annotation => _annotation;
}
}

View File

@@ -1,23 +0,0 @@
using System;
using System.Diagnostics;
namespace CSSUDII.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;
}
}

View File

@@ -1,16 +0,0 @@
using System.Runtime.CompilerServices;
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_aead_aes256gcm_state
{
[NativeTypeName("unsigned char[512]")]
public _opaque_e__FixedBuffer opaque;
[InlineArray(512)]
public partial struct _opaque_e__FixedBuffer
{
public byte e0;
}
}
}

View File

@@ -1,9 +0,0 @@
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_auth_hmacsha256_state
{
public crypto_hash_sha256_state ictx;
public crypto_hash_sha256_state octx;
}
}

View File

@@ -1,9 +0,0 @@
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_auth_hmacsha512256_state
{
public crypto_hash_sha512_state ictx;
public crypto_hash_sha512_state octx;
}
}

View File

@@ -1,16 +0,0 @@
using System.Runtime.CompilerServices;
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_generichash_blake2b_state
{
[NativeTypeName("unsigned char[384]")]
public _opaque_e__FixedBuffer opaque;
[InlineArray(384)]
public partial struct _opaque_e__FixedBuffer
{
public byte e0;
}
}
}

View File

@@ -1,28 +0,0 @@
using System.Runtime.CompilerServices;
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_hash_sha256_state
{
[NativeTypeName("uint32_t[8]")]
public _state_e__FixedBuffer state;
[NativeTypeName("uint64_t")]
public ulong count;
[NativeTypeName("uint8_t[64]")]
public _buf_e__FixedBuffer buf;
[InlineArray(8)]
public partial struct _state_e__FixedBuffer
{
public uint e0;
}
[InlineArray(64)]
public partial struct _buf_e__FixedBuffer
{
public byte e0;
}
}
}

View File

@@ -1,34 +0,0 @@
using System.Runtime.CompilerServices;
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_hash_sha512_state
{
[NativeTypeName("uint64_t[8]")]
public _state_e__FixedBuffer state;
[NativeTypeName("uint64_t[2]")]
public _count_e__FixedBuffer count;
[NativeTypeName("uint8_t[128]")]
public _buf_e__FixedBuffer buf;
[InlineArray(8)]
public partial struct _state_e__FixedBuffer
{
public ulong e0;
}
[InlineArray(2)]
public partial struct _count_e__FixedBuffer
{
public ulong e0;
}
[InlineArray(128)]
public partial struct _buf_e__FixedBuffer
{
public byte e0;
}
}
}

View File

@@ -1,16 +0,0 @@
using System.Runtime.CompilerServices;
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_onetimeauth_poly1305_state
{
[NativeTypeName("unsigned char[256]")]
public _opaque_e__FixedBuffer opaque;
[InlineArray(256)]
public partial struct _opaque_e__FixedBuffer
{
public byte e0;
}
}
}

View File

@@ -1,34 +0,0 @@
using System.Runtime.CompilerServices;
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_secretstream_xchacha20poly1305_state
{
[NativeTypeName("unsigned char[32]")]
public _k_e__FixedBuffer k;
[NativeTypeName("unsigned char[12]")]
public _nonce_e__FixedBuffer nonce;
[NativeTypeName("unsigned char[8]")]
public __pad_e__FixedBuffer _pad;
[InlineArray(32)]
public partial struct _k_e__FixedBuffer
{
public byte e0;
}
[InlineArray(12)]
public partial struct _nonce_e__FixedBuffer
{
public byte e0;
}
[InlineArray(8)]
public partial struct __pad_e__FixedBuffer
{
public byte e0;
}
}
}

View File

@@ -1,7 +0,0 @@
namespace CSSUDII.Sodium.Interop
{
public partial struct crypto_sign_ed25519ph_state
{
public crypto_hash_sha512_state hs;
}
}

View File

@@ -1,23 +0,0 @@
namespace CSSUDII.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;
}
}