implement siphash (confirmed identical hash)

This commit is contained in:
Quaternions 2024-12-06 18:06:26 -08:00
parent a97738b378
commit 86121bbfc1
3 changed files with 6 additions and 3 deletions

1
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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)