[#xxxx] policy: Hash entity name to support large namespaces

Namespace is a part of entity name, so it should be hashed
in order to fit neo-go storage key.

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
Alexey Vanin 2024-04-12 19:18:46 +03:00
parent 5b0ea5e0a8
commit 670c74610b
2 changed files with 7 additions and 1 deletions

View file

@ -4,6 +4,7 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
"github.com/nspcc-dev/neo-go/pkg/interop/native/crypto"
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
@ -107,6 +108,9 @@ func storageKey(prefix Kind, counter int, name []byte) []byte {
}
func mapKey(kind Kind, name []byte) []byte {
if len(name) > 0 {
name = crypto.Sha256(name)
}
return append([]byte{mappingKeyPrefix, byte(kind)}, name...)
}

View file

@ -2,6 +2,7 @@ package tests
import (
"bytes"
"crypto/sha256"
"path"
"testing"
@ -185,8 +186,9 @@ func checkTargets(t *testing.T, e *neotest.ContractInvoker, kind byte, expected
require.Equal(t, len(expected), len(targets))
for i := range expected {
exp := sha256.Sum256(expected[i])
bytesTargets, err := targets[i].TryBytes()
require.NoError(t, err)
require.Equal(t, expected[i], bytesTargets)
require.Equal(t, exp[:], bytesTargets)
}
}