-
Notifications
You must be signed in to change notification settings - Fork 0
CalculateHash #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SupinePandora43
wants to merge
29
commits into
main
Choose a base branch
from
HashCalc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
018d191
initial
SupinePandora43 9cdc7cf
NativeMath actions
SupinePandora43 2e9f0dd
net5
SupinePandora43 baee905
set NativeMath to nil
SupinePandora43 5560ec6
free NativeMath using GCHandle
SupinePandora43 5760496
lua tests
SupinePandora43 3fd9906
math.Approach
SupinePandora43 4068c9d
donothingwithit
SupinePandora43 414eab0
handles list
SupinePandora43 def37ed
current
SupinePandora43 b0d3d94
thousand
SupinePandora43 7a02eb0
current
SupinePandora43 a388698
Distance
SupinePandora43 2b60337
disable jit
SupinePandora43 6fc8605
enable JIT
SupinePandora43 29cac01
HashCalc
SupinePandora43 95a2c41
ToString("X2")
SupinePandora43 34ec90f
print
SupinePandora43 d274c4a
builder
SupinePandora43 b2a8ebf
return 1
SupinePandora43 1c2c848
fix casing
SupinePandora43 4c340b9
sha256 unicode test
SupinePandora43 fc08c76
CalculateHash
SupinePandora43 c6659d7
md5 test
SupinePandora43 cbe2384
SHA512
SupinePandora43 722c572
Managed function
SupinePandora43 62e180b
remove unused includes
SupinePandora43 064c040
add hashName check
SupinePandora43 0d173d2
add timeout minutes
SupinePandora43 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
name: Build & Test | ||
on: | ||
push: | ||
branches: [ main, HashCalc ] | ||
pull_request: | ||
branches: [ main ] | ||
jobs: | ||
linux: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET Core | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 5.0.100 | ||
- name: Install dependencies | ||
run: dotnet restore Examples.sln | ||
- name: Install Steam and Garry's Mod Dedicated Server | ||
run: | | ||
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz | ||
tar -xvzf steamcmd_linux.tar.gz | ||
rm -rfv steamcmd_linux.tar.gz | ||
./steamcmd.sh +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit | ||
- name: Install GmodDotNet | ||
run: | | ||
wget https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-linux.0.7.0-beta.2.30293992.master.tar.gz -O gmoddotnet.tar.gz | ||
mkdir ./gmod/garrysmod/lua/bin | ||
tar -xvzf gmoddotnet.tar.gz -C ./gmod/garrysmod/lua/bin | ||
rm -rfv gmoddotnet.tar.gz | ||
- name: Build Module | ||
run: dotnet publish HashCalc/HashCalc.csproj --configuration Release --framework net5 -o ./gmod/garrysmod/lua/bin/Modules/HashCalc | ||
- name: Upload a Build Artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: HashCalc linux-x64 | ||
path: ./gmod/garrysmod/lua/bin/Modules/HashCalc/* | ||
retention-days: 10 | ||
- name: Copy test.lua | ||
run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun | ||
- name: Run Garry's Mod | ||
run: ./srcds_run_x64 -game garrysmod -systemtest -condebug +sv_hibernate_think 1 || true | ||
working-directory: ./gmod/ | ||
timeout-minutes: 1 | ||
continue-on-error: true | ||
- name: Print log | ||
run: cat gmod/garrysmod/console.log | ||
- name: Tests successfull? | ||
uses: andstor/file-existence-action@v1 | ||
with: | ||
files: "gmod/garrysmod/data/success.txt" | ||
allow_failure: true | ||
windows-build: | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET Core SDK | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 5.0.100 | ||
- name: Install dependencies | ||
run: dotnet restore Examples.sln | ||
- name: Install Steam and Garry's Mod Dedicated Server | ||
shell: bash | ||
run: | | ||
curl https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip -O -L | ||
powershell -Command 'Expand-Archive -LiteralPath ./steamcmd.zip -DestinationPath ./' | ||
./steamcmd.exe +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit || true | ||
- name: Install GmodDotNet | ||
shell: bash | ||
run: | | ||
curl -o gmoddotnet.zip https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-windows.0.7.0-beta.2.30293992.master.zip -O -L | ||
mkdir ./gmod/garrysmod/lua/bin | ||
powershell -Command 'Expand-Archive -LiteralPath ./gmoddotnet.zip -DestinationPath ./gmod/garrysmod/lua/bin' | ||
- name: Build Module | ||
run: dotnet publish HashCalc/HashCalc.csproj --configuration Release --framework net5 -o ./gmod/garrysmod/lua/bin/Modules/HashCalc | ||
- name: Upload a Build Artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: HashCalc win-x64 | ||
path: ./gmod/garrysmod/lua/bin/Modules/HashCalc/* | ||
retention-days: 10 | ||
- name: Copy test.lua | ||
run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun | ||
- name: Run Garry's Mod | ||
shell: bash | ||
run: | | ||
powershell -Command './gmod/srcds_win64.exe -console -systemtest -condebug -game "garrysmod" +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 16 +sv_hibernate_think 1' | ||
powershell -Command 'Wait-Process -Name srcds_win64' | ||
timeout-minutes: 1 | ||
continue-on-error: true | ||
- name: Print log | ||
shell: bash | ||
run: cat gmod/garrysmod/console.log | ||
- name: Tests successfull? | ||
id: check_files | ||
uses: andstor/file-existence-action@v1 | ||
with: | ||
files: "gmod/garrysmod/data/success.txt" | ||
allow_failure: true | ||
macos-build: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET Core | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 5.0.100 | ||
- name: Install dependencies | ||
run: dotnet restore Examples.sln | ||
- name: Build Module | ||
run: dotnet publish Examples.sln --configuration Release --framework net5 | ||
- name: Upload a Build Artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: HashCalc osx-x64 | ||
path: HashCalc/bin/Release/net5/osx-x64/publish/* | ||
retention-days: 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
hook.Add("Tick", "Template_CloseServer", engine.CloseServer) | ||
require("dotnet") | ||
|
||
local function run_test() | ||
local module_loaded = dotnet.load("HashCalc") | ||
assert(module_loaded) | ||
|
||
--------SHA256-------- | ||
|
||
local sha256 = CalculateHash("SHA256","test") | ||
assert(sha256==string.upper("9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")) | ||
|
||
local sha256_unicode = CalculateHash("SHA256","♥") | ||
assert(sha256_unicode==string.upper("7c546e1819d9562a67643820b4305c3892fd9a151628e447c8e8dae162fe8f57")) | ||
|
||
---------MD5---------- | ||
|
||
local md5 = CalculateHash("MD5","test") | ||
assert(md5==string.upper("098f6bcd4621d373cade4e832627b4f6")) | ||
|
||
local md5_unicode = CalculateHash("MD5","♥") | ||
assert(md5_unicode==string.upper("d7d4076e1ad9c734baad210480cc903a")) | ||
|
||
--------SHA512-------- | ||
|
||
local sha512 = CalculateHash("SHA512","test") | ||
assert(sha512==string.upper("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff")) | ||
|
||
local sha512_unicode = CalculateHash("SHA512","♥") | ||
assert(sha512_unicode==string.upper("09de9680f8bfc115d42d36646ef28b4cfe3fbffab095bb2ac86c1be9d9ad164a67aa07227d13fea504acf320a68f5fc507c86b803942a7023ccb0e4d23b65f04")) | ||
|
||
---------------------- | ||
|
||
local module_unloaded = dotnet.unload("HashCalc") | ||
assert(module_unloaded) | ||
end | ||
|
||
run_test() | ||
|
||
print("tests are successful!") | ||
file.Write("success.txt", "done") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.vs | ||
bin | ||
obj |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30803.129 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HashCalc", "HashCalc\HashCalc.csproj", "{5849F24D-B5D7-4A48-9469-021DEE4B8531}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{342AA3D8-AFF4-48DE-B97C-DE6E0CF35634}" | ||
ProjectSection(SolutionItems) = preProject | ||
.gitignore = .gitignore | ||
.github\workflows\build.yml = .github\workflows\build.yml | ||
README.md = README.md | ||
.github\workflows\test.lua = .github\workflows\test.lua | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5849F24D-B5D7-4A48-9469-021DEE4B8531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5849F24D-B5D7-4A48-9469-021DEE4B8531}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5849F24D-B5D7-4A48-9469-021DEE4B8531}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5849F24D-B5D7-4A48-9469-021DEE4B8531}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {27D856A3-D44D-42EB-AB15-26DF09A9E065} | ||
EndGlobalSection | ||
EndGlobal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using GmodNET.API; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace NativeMath | ||
{ | ||
public class HashCalc : IModule | ||
{ | ||
public string ModuleName => "HashCalc"; | ||
|
||
public string ModuleVersion => "0.0.1"; | ||
|
||
private List<GCHandle> handles; | ||
|
||
private static readonly string[] hashNames = new[]{ | ||
"SHA", "SHA1", "System.Security.Cryptography.SHA1", "System.Security.Cryptography.HashAlgorithm", | ||
"MD5", "System.Security.Cryptography.MD5", | ||
"SHA256", "SHA-256", "System.Security.Cryptography.SHA256", | ||
"SHA384", "SHA-384", "System.Security.Cryptography.SHA384", | ||
"SHA512", "SHA-512", "System.Security.Cryptography.SHA512" | ||
}; | ||
|
||
private static int CalculateHash(ILua lua) | ||
{ | ||
string hashName = lua.GetString(1); | ||
string data = lua.GetString(2); | ||
if (!hashNames.Contains(hashName)) throw new ArgumentException("invalid hash algorithm name"); | ||
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(hashName); | ||
byte[] hash = hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(data)); | ||
int hashLength = hash.Length; | ||
StringBuilder builder = new(); | ||
for (int i = 0; i < hashLength; i++) | ||
{ | ||
builder.Append(hash[i].ToString("X2")); | ||
} | ||
lua.PushString(builder.ToString()); | ||
return 1; | ||
} | ||
|
||
public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) | ||
{ | ||
handles = new(); | ||
|
||
lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); | ||
GCHandle handle = lua.PushManagedFunction(CalculateHash); | ||
handles.Add(handle); | ||
lua.SetField(-2, "CalculateHash"); | ||
lua.Pop(); | ||
} | ||
|
||
public void Unload(ILua lua) | ||
{ | ||
foreach (var handle in handles) | ||
{ | ||
handle.Free(); | ||
} | ||
handles = null; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>net5</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="GmodNET.API" Version="0.7.0-*" /> | ||
</ItemGroup> | ||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> | ||
<add key="nuget" value="https://api.nuget.org/v3/index.json" /> | ||
<add key="gmodnet-packages" value="https://pkgs.dev.azure.com/GmodNET/gmodnet-artifacts/_packaging/gmodnet-packages/nuget/v3/index.json" /> | ||
</packageSources> | ||
</configuration> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.