diff --git a/audit/result.go b/audit/result.go index c4773cc6..1494bae1 100644 --- a/audit/result.go +++ b/audit/result.go @@ -4,7 +4,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/audit" "github.com/nspcc-dev/neofs-api-go/v2/refs" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" - "github.com/nspcc-dev/neofs-sdk-go/object" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/version" ) @@ -141,7 +141,7 @@ func (r *Result) SetRetries(v uint32) { } // PassSG returns list of Storage Groups that passed audit PoR stage. -func (r *Result) PassSG() []*object.ID { +func (r *Result) PassSG() []*oid.ID { mV2 := (*audit.DataAuditResult)(r). GetPassSG() @@ -149,17 +149,17 @@ func (r *Result) PassSG() []*object.ID { return nil } - m := make([]*object.ID, len(mV2)) + m := make([]*oid.ID, len(mV2)) for i := range mV2 { - m[i] = object.NewIDFromV2(mV2[i]) + m[i] = oid.NewIDFromV2(mV2[i]) } return m } // SetPassSG sets list of Storage Groups that passed audit PoR stage. -func (r *Result) SetPassSG(list []*object.ID) { +func (r *Result) SetPassSG(list []*oid.ID) { mV2 := (*audit.DataAuditResult)(r). GetPassSG() @@ -183,7 +183,7 @@ func (r *Result) SetPassSG(list []*object.ID) { } // FailSG returns list of Storage Groups that failed audit PoR stage. -func (r *Result) FailSG() []*object.ID { +func (r *Result) FailSG() []*oid.ID { mV2 := (*audit.DataAuditResult)(r). GetFailSG() @@ -191,17 +191,17 @@ func (r *Result) FailSG() []*object.ID { return nil } - m := make([]*object.ID, len(mV2)) + m := make([]*oid.ID, len(mV2)) for i := range mV2 { - m[i] = object.NewIDFromV2(mV2[i]) + m[i] = oid.NewIDFromV2(mV2[i]) } return m } // SetFailSG sets list of Storage Groups that failed audit PoR stage. -func (r *Result) SetFailSG(list []*object.ID) { +func (r *Result) SetFailSG(list []*oid.ID) { mV2 := (*audit.DataAuditResult)(r). GetFailSG() diff --git a/audit/result_test.go b/audit/result_test.go index 28db3559..b661167e 100644 --- a/audit/result_test.go +++ b/audit/result_test.go @@ -7,8 +7,8 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/audit" audittest "github.com/nspcc-dev/neofs-sdk-go/audit/test" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" - "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/nspcc-dev/neofs-sdk-go/version" "github.com/stretchr/testify/require" ) @@ -40,11 +40,11 @@ func TestResult(t *testing.T) { r.SetRetries(retries) require.Equal(t, retries, r.Retries()) - passSG := []*object.ID{objecttest.ID(), objecttest.ID()} + passSG := []*oid.ID{test.ID(), test.ID()} r.SetPassSG(passSG) require.Equal(t, passSG, r.PassSG()) - failSG := []*object.ID{objecttest.ID(), objecttest.ID()} + failSG := []*oid.ID{test.ID(), test.ID()} r.SetFailSG(failSG) require.Equal(t, failSG, r.FailSG()) diff --git a/audit/test/generate.go b/audit/test/generate.go index 212d07ac..8ae63b1d 100644 --- a/audit/test/generate.go +++ b/audit/test/generate.go @@ -3,8 +3,8 @@ package audittest import ( "github.com/nspcc-dev/neofs-sdk-go/audit" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" - "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "github.com/nspcc-dev/neofs-sdk-go/object/id/test" versiontest "github.com/nspcc-dev/neofs-sdk-go/version/test" ) @@ -30,8 +30,8 @@ func Result() *audit.Result { []byte("node3"), []byte("node4"), }) - x.SetPassSG([]*object.ID{objecttest.ID(), objecttest.ID()}) - x.SetFailSG([]*object.ID{objecttest.ID(), objecttest.ID()}) + x.SetPassSG([]*oid.ID{test.ID(), test.ID()}) + x.SetFailSG([]*oid.ID{test.ID(), test.ID()}) return x } diff --git a/client/object.go b/client/object.go index 54ed6fa9..ac500962 100644 --- a/client/object.go +++ b/client/object.go @@ -17,6 +17,8 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" + "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" signer "github.com/nspcc-dev/neofs-sdk-go/util/signature" ) @@ -29,17 +31,17 @@ type PutObjectParams struct { // ObjectAddressWriter is an interface of the // component that writes the object address. type ObjectAddressWriter interface { - SetAddress(*object.Address) + SetAddress(*address.Address) } type DeleteObjectParams struct { - addr *object.Address + addr *address.Address tombTgt ObjectAddressWriter } type GetObjectParams struct { - addr *object.Address + addr *address.Address raw bool @@ -49,7 +51,7 @@ type GetObjectParams struct { } type ObjectHeaderParams struct { - addr *object.Address + addr *address.Address raw bool @@ -57,7 +59,7 @@ type ObjectHeaderParams struct { } type RangeDataParams struct { - addr *object.Address + addr *address.Address raw bool @@ -69,7 +71,7 @@ type RangeDataParams struct { type RangeChecksumParams struct { tz bool - addr *object.Address + addr *address.Address rs []*object.Range @@ -186,14 +188,14 @@ func (p *PutObjectParams) PayloadReader() io.Reader { type ObjectPutRes struct { statusRes - id *object.ID + id *oid.ID } -func (x *ObjectPutRes) setID(id *object.ID) { +func (x *ObjectPutRes) setID(id *oid.ID) { x.id = id } -func (x ObjectPutRes) ID() *object.ID { +func (x ObjectPutRes) ID() *oid.ID { return x.id } @@ -317,14 +319,14 @@ func (c *Client) PutObject(ctx context.Context, p *PutObjectParams, opts ...Call } // convert object identifier - id := object.NewIDFromV2(resp.GetBody().GetObjectID()) + id := oid.NewIDFromV2(resp.GetBody().GetObjectID()) res.setID(id) return res, nil } -func (p *DeleteObjectParams) WithAddress(v *object.Address) *DeleteObjectParams { +func (p *DeleteObjectParams) WithAddress(v *address.Address) *DeleteObjectParams { if p != nil { p.addr = v } @@ -332,7 +334,7 @@ func (p *DeleteObjectParams) WithAddress(v *object.Address) *DeleteObjectParams return p } -func (p *DeleteObjectParams) Address() *object.Address { +func (p *DeleteObjectParams) Address() *address.Address { if p != nil { return p.addr } @@ -361,14 +363,14 @@ func (p *DeleteObjectParams) TombstoneAddressTarget() ObjectAddressWriter { type ObjectDeleteRes struct { statusRes - tombAddr *object.Address + tombAddr *address.Address } -func (x ObjectDeleteRes) TombstoneAddress() *object.Address { +func (x ObjectDeleteRes) TombstoneAddress() *address.Address { return x.tombAddr } -func (x *ObjectDeleteRes) setTombstoneAddress(addr *object.Address) { +func (x *ObjectDeleteRes) setTombstoneAddress(addr *address.Address) { x.tombAddr = addr } @@ -444,12 +446,12 @@ func (c *Client) DeleteObject(ctx context.Context, p *DeleteObjectParams, opts . addrv2 := resp.GetBody().GetTombstone() - res.setTombstoneAddress(object.NewAddressFromV2(addrv2)) + res.setTombstoneAddress(address.NewAddressFromV2(addrv2)) return res, nil } -func (p *GetObjectParams) WithAddress(v *object.Address) *GetObjectParams { +func (p *GetObjectParams) WithAddress(v *address.Address) *GetObjectParams { if p != nil { p.addr = v } @@ -457,7 +459,7 @@ func (p *GetObjectParams) WithAddress(v *object.Address) *GetObjectParams { return p } -func (p *GetObjectParams) Address() *object.Address { +func (p *GetObjectParams) Address() *address.Address { if p != nil { return p.addr } @@ -753,7 +755,7 @@ loop: return res, nil } -func (p *ObjectHeaderParams) WithAddress(v *object.Address) *ObjectHeaderParams { +func (p *ObjectHeaderParams) WithAddress(v *address.Address) *ObjectHeaderParams { if p != nil { p.addr = v } @@ -761,7 +763,7 @@ func (p *ObjectHeaderParams) WithAddress(v *object.Address) *ObjectHeaderParams return p } -func (p *ObjectHeaderParams) Address() *object.Address { +func (p *ObjectHeaderParams) Address() *address.Address { if p != nil { return p.addr } @@ -937,7 +939,7 @@ func (c *Client) HeadObject(ctx context.Context, p *ObjectHeaderParams, opts ... return res, nil } -func (p *RangeDataParams) WithAddress(v *object.Address) *RangeDataParams { +func (p *RangeDataParams) WithAddress(v *address.Address) *RangeDataParams { if p != nil { p.addr = v } @@ -945,7 +947,7 @@ func (p *RangeDataParams) WithAddress(v *object.Address) *RangeDataParams { return p } -func (p *RangeDataParams) Address() *object.Address { +func (p *RangeDataParams) Address() *address.Address { if p != nil { return p.addr } @@ -1141,7 +1143,7 @@ func (c *Client) ObjectPayloadRangeData(ctx context.Context, p *RangeDataParams, return res, nil } -func (p *RangeChecksumParams) WithAddress(v *object.Address) *RangeChecksumParams { +func (p *RangeChecksumParams) WithAddress(v *address.Address) *RangeChecksumParams { if p != nil { p.addr = v } @@ -1149,7 +1151,7 @@ func (p *RangeChecksumParams) WithAddress(v *object.Address) *RangeChecksumParam return p } -func (p *RangeChecksumParams) Address() *object.Address { +func (p *RangeChecksumParams) Address() *address.Address { if p != nil { return p.addr } @@ -1329,14 +1331,14 @@ func (p *SearchObjectParams) SearchFilters() object.SearchFilters { type ObjectSearchRes struct { statusRes - ids []*object.ID + ids []*oid.ID } -func (x *ObjectSearchRes) setIDList(v []*object.ID) { +func (x *ObjectSearchRes) setIDList(v []*oid.ID) { x.ids = v } -func (x ObjectSearchRes) IDList() []*object.ID { +func (x ObjectSearchRes) IDList() []*oid.ID { return x.ids } @@ -1394,7 +1396,7 @@ func (c *Client) SearchObjects(ctx context.Context, p *SearchObjectParams, opts } var ( - searchResult []*object.ID + searchResult []*oid.ID resp = new(v2object.SearchResponse) messageWas bool @@ -1437,7 +1439,7 @@ func (c *Client) SearchObjects(ctx context.Context, p *SearchObjectParams, opts chunk := resp.GetBody().GetIDList() for i := range chunk { - searchResult = append(searchResult, object.NewIDFromV2(chunk[i])) + searchResult = append(searchResult, oid.NewIDFromV2(chunk[i])) } } diff --git a/eacl/record.go b/eacl/record.go index 05fd109c..bea69dc6 100644 --- a/eacl/record.go +++ b/eacl/record.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/checksum" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/version" ) @@ -111,7 +112,7 @@ func (r *Record) AddObjectVersionFilter(m Match, v *version.Version) { } // AddObjectIDFilter adds filter by object ID. -func (r *Record) AddObjectIDFilter(m Match, id *object.ID) { +func (r *Record) AddObjectIDFilter(m Match, id *oid.ID) { r.addObjectReservedFilter(m, fKeyObjID, id) } diff --git a/eacl/record_test.go b/eacl/record_test.go index 1a141072..383e3230 100644 --- a/eacl/record_test.go +++ b/eacl/record_test.go @@ -10,7 +10,7 @@ import ( checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test" + "github.com/nspcc-dev/neofs-sdk-go/object/id/test" ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test" versiontest "github.com/nspcc-dev/neofs-sdk-go/version/test" "github.com/stretchr/testify/require" @@ -156,7 +156,7 @@ func TestRecord_ToV2(t *testing.T) { func TestReservedRecords(t *testing.T) { var ( v = versiontest.Version() - oid = objecttest.ID() + oid = test.ID() cid = cidtest.ID() ownerid = ownertest.ID() h = checksumtest.Checksum() diff --git a/object/address.go b/object/address/address.go similarity index 93% rename from object/address.go rename to object/address/address.go index 0cba83bc..b7cb0ad4 100644 --- a/object/address.go +++ b/object/address/address.go @@ -1,4 +1,4 @@ -package object +package address import ( "errors" @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/refs" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Address represents v2-compatible object address. @@ -55,13 +56,13 @@ func (a *Address) SetContainerID(id *cid.ID) { } // ObjectID returns object identifier. -func (a *Address) ObjectID() *ID { - return NewIDFromV2( +func (a *Address) ObjectID() *oid.ID { + return oid.NewIDFromV2( (*refs.Address)(a).GetObjectID()) } // SetObjectID sets object identifier. -func (a *Address) SetObjectID(id *ID) { +func (a *Address) SetObjectID(id *oid.ID) { (*refs.Address)(a).SetObjectID(id.ToV2()) } @@ -69,7 +70,7 @@ func (a *Address) SetObjectID(id *ID) { func (a *Address) Parse(s string) error { var ( err error - oid = NewID() + oid = oid.NewID() id = cid.New() parts = strings.Split(s, addressSeparator) ) diff --git a/object/address_test.go b/object/address/address_test.go similarity index 94% rename from object/address_test.go rename to object/address/address_test.go index 3df0bc9b..76c446e9 100644 --- a/object/address_test.go +++ b/object/address/address_test.go @@ -1,4 +1,4 @@ -package object +package address import ( "strings" @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/refs" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -22,7 +23,7 @@ func TestAddress_SetContainerID(t *testing.T) { func TestAddress_SetObjectID(t *testing.T) { a := NewAddress() - oid := randID(t) + oid := oidtest.ID() a.SetObjectID(oid) @@ -32,8 +33,7 @@ func TestAddress_SetObjectID(t *testing.T) { func TestAddress_Parse(t *testing.T) { cid := cidtest.ID() - oid := NewID() - oid.SetSHA256(randSHA256Checksum(t)) + oid := oidtest.ID() t.Run("should parse successful", func(t *testing.T) { s := strings.Join([]string{cid.String(), oid.String()}, addressSeparator) @@ -62,7 +62,7 @@ func TestAddress_Parse(t *testing.T) { func TestAddressEncoding(t *testing.T) { a := NewAddress() - a.SetObjectID(randID(t)) + a.SetObjectID(oidtest.ID()) a.SetContainerID(cidtest.ID()) t.Run("binary", func(t *testing.T) { diff --git a/object/address/test/generate.go b/object/address/test/generate.go new file mode 100644 index 00000000..bc16f344 --- /dev/null +++ b/object/address/test/generate.go @@ -0,0 +1,17 @@ +package address + +import ( + "github.com/nspcc-dev/neofs-sdk-go/container/id/test" + "github.com/nspcc-dev/neofs-sdk-go/object/address" + "github.com/nspcc-dev/neofs-sdk-go/object/id/test" +) + +// Address returns random object.Address. +func Address() *address.Address { + x := address.NewAddress() + + x.SetContainerID(cidtest.ID()) + x.SetObjectID(test.ID()) + + return x +} diff --git a/object/fmt.go b/object/fmt.go index 3eb5d5f0..8229c198 100644 --- a/object/fmt.go +++ b/object/fmt.go @@ -8,6 +8,7 @@ import ( signatureV2 "github.com/nspcc-dev/neofs-api-go/v2/signature" "github.com/nspcc-dev/neofs-sdk-go/checksum" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/signature" sigutil "github.com/nspcc-dev/neofs-sdk-go/util/signature" ) @@ -45,13 +46,13 @@ func VerifyPayloadChecksum(obj *Object) error { } // CalculateID calculates identifier for the object. -func CalculateID(obj *Object) (*ID, error) { +func CalculateID(obj *Object) (*oid.ID, error) { data, err := obj.ToV2().GetHeader().StableMarshal(nil) if err != nil { return nil, err } - id := NewID() + id := oid.NewID() id.SetSHA256(sha256.Sum256(data)) return id, nil @@ -85,7 +86,7 @@ func VerifyID(obj *Object) error { return nil } -func CalculateIDSignature(key *ecdsa.PrivateKey, id *ID) (*signature.Signature, error) { +func CalculateIDSignature(key *ecdsa.PrivateKey, id *oid.ID) (*signature.Signature, error) { sig := signature.New() if err := sigutil.SignDataWithHandler( diff --git a/object/id.go b/object/id/id.go similarity index 99% rename from object/id.go rename to object/id/id.go index f5ecdb85..4c3d0e47 100644 --- a/object/id.go +++ b/object/id/id.go @@ -1,4 +1,4 @@ -package object +package oid import ( "bytes" diff --git a/object/id_test.go b/object/id/id_test.go similarity index 91% rename from object/id_test.go rename to object/id/id_test.go index e4086d82..336ba734 100644 --- a/object/id_test.go +++ b/object/id/id_test.go @@ -1,4 +1,4 @@ -package object +package oid import ( "crypto/rand" @@ -11,6 +11,20 @@ import ( "github.com/stretchr/testify/require" ) +func randID(t *testing.T) *ID { + id := NewID() + id.SetSHA256(randSHA256Checksum(t)) + + return id +} + +func randSHA256Checksum(t *testing.T) (cs [sha256.Size]byte) { + _, err := rand.Read(cs[:]) + require.NoError(t, err) + + return +} + func TestIDV2(t *testing.T) { id := NewID() diff --git a/object/id/test/generate.go b/object/id/test/generate.go new file mode 100644 index 00000000..7bd5bbe4 --- /dev/null +++ b/object/id/test/generate.go @@ -0,0 +1,26 @@ +package test + +import ( + "crypto/sha256" + "math/rand" + + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" +) + +// ID returns random object.ID. +func ID() *oid.ID { + checksum := [sha256.Size]byte{} + + rand.Read(checksum[:]) + + return idWithChecksum(checksum) +} + +// idWithChecksum returns object.ID initialized +// with specified checksum. +func idWithChecksum(cs [sha256.Size]byte) *oid.ID { + id := oid.NewID() + id.SetSHA256(cs) + + return id +} diff --git a/object/raw.go b/object/raw.go index 0bf79170..0d9e7ce3 100644 --- a/object/raw.go +++ b/object/raw.go @@ -4,6 +4,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-sdk-go/checksum" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/signature" @@ -48,7 +49,7 @@ func (o *RawObject) Object() *Object { } // SetID sets object identifier. -func (o *RawObject) SetID(v *ID) { +func (o *RawObject) SetID(v *oid.ID) { o.setID(v) } @@ -103,12 +104,12 @@ func (o *RawObject) SetAttributes(v ...*Attribute) { } // SetPreviousID sets identifier of the previous sibling object. -func (o *RawObject) SetPreviousID(v *ID) { +func (o *RawObject) SetPreviousID(v *oid.ID) { o.setPreviousID(v) } // SetChildren sets list of the identifiers of the child objects. -func (o *RawObject) SetChildren(v ...*ID) { +func (o *RawObject) SetChildren(v ...*oid.ID) { o.setChildren(v...) } @@ -118,7 +119,7 @@ func (o *RawObject) SetSplitID(id *SplitID) { } // SetParentID sets identifier of the parent object. -func (o *RawObject) SetParentID(v *ID) { +func (o *RawObject) SetParentID(v *oid.ID) { o.setParentID(v) } diff --git a/object/raw_test.go b/object/raw_test.go index e03fa30b..be254718 100644 --- a/object/raw_test.go +++ b/object/raw_test.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-sdk-go/checksum" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test" sessiontest "github.com/nspcc-dev/neofs-sdk-go/session/test" "github.com/nspcc-dev/neofs-sdk-go/signature" @@ -15,8 +16,8 @@ import ( "github.com/stretchr/testify/require" ) -func randID(t *testing.T) *ID { - id := NewID() +func randID(t *testing.T) *oid.ID { + id := oid.NewID() id.SetSHA256(randSHA256Checksum(t)) return id @@ -121,7 +122,6 @@ func TestRawObject_SetCreationEpoch(t *testing.T) { func TestRawObject_SetPayloadChecksum(t *testing.T) { obj := NewRaw() - cs := checksum.New() cs.SetSHA256(randSHA256Checksum(t)) @@ -175,7 +175,7 @@ func TestRawObject_SetChildren(t *testing.T) { obj.SetChildren(id1, id2) - require.Equal(t, []*ID{id1, id2}, obj.Children()) + require.Equal(t, []*oid.ID{id1, id2}, obj.Children()) } func TestRawObject_SetSplitID(t *testing.T) { diff --git a/object/rw.go b/object/rw.go index 014e22e2..39e24575 100644 --- a/object/rw.go +++ b/object/rw.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-sdk-go/checksum" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/signature" @@ -45,14 +46,14 @@ func (o *rwObject) setSplitFields(setter func(*object.SplitHeader)) { } // ID returns object identifier. -func (o *rwObject) ID() *ID { - return NewIDFromV2( +func (o *rwObject) ID() *oid.ID { + return oid.NewIDFromV2( (*object.Object)(o). GetObjectID(), ) } -func (o *rwObject) setID(v *ID) { +func (o *rwObject) setID(v *oid.ID) { (*object.Object)(o). SetObjectID(v.ToV2()) } @@ -205,8 +206,8 @@ func (o *rwObject) setAttributes(v ...*Attribute) { } // PreviousID returns identifier of the previous sibling object. -func (o *rwObject) PreviousID() *ID { - return NewIDFromV2( +func (o *rwObject) PreviousID() *oid.ID { + return oid.NewIDFromV2( (*object.Object)(o). GetHeader(). GetSplit(). @@ -214,29 +215,29 @@ func (o *rwObject) PreviousID() *ID { ) } -func (o *rwObject) setPreviousID(v *ID) { +func (o *rwObject) setPreviousID(v *oid.ID) { o.setSplitFields(func(split *object.SplitHeader) { split.SetPrevious(v.ToV2()) }) } // Children return list of the identifiers of the child objects. -func (o *rwObject) Children() []*ID { +func (o *rwObject) Children() []*oid.ID { ids := (*object.Object)(o). GetHeader(). GetSplit(). GetChildren() - res := make([]*ID, 0, len(ids)) + res := make([]*oid.ID, 0, len(ids)) for i := range ids { - res = append(res, NewIDFromV2(ids[i])) + res = append(res, oid.NewIDFromV2(ids[i])) } return res } -func (o *rwObject) setChildren(v ...*ID) { +func (o *rwObject) setChildren(v ...*oid.ID) { ids := make([]*refs.ObjectID, 0, len(v)) for i := range v { @@ -266,8 +267,8 @@ func (o *rwObject) setSplitID(id *SplitID) { } // ParentID returns identifier of the parent object. -func (o *rwObject) ParentID() *ID { - return NewIDFromV2( +func (o *rwObject) ParentID() *oid.ID { + return oid.NewIDFromV2( (*object.Object)(o). GetHeader(). GetSplit(). @@ -275,7 +276,7 @@ func (o *rwObject) ParentID() *ID { ) } -func (o *rwObject) setParentID(v *ID) { +func (o *rwObject) setParentID(v *oid.ID) { o.setSplitFields(func(split *object.SplitHeader) { split.SetParent(v.ToV2()) }) diff --git a/object/search.go b/object/search.go index 3c6dd918..9dc40002 100644 --- a/object/search.go +++ b/object/search.go @@ -6,6 +6,7 @@ import ( v2object "github.com/nspcc-dev/neofs-api-go/v2/object" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/version" ) @@ -262,12 +263,12 @@ func (f *SearchFilters) AddPhyFilter() { } // AddParentIDFilter adds filter by parent identifier. -func (f *SearchFilters) AddParentIDFilter(m SearchMatchType, id *ID) { +func (f *SearchFilters) AddParentIDFilter(m SearchMatchType, id *oid.ID) { f.addReservedFilter(m, fKeyParent, id) } // AddObjectIDFilter adds filter by object identifier. -func (f *SearchFilters) AddObjectIDFilter(m SearchMatchType, id *ID) { +func (f *SearchFilters) AddObjectIDFilter(m SearchMatchType, id *oid.ID) { f.addReservedFilter(m, fKeyObjectID, id) } diff --git a/object/search_test.go b/object/search_test.go index a9ec0cf4..debaff79 100644 --- a/object/search_test.go +++ b/object/search_test.go @@ -7,6 +7,7 @@ import ( v2object "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-sdk-go/object" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) @@ -99,12 +100,12 @@ func TestSearchFilters_AddPhyFilter(t *testing.T) { require.Equal(t, "", f.Value()) } -func testOID() *object.ID { +func testOID() *oid.ID { cs := [sha256.Size]byte{} rand.Read(cs[:]) - id := object.NewID() + id := oid.NewID() id.SetSHA256(cs) return id diff --git a/object/splitinfo.go b/object/splitinfo.go index 3dfc2212..28040119 100644 --- a/object/splitinfo.go +++ b/object/splitinfo.go @@ -2,6 +2,7 @@ package object import ( "github.com/nspcc-dev/neofs-api-go/v2/object" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type SplitInfo object.SplitInfo @@ -39,21 +40,21 @@ func (s *SplitInfo) SetSplitID(v *SplitID) { (*object.SplitInfo)(s).SetSplitID(v.ToV2()) } -func (s *SplitInfo) LastPart() *ID { - return NewIDFromV2( +func (s *SplitInfo) LastPart() *oid.ID { + return oid.NewIDFromV2( (*object.SplitInfo)(s).GetLastPart()) } -func (s *SplitInfo) SetLastPart(v *ID) { +func (s *SplitInfo) SetLastPart(v *oid.ID) { (*object.SplitInfo)(s).SetLastPart(v.ToV2()) } -func (s *SplitInfo) Link() *ID { - return NewIDFromV2( +func (s *SplitInfo) Link() *oid.ID { + return oid.NewIDFromV2( (*object.SplitInfo)(s).GetLink()) } -func (s *SplitInfo) SetLink(v *ID) { +func (s *SplitInfo) SetLink(v *oid.ID) { (*object.SplitInfo)(s).SetLink(v.ToV2()) } diff --git a/object/splitinfo_test.go b/object/splitinfo_test.go index 2754f2a1..5f996419 100644 --- a/object/splitinfo_test.go +++ b/object/splitinfo_test.go @@ -6,6 +6,7 @@ import ( objv2 "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-sdk-go/object" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) @@ -43,11 +44,11 @@ func TestSplitInfo(t *testing.T) { }) } -func generateID() *object.ID { +func generateID() *oid.ID { var buf [32]byte _, _ = rand.Read(buf[:]) - id := object.NewID() + id := oid.NewID() id.SetSHA256(buf) return id diff --git a/object/test/generate.go b/object/test/generate.go index 5e09a06c..11a89252 100644 --- a/object/test/generate.go +++ b/object/test/generate.go @@ -1,47 +1,18 @@ package objecttest import ( - "crypto/sha256" - "math/rand" - "github.com/google/uuid" checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "github.com/nspcc-dev/neofs-sdk-go/object/id/test" ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test" sessiontest "github.com/nspcc-dev/neofs-sdk-go/session/test" sigtest "github.com/nspcc-dev/neofs-sdk-go/signature/test" "github.com/nspcc-dev/neofs-sdk-go/version" ) -// ID returns random object.ID. -func ID() *object.ID { - checksum := [sha256.Size]byte{} - - rand.Read(checksum[:]) - - return IDWithChecksum(checksum) -} - -// IDWithChecksum returns object.ID initialized -// with specified checksum. -func IDWithChecksum(cs [sha256.Size]byte) *object.ID { - id := object.NewID() - id.SetSHA256(cs) - - return id -} - -// Address returns random object.Address. -func Address() *object.Address { - x := object.NewAddress() - - x.SetContainerID(cidtest.ID()) - x.SetObjectID(ID()) - - return x -} - // Range returns random object.Range. func Range() *object.Range { x := object.NewRange() @@ -74,7 +45,7 @@ func SplitID() *object.SplitID { func generateRaw(withParent bool) *object.RawObject { x := object.NewRaw() - x.SetID(ID()) + x.SetID(test.ID()) x.SetSessionToken(sessiontest.Token()) x.SetPayload([]byte{1, 2, 3}) x.SetOwnerID(ownertest.ID()) @@ -83,9 +54,9 @@ func generateRaw(withParent bool) *object.RawObject { x.SetVersion(version.Current()) x.SetPayloadSize(111) x.SetCreationEpoch(222) - x.SetPreviousID(ID()) - x.SetParentID(ID()) - x.SetChildren(ID(), ID()) + x.SetPreviousID(test.ID()) + x.SetParentID(test.ID()) + x.SetChildren(test.ID(), test.ID()) x.SetAttributes(Attribute(), Attribute()) x.SetSplitID(SplitID()) x.SetPayloadChecksum(checksumtest.Checksum()) @@ -115,7 +86,7 @@ func Tombstone() *object.Tombstone { x.SetSplitID(SplitID()) x.SetExpirationEpoch(13) - x.SetMembers([]*object.ID{ID(), ID()}) + x.SetMembers([]*oid.ID{test.ID(), test.ID()}) return x } @@ -125,8 +96,8 @@ func SplitInfo() *object.SplitInfo { x := object.NewSplitInfo() x.SetSplitID(SplitID()) - x.SetLink(ID()) - x.SetLastPart(ID()) + x.SetLink(test.ID()) + x.SetLastPart(test.ID()) return x } @@ -135,7 +106,7 @@ func SplitInfo() *object.SplitInfo { func SearchFilters() object.SearchFilters { x := object.NewSearchFilters() - x.AddObjectIDFilter(object.MatchStringEqual, ID()) + x.AddObjectIDFilter(object.MatchStringEqual, test.ID()) x.AddObjectContainerIDFilter(object.MatchStringNotEqual, cidtest.ID()) return x diff --git a/object/tombstone.go b/object/tombstone.go index 766b4a83..43fa62ed 100644 --- a/object/tombstone.go +++ b/object/tombstone.go @@ -3,6 +3,7 @@ package object import ( "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/tombstone" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Tombstone represents v2-compatible tombstone structure. @@ -54,7 +55,7 @@ func (t *Tombstone) SetSplitID(v *SplitID) { } // Members returns list of objects to be deleted. -func (t *Tombstone) Members() []*ID { +func (t *Tombstone) Members() []*oid.ID { msV2 := (*tombstone.Tombstone)(t). GetMembers() @@ -62,17 +63,17 @@ func (t *Tombstone) Members() []*ID { return nil } - ms := make([]*ID, 0, len(msV2)) + ms := make([]*oid.ID, 0, len(msV2)) for i := range msV2 { - ms = append(ms, NewIDFromV2(msV2[i])) + ms = append(ms, oid.NewIDFromV2(msV2[i])) } return ms } // SetMembers sets list of objects to be deleted. -func (t *Tombstone) SetMembers(v []*ID) { +func (t *Tombstone) SetMembers(v []*oid.ID) { var ms []*refs.ObjectID if v != nil { diff --git a/object/tombstone_test.go b/object/tombstone_test.go index c074fe01..48adf7f5 100644 --- a/object/tombstone_test.go +++ b/object/tombstone_test.go @@ -6,15 +6,16 @@ import ( "testing" "github.com/nspcc-dev/neofs-api-go/v2/tombstone" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) -func generateIDList(sz int) []*ID { - res := make([]*ID, sz) +func generateIDList(sz int) []*oid.ID { + res := make([]*oid.ID, sz) cs := [sha256.Size]byte{} for i := 0; i < sz; i++ { - res[i] = NewID() + res[i] = oid.NewID() rand.Read(cs[:]) res[i].SetSHA256(cs) } diff --git a/pool/pool.go b/pool/pool.go index b0af1d48..3d213f77 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -22,6 +22,7 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/eacl" "github.com/nspcc-dev/neofs-sdk-go/object" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/token" @@ -157,14 +158,14 @@ type Pool interface { } type Object interface { - PutObject(ctx context.Context, params *client.PutObjectParams, opts ...CallOption) (*object.ID, error) + PutObject(ctx context.Context, params *client.PutObjectParams, opts ...CallOption) (*oid.ID, error) DeleteObject(ctx context.Context, params *client.DeleteObjectParams, opts ...CallOption) error GetObject(ctx context.Context, params *client.GetObjectParams, opts ...CallOption) (*object.Object, error) GetObjectHeader(ctx context.Context, params *client.ObjectHeaderParams, opts ...CallOption) (*object.Object, error) ObjectPayloadRangeData(ctx context.Context, params *client.RangeDataParams, opts ...CallOption) ([]byte, error) ObjectPayloadRangeSHA256(ctx context.Context, params *client.RangeChecksumParams, opts ...CallOption) ([][32]byte, error) ObjectPayloadRangeTZ(ctx context.Context, params *client.RangeChecksumParams, opts ...CallOption) ([][64]byte, error) - SearchObject(ctx context.Context, params *client.SearchObjectParams, opts ...CallOption) ([]*object.ID, error) + SearchObject(ctx context.Context, params *client.SearchObjectParams, opts ...CallOption) ([]*oid.ID, error) } type Container interface { @@ -540,7 +541,7 @@ func (p *pool) checkSessionTokenErr(err error, address string) bool { return false } -func (p *pool) PutObject(ctx context.Context, params *client.PutObjectParams, opts ...CallOption) (*object.ID, error) { +func (p *pool) PutObject(ctx context.Context, params *client.PutObjectParams, opts ...CallOption) (*oid.ID, error) { cfg := cfgFromOpts(append(opts, useDefaultSession())...) cp, options, err := p.conn(ctx, cfg) if err != nil { @@ -729,7 +730,7 @@ func (p *pool) ObjectPayloadRangeTZ(ctx context.Context, params *client.RangeChe return hs, nil } -func (p *pool) SearchObject(ctx context.Context, params *client.SearchObjectParams, opts ...CallOption) ([]*object.ID, error) { +func (p *pool) SearchObject(ctx context.Context, params *client.SearchObjectParams, opts ...CallOption) ([]*oid.ID, error) { cfg := cfgFromOpts(append(opts, useDefaultSession())...) cp, options, err := p.conn(ctx, cfg) if err != nil { diff --git a/storagegroup/storagegroup.go b/storagegroup/storagegroup.go index c5ddb633..8ceb5b5c 100644 --- a/storagegroup/storagegroup.go +++ b/storagegroup/storagegroup.go @@ -4,7 +4,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/storagegroup" "github.com/nspcc-dev/neofs-sdk-go/checksum" - "github.com/nspcc-dev/neofs-sdk-go/object" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // StorageGroup represents v2-compatible storage group. @@ -67,17 +67,17 @@ func (sg *StorageGroup) SetExpirationEpoch(epoch uint64) { // Members returns strictly ordered list of // storage group member objects. -func (sg *StorageGroup) Members() []*object.ID { +func (sg *StorageGroup) Members() []*oid.ID { mV2 := (*storagegroup.StorageGroup)(sg).GetMembers() if mV2 == nil { return nil } - m := make([]*object.ID, len(mV2)) + m := make([]*oid.ID, len(mV2)) for i := range mV2 { - m[i] = object.NewIDFromV2(mV2[i]) + m[i] = oid.NewIDFromV2(mV2[i]) } return m @@ -85,7 +85,7 @@ func (sg *StorageGroup) Members() []*object.ID { // SetMembers sets strictly ordered list of // storage group member objects. -func (sg *StorageGroup) SetMembers(members []*object.ID) { +func (sg *StorageGroup) SetMembers(members []*oid.ID) { mV2 := (*storagegroup.StorageGroup)(sg).GetMembers() if members == nil { diff --git a/storagegroup/storagegroup_test.go b/storagegroup/storagegroup_test.go index 5121a979..cd3acff6 100644 --- a/storagegroup/storagegroup_test.go +++ b/storagegroup/storagegroup_test.go @@ -5,8 +5,8 @@ import ( storagegroupV2 "github.com/nspcc-dev/neofs-api-go/v2/storagegroup" checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test" - "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/nspcc-dev/neofs-sdk-go/storagegroup" storagegrouptest "github.com/nspcc-dev/neofs-sdk-go/storagegroup/test" "github.com/stretchr/testify/require" @@ -27,7 +27,7 @@ func TestStorageGroup(t *testing.T) { sg.SetExpirationEpoch(exp) require.Equal(t, exp, sg.ExpirationEpoch()) - members := []*object.ID{objecttest.ID(), objecttest.ID()} + members := []*oid.ID{test.ID(), test.ID()} sg.SetMembers(members) require.Equal(t, members, sg.Members()) } diff --git a/storagegroup/test/generate.go b/storagegroup/test/generate.go index 13f5e88b..181dc8c2 100644 --- a/storagegroup/test/generate.go +++ b/storagegroup/test/generate.go @@ -2,8 +2,8 @@ package storagegrouptest import ( checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test" - "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/nspcc-dev/neofs-sdk-go/storagegroup" ) @@ -14,7 +14,7 @@ func StorageGroup() *storagegroup.StorageGroup { x.SetExpirationEpoch(66) x.SetValidationDataSize(322) x.SetValidationDataHash(checksumtest.Checksum()) - x.SetMembers([]*object.ID{objecttest.ID(), objecttest.ID()}) + x.SetMembers([]*oid.ID{test.ID(), test.ID()}) return x }