From 86121bbfc1053badfeea08ce6d1990a0aa6c0a28 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 6 Dec 2024 18:06:26 -0800 Subject: [PATCH] implement siphash (confirmed identical hash) --- go.mod | 1 + go.sum | 2 ++ pkg/service/scripts.go | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c583719..20ab013 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ toolchain go1.23.3 require ( git.itzana.me/strafesnet/go-grpc v0.0.0-20241129081229-9e166b3d11f7 git.itzana.me/strafesnet/utils v0.0.0-20220716194944-d8ca164052f9 + github.com/dchest/siphash v1.2.3 github.com/go-faster/errors v0.7.1 github.com/go-faster/jx v1.1.0 github.com/ogen-go/ogen v1.2.1 diff --git a/go.sum b/go.sum index 937e93e..79efebe 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA= +github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc= github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/pkg/service/scripts.go b/pkg/service/scripts.go index d502c6e..10ecdba 100644 --- a/pkg/service/scripts.go +++ b/pkg/service/scripts.go @@ -7,6 +7,7 @@ import ( "git.itzana.me/strafesnet/maps-service/pkg/api" "git.itzana.me/strafesnet/maps-service/pkg/datastore" "git.itzana.me/strafesnet/maps-service/pkg/model" + "github.com/dchest/siphash" ) var ( @@ -29,7 +30,7 @@ func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*a script, err := svc.DB.Scripts().Create(ctx, model.Script{ ID: 0, - Hash: 0, // TODO + Hash: siphash.Hash(0,0,[]byte(req.Source)), Source: req.Source, SubmissionID: req.SubmissionID.Or(0), }) @@ -101,8 +102,7 @@ func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, par pmap := datastore.Optional() if source,ok:=req.Source.Get();ok{ pmap.Add("source",source) - panic("unimplemented") - pmap.Add("from_script_hash",0) + pmap.Add("hash",siphash.Hash(0,0,[]byte(source))) } if SubmissionID,ok:=req.SubmissionID.Get();ok{ pmap.Add("submission_id",SubmissionID)