forked from TrueCloudLab/frostfs-api-go
[#217] pkg/eacl: Change interface for working with keys on Target and Record
In previous implementation Target provided Keys/SetKeys methods which allowed working with ECDSA keys. There was also a bug in the NewTargetFromV2 function when the binary key differed in format from the ECDSA key. New BinaryKeys/SetBinaryKeys methods work with binary keys. To work with ECDSA keys added functions TargetECDSAKeys/SetTargetECDSAKeys. Old methods are left and marked deprecated. Type Record provided an interface for adding a Target by Role and a list of ECDSA keys. New SetTargets method allows to set the list of Target's, AddTarget function allows to add a single Target. AddFormedTarget works like old AddTarget method, which is now deprecated. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
2a94fdc5e7
commit
c01024b553
4 changed files with 134 additions and 43 deletions
|
@ -11,22 +11,21 @@ import (
|
|||
)
|
||||
|
||||
func TestTarget(t *testing.T) {
|
||||
keys := []ecdsa.PublicKey{
|
||||
test.DecodeKey(1).PublicKey,
|
||||
test.DecodeKey(2).PublicKey,
|
||||
keys := []*ecdsa.PublicKey{
|
||||
&test.DecodeKey(1).PublicKey,
|
||||
&test.DecodeKey(2).PublicKey,
|
||||
}
|
||||
|
||||
target := &Target{
|
||||
role: RoleSystem,
|
||||
keys: keys,
|
||||
}
|
||||
target := NewTarget()
|
||||
target.SetRole(RoleSystem)
|
||||
SetTargetECDSAKeys(target, keys...)
|
||||
|
||||
v2 := target.ToV2()
|
||||
require.NotNil(t, v2)
|
||||
require.Equal(t, v2acl.RoleSystem, v2.GetRole())
|
||||
require.Len(t, v2.GetKeys(), len(keys))
|
||||
for i, key := range v2.GetKeys() {
|
||||
require.Equal(t, key, crypto.MarshalPublicKey(&keys[i]))
|
||||
require.Equal(t, key, crypto.MarshalPublicKey(keys[i]))
|
||||
}
|
||||
|
||||
newTarget := NewTargetFromV2(v2)
|
||||
|
@ -40,7 +39,7 @@ func TestTarget(t *testing.T) {
|
|||
func TestTargetEncoding(t *testing.T) {
|
||||
tar := NewTarget()
|
||||
tar.SetRole(RoleSystem)
|
||||
tar.SetKeys(test.DecodeKey(-1).PublicKey)
|
||||
SetTargetECDSAKeys(tar, &test.DecodeKey(-1).PublicKey)
|
||||
|
||||
t.Run("binary", func(t *testing.T) {
|
||||
data, err := tar.Marshal()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue