2020-07-24 13:54:03 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EACLArgs groups the arguments
|
|
|
|
// of get eACL test invoke call.
|
|
|
|
type EACLArgs struct {
|
|
|
|
cid []byte // container identifier
|
|
|
|
}
|
|
|
|
|
|
|
|
// EACLValues groups the stack parameters
|
|
|
|
// returned by get eACL test invoke.
|
|
|
|
type EACLValues struct {
|
|
|
|
eacl []byte // extended ACL table
|
2020-09-04 12:18:47 +00:00
|
|
|
|
2021-01-14 16:00:10 +00:00
|
|
|
signature []byte // RFC-6979 signature of extended ACL table
|
|
|
|
|
|
|
|
publicKey []byte // public key of the extended ACL table signer
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetCID sets the container identifier
|
|
|
|
// in a binary format.
|
|
|
|
func (g *EACLArgs) SetCID(v []byte) {
|
|
|
|
g.cid = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// EACL returns the eACL table
|
|
|
|
// in a binary format.
|
|
|
|
func (g *EACLValues) EACL() []byte {
|
|
|
|
return g.eacl
|
|
|
|
}
|
|
|
|
|
2021-01-14 16:00:10 +00:00
|
|
|
// Signature returns RFC-6979 signature of extended ACL table.
|
2020-09-04 12:18:47 +00:00
|
|
|
func (g *EACLValues) Signature() []byte {
|
|
|
|
return g.signature
|
|
|
|
}
|
|
|
|
|
2021-01-14 16:00:10 +00:00
|
|
|
// PublicKey of the signature.
|
|
|
|
func (g *EACLValues) PublicKey() []byte {
|
|
|
|
return g.publicKey
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// EACL performs the test invoke of get eACL
|
|
|
|
// method of NeoFS Container contract.
|
|
|
|
func (c *Client) EACL(args EACLArgs) (*EACLValues, error) {
|
|
|
|
prms, err := c.client.TestInvoke(
|
|
|
|
c.eaclMethod,
|
|
|
|
args.cid,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.eaclMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
} else if ln := len(prms); ln != 1 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.eaclMethod, ln)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 12:18:47 +00:00
|
|
|
arr, err := client.ArrayFromStackItem(prms[0])
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get item array of eACL (%s): %w", c.eaclMethod, err)
|
2020-09-04 12:18:47 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 14:46:34 +00:00
|
|
|
if len(arr) != 4 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("unexpected eacl stack item count (%s): %d", c.eaclMethod, len(arr))
|
2020-09-04 12:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
eacl, err := client.BytesFromStackItem(arr[0])
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array of eACL (%s): %w", c.eaclMethod, err)
|
2020-09-04 12:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sig, err := client.BytesFromStackItem(arr[1])
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array of eACL signature (%s): %w", c.eaclMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 16:00:10 +00:00
|
|
|
pub, err := client.BytesFromStackItem(arr[2])
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array of eACL public key (%s): %w", c.eaclMethod, err)
|
2021-01-14 16:00:10 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
return &EACLValues{
|
2020-09-04 12:18:47 +00:00
|
|
|
eacl: eacl,
|
|
|
|
signature: sig,
|
2021-01-14 16:00:10 +00:00
|
|
|
publicKey: pub,
|
2020-07-24 13:54:03 +00:00
|
|
|
}, nil
|
|
|
|
}
|