Skip to content

Commit

Permalink
update: interop cs files
Browse files Browse the repository at this point in the history
  • Loading branch information
netpyoung committed Oct 15, 2023
1 parent 556b081 commit 9b1af55
Show file tree
Hide file tree
Showing 14 changed files with 500 additions and 211 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Diagnostics;

namespace unity.libsodium.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;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace unity.libsodium.Interop
{
public unsafe partial struct crypto_aead_aes256gcm_state_
{
[NativeTypeName("unsigned char [512]")]
[NativeTypeName("unsigned char[512]")]
public fixed byte opaque[512];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace unity.libsodium.Interop
{
public unsafe partial struct crypto_generichash_blake2b_state
{
[NativeTypeName("unsigned char [384]")]
[NativeTypeName("unsigned char[384]")]
public fixed byte opaque[384];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace unity.libsodium.Interop
{
public unsafe partial struct crypto_hash_sha256_state
{
[NativeTypeName("uint32_t [8]")]
[NativeTypeName("uint32_t[8]")]
public fixed uint state[8];

[NativeTypeName("uint64_t")]
public ulong count;

[NativeTypeName("uint8_t [64]")]
[NativeTypeName("uint8_t[64]")]
public fixed byte buf[64];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace unity.libsodium.Interop
{
public unsafe partial struct crypto_hash_sha512_state
{
[NativeTypeName("uint64_t [8]")]
[NativeTypeName("uint64_t[8]")]
public fixed ulong state[8];

[NativeTypeName("uint64_t [2]")]
[NativeTypeName("uint64_t[2]")]
public fixed ulong count[2];

[NativeTypeName("uint8_t [128]")]
[NativeTypeName("uint8_t[128]")]
public fixed byte buf[128];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace unity.libsodium.Interop
{
public partial struct crypto_kdf_hkdf_sha256_state
{
public crypto_auth_hmacsha256_state st;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace unity.libsodium.Interop
{
public partial struct crypto_kdf_hkdf_sha512_state
{
public crypto_auth_hmacsha512_state st;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace unity.libsodium.Interop
{
public unsafe partial struct crypto_onetimeauth_poly1305_state
{
[NativeTypeName("unsigned char [256]")]
[NativeTypeName("unsigned char[256]")]
public fixed byte opaque[256];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace unity.libsodium.Interop
{
public unsafe partial struct crypto_secretstream_xchacha20poly1305_state
{
[NativeTypeName("unsigned char [32]")]
[NativeTypeName("unsigned char[32]")]
public fixed byte k[32];

[NativeTypeName("unsigned char [12]")]
[NativeTypeName("unsigned char[12]")]
public fixed byte nonce[12];

[NativeTypeName("unsigned char [8]")]
[NativeTypeName("unsigned char[8]")]
public fixed byte _pad[8];
}
}
613 changes: 416 additions & 197 deletions unity.libsodium/Assets/unity.libsodium/NativeLibsodium.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions unity.libsodium/Assets/unity.libsodium/StreamEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static unsafe byte[] GetRandomBytes(int count)
byte[] buffer = new byte[count];
fixed (byte* bufferPtr = buffer)
{
NativeLibsodium.randombytes_buf(bufferPtr, count);
NativeLibsodium.randombytes_buf(bufferPtr, (uint)count);
}
return buffer;
}
Expand All @@ -103,8 +103,8 @@ unsafe public static byte[] HexToBinary(string hex)
{
//we call sodium_hex2bin with some chars to be ignored
int ret = NativeLibsodium.sodium_hex2bin(
arrPtr, arr.Length,
hex, hexBytes.Length,
arrPtr, (uint)arr.Length,
hex, (uint)hexBytes.Length,
IGNORED_CHARS,
out binLength,
null
Expand Down

0 comments on commit 9b1af55

Please sign in to comment.