Skip to content

Commit

Permalink
Bind out crc64 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin authored Oct 21, 2024
1 parent 37e50ac commit 026a707
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
Expand Down
9 changes: 9 additions & 0 deletions aws-crt-checksums/Crc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ public delegate UInt32 aws_dotnet_crc32([In, MarshalAs(UnmanagedType.LPArray, Si
[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
public delegate UInt32 aws_dotnet_crc32c([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2, ArraySubType = UnmanagedType.U1)] byte[] buffer,
Int32 length, UInt32 previous);

[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
public delegate UInt64 aws_dotnet_crc64nvme([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2, ArraySubType = UnmanagedType.U1)] byte[] buffer,
Int32 length, UInt64 previous);

public static aws_dotnet_crc32 crc32 = NativeAPI.Bind<aws_dotnet_crc32>();
public static aws_dotnet_crc32c crc32c = NativeAPI.Bind<aws_dotnet_crc32c>();
public static aws_dotnet_crc64nvme crc64nvme = NativeAPI.Bind<aws_dotnet_crc64nvme>();
}
public static uint crc32(byte[] buffer, uint previous = 0)
{
Expand All @@ -30,5 +35,9 @@ public static uint crc32c(byte[] buffer, uint previous = 0)
{
return API.crc32c(buffer, buffer.Length, previous);
}
public static ulong crc64nvme(byte[] buffer, ulong previous = 0)
{
return API.crc64nvme(buffer, buffer.Length, previous);
}
}
}
9 changes: 7 additions & 2 deletions native/src/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@

AWS_DOTNET_API
uint32_t aws_dotnet_crc32(const uint8_t *input, int length, uint32_t previous) {
return aws_checksums_crc32(input, length, previous);
return aws_checksums_crc32_ex(input, (size_t)length, previous);
}

AWS_DOTNET_API
uint32_t aws_dotnet_crc32c(const uint8_t *input, int length, uint32_t previous) {
return aws_checksums_crc32c(input, length, previous);
return aws_checksums_crc32c_ex(input, (size_t)length, previous);
}

AWS_DOTNET_API
uint64_t aws_dotnet_crc64nvme(const uint8_t *input, int length, uint64_t previous) {
return aws_checksums_crc64nvme_ex(input, (size_t)length, previous);
}
18 changes: 18 additions & 0 deletions tests/CrcTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,23 @@ public void TestCrc32cLargeBuffer()
uint expected = 0xfb5b991d;
Assert.Equal(expected, res);
}
[Fact]
public void TestCrc64NVMEZeroes()
{
byte[] zeroes = new byte[32];
ulong res = Crc.crc64nvme(zeroes);
ulong expected = 0xCF3473434D4ECF3B;
Assert.Equal(expected, res);
}
[Fact]
public void TestCrc64NVMEZeroesIterated()
{
ulong res = 0;
for (int i = 0; i < 32; i++) {
res = Crc.crc64nvme(new byte[1], res);
}
ulong expected = 0xCF3473434D4ECF3B;
Assert.Equal(expected, res);
}
}
}

0 comments on commit 026a707

Please sign in to comment.