diff --git a/Makefile b/Makefile index 19b3138..7ed6954 100755 --- a/Makefile +++ b/Makefile @@ -61,12 +61,13 @@ protoc: make protoc-install; \ fi # Protoc generate - @for f in `find . -type f -name '*.proto' -not -path './bin/*'`; do \ + @for f in `find . -type f -name '*.proto' -not -path './bin/*' -not -path './util/proto/test/*'`; do \ echo "⇒ Processing $$f "; \ $(PROTOC_DIR)/bin/protoc \ --proto_path=.:$(PROTOC_DIR)/include:/usr/local/include \ - --plugin=protoc-gen-go=$(PROTOC_GEN_GO_DIR)/protoc-gen-go \ - --go_out=. --go_opt=paths=source_relative \ + --plugin=protoc-gen-go-frostfs=$(abspath ./bin/protogen) \ + --go-frostfs_out=fuzz=true:. \ + --go-frostfs_opt=paths=source_relative \ --go-grpc_opt=require_unimplemented_servers=false \ --go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \ done @@ -79,7 +80,9 @@ protogen: protoc-test: protoc protogen @$(PROTOC_DIR)/bin/protoc \ --plugin=protoc-gen-go-frostfs=$(abspath $(BIN)/protogen) \ - --go-frostfs_out=. --go-frostfs_opt=paths=source_relative \ + --go-frostfs_opt=Mutil/proto/test/test.proto=git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/test/custom \ + --go-frostfs_opt=module=git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 \ + --go-frostfs_out=. --go-frostfs_opt=paths=import \ ./util/proto/test/test.proto # Run Unit Test with go test diff --git a/accounting/grpc/service.go b/accounting/grpc/service.go deleted file mode 100644 index fa292bf..0000000 --- a/accounting/grpc/service.go +++ /dev/null @@ -1,46 +0,0 @@ -package accounting - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -// SetOwnerId sets identifier of the account owner. -func (m *BalanceRequest_Body) SetOwnerId(v *refs.OwnerID) { - m.OwnerId = v -} - -// SetBody sets body of the request. -func (m *BalanceRequest) SetBody(v *BalanceRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *BalanceRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *BalanceRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetBalance sets balance value of the response. -func (m *BalanceResponse_Body) SetBalance(v *Decimal) { - m.Balance = v -} - -// SetBody sets body of the response. -func (m *BalanceResponse) SetBody(v *BalanceResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *BalanceResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *BalanceResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} diff --git a/accounting/grpc/service.pb.go b/accounting/grpc/service.pb.go deleted file mode 100644 index b66bb7a..0000000 Binary files a/accounting/grpc/service.pb.go and /dev/null differ diff --git a/accounting/grpc/service_frostfs.pb.go b/accounting/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..e44d7d4 Binary files /dev/null and b/accounting/grpc/service_frostfs.pb.go differ diff --git a/accounting/grpc/service_frostfs_fuzz.go b/accounting/grpc/service_frostfs_fuzz.go new file mode 100644 index 0000000..69e7174 --- /dev/null +++ b/accounting/grpc/service_frostfs_fuzz.go @@ -0,0 +1,45 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package accounting + +func DoFuzzProtoBalanceRequest(data []byte) int { + msg := new(BalanceRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONBalanceRequest(data []byte) int { + msg := new(BalanceRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoBalanceResponse(data []byte) int { + msg := new(BalanceResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONBalanceResponse(data []byte) int { + msg := new(BalanceResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/accounting/grpc/service_frostfs_test.go b/accounting/grpc/service_frostfs_test.go new file mode 100644 index 0000000..b97a13e --- /dev/null +++ b/accounting/grpc/service_frostfs_test.go @@ -0,0 +1,31 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package accounting + +import ( + testing "testing" +) + +func FuzzProtoBalanceRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoBalanceRequest(data) + }) +} +func FuzzJSONBalanceRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONBalanceRequest(data) + }) +} +func FuzzProtoBalanceResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoBalanceResponse(data) + }) +} +func FuzzJSONBalanceResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONBalanceResponse(data) + }) +} diff --git a/accounting/grpc/types.go b/accounting/grpc/types.go deleted file mode 100644 index 1c1bac9..0000000 --- a/accounting/grpc/types.go +++ /dev/null @@ -1,11 +0,0 @@ -package accounting - -// SetValue sets value of the decimal number. -func (m *Decimal) SetValue(v int64) { - m.Value = v -} - -// SetPrecision sets precision of the decimal number. -func (m *Decimal) SetPrecision(v uint32) { - m.Precision = v -} diff --git a/accounting/grpc/types.pb.go b/accounting/grpc/types.pb.go deleted file mode 100644 index 8be14bc..0000000 Binary files a/accounting/grpc/types.pb.go and /dev/null differ diff --git a/accounting/grpc/types_frostfs.pb.go b/accounting/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..182705e Binary files /dev/null and b/accounting/grpc/types_frostfs.pb.go differ diff --git a/accounting/grpc/types_frostfs_fuzz.go b/accounting/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..5eb5e97 --- /dev/null +++ b/accounting/grpc/types_frostfs_fuzz.go @@ -0,0 +1,26 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package accounting + +func DoFuzzProtoDecimal(data []byte) int { + msg := new(Decimal) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONDecimal(data []byte) int { + msg := new(Decimal) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/accounting/grpc/types_frostfs_test.go b/accounting/grpc/types_frostfs_test.go new file mode 100644 index 0000000..404b75e --- /dev/null +++ b/accounting/grpc/types_frostfs_test.go @@ -0,0 +1,21 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package accounting + +import ( + testing "testing" +) + +func FuzzProtoDecimal(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoDecimal(data) + }) +} +func FuzzJSONDecimal(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONDecimal(data) + }) +} diff --git a/acl/convert.go b/acl/convert.go index 0cf455c..c5768ad 100644 --- a/acl/convert.go +++ b/acl/convert.go @@ -478,7 +478,7 @@ func (bt *BearerTokenBody) ToGRPCMessage() grpc.Message { m.SetLifetime(bt.lifetime.ToGRPCMessage().(*acl.BearerToken_Body_TokenLifetime)) m.SetEaclTable(bt.eacl.ToGRPCMessage().(*acl.EACLTable)) m.SetAllowImpersonate(bt.impersonate) - m.SetAPEOverride(bt.apeOverride.ToGRPCMessage().(*acl.BearerToken_Body_APEOverride)) + m.SetApeOverride(bt.apeOverride.ToGRPCMessage().(*acl.BearerToken_Body_APEOverride)) } return m diff --git a/acl/grpc/types.go b/acl/grpc/types.go deleted file mode 100644 index fbcbb91..0000000 --- a/acl/grpc/types.go +++ /dev/null @@ -1,193 +0,0 @@ -package acl - -import ( - ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc" - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" -) - -// SetVersion sets version of EACL rules in table. -func (m *EACLTable) SetVersion(v *refs.Version) { - m.Version = v -} - -// SetContainerId sets container identifier of the eACL table. -func (m *EACLTable) SetContainerId(v *refs.ContainerID) { - m.ContainerId = v -} - -// SetRecords sets record list of the eACL table. -func (m *EACLTable) SetRecords(v []*EACLRecord) { - m.Records = v -} - -// SetOperation sets operation of the eACL record. -func (m *EACLRecord) SetOperation(v Operation) { - m.Operation = v -} - -// SetAction sets action of the eACL record. -func (m *EACLRecord) SetAction(v Action) { - m.Action = v -} - -// SetFilters sets filter list of the eACL record. -func (m *EACLRecord) SetFilters(v []*EACLRecord_Filter) { - m.Filters = v -} - -// SetTargets sets target list of the eACL record. -func (m *EACLRecord) SetTargets(v []*EACLRecord_Target) { - m.Targets = v -} - -// SetHeaderType sets header type of the eACL filter. -func (m *EACLRecord_Filter) SetHeaderType(v HeaderType) { - m.HeaderType = v -} - -// SetMatchType sets match type of the eACL filter. -func (m *EACLRecord_Filter) SetMatchType(v MatchType) { - m.MatchType = v -} - -// SetKey sets key of the eACL filter. -func (m *EACLRecord_Filter) SetKey(v string) { - m.Key = v -} - -// SetValue sets value of the eACL filter. -func (m *EACLRecord_Filter) SetValue(v string) { - m.Value = v -} - -// SetRole sets target group of the eACL target. -func (m *EACLRecord_Target) SetRole(v Role) { - m.Role = v -} - -// SetKeys of the eACL target. -func (m *EACLRecord_Target) SetKeys(v [][]byte) { - m.Keys = v -} - -// SetEaclTable sets eACL table of the bearer token. -func (m *BearerToken_Body) SetEaclTable(v *EACLTable) { - m.EaclTable = v -} - -func (m *BearerToken_Body) SetAPEOverride(v *BearerToken_Body_APEOverride) { - m.ApeOverride = v -} - -func (m *BearerToken_Body_APEOverride) SetChains(v []*ape.Chain) { - m.Chains = v -} - -func (m *BearerToken_Body_APEOverride) SetTarget(v *ape.ChainTarget) { - m.Target = v -} - -// SetOwnerId sets identifier of the bearer token owner. -func (m *BearerToken_Body) SetOwnerId(v *refs.OwnerID) { - m.OwnerId = v -} - -// SetLifetime sets lifetime of the bearer token. -func (m *BearerToken_Body) SetLifetime(v *BearerToken_Body_TokenLifetime) { - m.Lifetime = v -} - -// SetAllowImpersonate allows impersonate. -func (m *BearerToken_Body) SetAllowImpersonate(v bool) { - m.AllowImpersonate = v -} - -// SetBody sets bearer token body. -func (m *BearerToken) SetBody(v *BearerToken_Body) { - m.Body = v -} - -// SetSignature sets bearer token signature. -func (m *BearerToken) SetSignature(v *refs.Signature) { - m.Signature = v -} - -// SetExp sets epoch number of the token expiration. -func (m *BearerToken_Body_TokenLifetime) SetExp(v uint64) { - m.Exp = v -} - -// SetNbf sets starting epoch number of the token. -func (m *BearerToken_Body_TokenLifetime) SetNbf(v uint64) { - m.Nbf = v -} - -// SetIat sets the number of the epoch in which the token was issued. -func (m *BearerToken_Body_TokenLifetime) SetIat(v uint64) { - m.Iat = v -} - -// FromString parses Action from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Action) FromString(s string) bool { - i, ok := Action_value[s] - if ok { - *x = Action(i) - } - - return ok -} - -// FromString parses Role from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Role) FromString(s string) bool { - i, ok := Role_value[s] - if ok { - *x = Role(i) - } - - return ok -} - -// FromString parses Operation from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Operation) FromString(s string) bool { - i, ok := Operation_value[s] - if ok { - *x = Operation(i) - } - - return ok -} - -// FromString parses MatchType from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *MatchType) FromString(s string) bool { - i, ok := MatchType_value[s] - if ok { - *x = MatchType(i) - } - - return ok -} - -// FromString parses HeaderType from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *HeaderType) FromString(s string) bool { - i, ok := HeaderType_value[s] - if ok { - *x = HeaderType(i) - } - - return ok -} diff --git a/acl/grpc/types.pb.go b/acl/grpc/types.pb.go deleted file mode 100644 index 39ab1e1..0000000 Binary files a/acl/grpc/types.pb.go and /dev/null differ diff --git a/acl/grpc/types_frostfs.pb.go b/acl/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..e542a19 Binary files /dev/null and b/acl/grpc/types_frostfs.pb.go differ diff --git a/acl/grpc/types_frostfs_fuzz.go b/acl/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..5d5b763 --- /dev/null +++ b/acl/grpc/types_frostfs_fuzz.go @@ -0,0 +1,64 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package acl + +func DoFuzzProtoEACLRecord(data []byte) int { + msg := new(EACLRecord) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONEACLRecord(data []byte) int { + msg := new(EACLRecord) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoEACLTable(data []byte) int { + msg := new(EACLTable) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONEACLTable(data []byte) int { + msg := new(EACLTable) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoBearerToken(data []byte) int { + msg := new(BearerToken) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONBearerToken(data []byte) int { + msg := new(BearerToken) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/acl/grpc/types_frostfs_test.go b/acl/grpc/types_frostfs_test.go new file mode 100644 index 0000000..c6d1c43 --- /dev/null +++ b/acl/grpc/types_frostfs_test.go @@ -0,0 +1,41 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package acl + +import ( + testing "testing" +) + +func FuzzProtoEACLRecord(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoEACLRecord(data) + }) +} +func FuzzJSONEACLRecord(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONEACLRecord(data) + }) +} +func FuzzProtoEACLTable(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoEACLTable(data) + }) +} +func FuzzJSONEACLTable(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONEACLTable(data) + }) +} +func FuzzProtoBearerToken(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoBearerToken(data) + }) +} +func FuzzJSONBearerToken(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONBearerToken(data) + }) +} diff --git a/ape/grpc/types.go b/ape/grpc/types.go deleted file mode 100644 index 931b6a3..0000000 --- a/ape/grpc/types.go +++ /dev/null @@ -1,21 +0,0 @@ -package ape - -func (t *ChainTarget) SetType(typ TargetType) { - t.Type = typ -} - -func (t *ChainTarget) SetName(name string) { - t.Name = name -} - -func (c *Chain) SetKind(kind isChain_Kind) { - c.Kind = kind -} - -func (cr *Chain_Raw) SetRaw(raw []byte) { - cr.Raw = raw -} - -func (cr *Chain_Raw) GetRaw() []byte { - return cr.Raw -} diff --git a/ape/grpc/types.pb.go b/ape/grpc/types.pb.go deleted file mode 100644 index ee8e0a7..0000000 Binary files a/ape/grpc/types.pb.go and /dev/null differ diff --git a/ape/grpc/types_frostfs.pb.go b/ape/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..1e92f22 Binary files /dev/null and b/ape/grpc/types_frostfs.pb.go differ diff --git a/ape/grpc/types_frostfs_fuzz.go b/ape/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..b7bf367 --- /dev/null +++ b/ape/grpc/types_frostfs_fuzz.go @@ -0,0 +1,45 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package ape + +func DoFuzzProtoChainTarget(data []byte) int { + msg := new(ChainTarget) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONChainTarget(data []byte) int { + msg := new(ChainTarget) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoChain(data []byte) int { + msg := new(Chain) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONChain(data []byte) int { + msg := new(Chain) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/ape/grpc/types_frostfs_test.go b/ape/grpc/types_frostfs_test.go new file mode 100644 index 0000000..93d7eea --- /dev/null +++ b/ape/grpc/types_frostfs_test.go @@ -0,0 +1,31 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package ape + +import ( + testing "testing" +) + +func FuzzProtoChainTarget(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoChainTarget(data) + }) +} +func FuzzJSONChainTarget(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONChainTarget(data) + }) +} +func FuzzProtoChain(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoChain(data) + }) +} +func FuzzJSONChain(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONChain(data) + }) +} diff --git a/apemanager/grpc/service.go b/apemanager/grpc/service.go deleted file mode 100644 index bd77db0..0000000 --- a/apemanager/grpc/service.go +++ /dev/null @@ -1,106 +0,0 @@ -package apemanager - -import ( - ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -func (rb *AddChainRequest_Body) SetTarget(t *ape.ChainTarget) { - rb.Target = t -} - -func (rb *AddChainRequest_Body) SetChain(chain *ape.Chain) { - rb.Chain = chain -} - -func (r *AddChainRequest) SetBody(rb *AddChainRequest_Body) { - r.Body = rb -} - -func (r *AddChainRequest) SetMetaHeader(mh *session.RequestMetaHeader) { - r.MetaHeader = mh -} - -func (r *AddChainRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) { - r.VerifyHeader = vh -} - -func (rb *AddChainResponse_Body) SetChainId(chainID []byte) { - rb.ChainId = chainID -} - -func (r *AddChainResponse) SetBody(rb *AddChainResponse_Body) { - r.Body = rb -} - -func (r *AddChainResponse) SetMetaHeader(mh *session.ResponseMetaHeader) { - r.MetaHeader = mh -} - -func (r *AddChainResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) { - r.VerifyHeader = vh -} - -func (rb *RemoveChainRequest_Body) SetTarget(t *ape.ChainTarget) { - rb.Target = t -} - -func (rb *RemoveChainRequest_Body) SetChainId(chainID []byte) { - rb.ChainId = chainID -} - -func (r *RemoveChainRequest) SetBody(rb *RemoveChainRequest_Body) { - r.Body = rb -} - -func (r *RemoveChainRequest) SetMetaHeader(mh *session.RequestMetaHeader) { - r.MetaHeader = mh -} - -func (r *RemoveChainRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) { - r.VerifyHeader = vh -} - -func (r *RemoveChainResponse) SetBody(rb *RemoveChainResponse_Body) { - r.Body = rb -} - -func (r *RemoveChainResponse) SetMetaHeader(mh *session.ResponseMetaHeader) { - r.MetaHeader = mh -} - -func (r *RemoveChainResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) { - r.VerifyHeader = vh -} - -func (r *ListChainsRequest_Body) SetTarget(t *ape.ChainTarget) { - r.Target = t -} - -func (r *ListChainsRequest) SetBody(rb *ListChainsRequest_Body) { - r.Body = rb -} - -func (r *ListChainsRequest) SetMetaHeader(mh *session.RequestMetaHeader) { - r.MetaHeader = mh -} - -func (r *ListChainsRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) { - r.VerifyHeader = vh -} - -func (rb *ListChainsResponse_Body) SetChains(chains []*ape.Chain) { - rb.Chains = chains -} - -func (r *ListChainsResponse) SetBody(rb *ListChainsResponse_Body) { - r.Body = rb -} - -func (r *ListChainsResponse) SetMetaHeader(mh *session.ResponseMetaHeader) { - r.MetaHeader = mh -} - -func (r *ListChainsResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) { - r.VerifyHeader = vh -} diff --git a/apemanager/grpc/service.pb.go b/apemanager/grpc/service.pb.go deleted file mode 100644 index 3baf193..0000000 Binary files a/apemanager/grpc/service.pb.go and /dev/null differ diff --git a/apemanager/grpc/service_frostfs.pb.go b/apemanager/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..380ba30 Binary files /dev/null and b/apemanager/grpc/service_frostfs.pb.go differ diff --git a/apemanager/grpc/service_frostfs_fuzz.go b/apemanager/grpc/service_frostfs_fuzz.go new file mode 100644 index 0000000..08af63e --- /dev/null +++ b/apemanager/grpc/service_frostfs_fuzz.go @@ -0,0 +1,121 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package apemanager + +func DoFuzzProtoAddChainRequest(data []byte) int { + msg := new(AddChainRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONAddChainRequest(data []byte) int { + msg := new(AddChainRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoAddChainResponse(data []byte) int { + msg := new(AddChainResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONAddChainResponse(data []byte) int { + msg := new(AddChainResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoRemoveChainRequest(data []byte) int { + msg := new(RemoveChainRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONRemoveChainRequest(data []byte) int { + msg := new(RemoveChainRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoRemoveChainResponse(data []byte) int { + msg := new(RemoveChainResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONRemoveChainResponse(data []byte) int { + msg := new(RemoveChainResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoListChainsRequest(data []byte) int { + msg := new(ListChainsRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONListChainsRequest(data []byte) int { + msg := new(ListChainsRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoListChainsResponse(data []byte) int { + msg := new(ListChainsResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONListChainsResponse(data []byte) int { + msg := new(ListChainsResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/apemanager/grpc/service_frostfs_test.go b/apemanager/grpc/service_frostfs_test.go new file mode 100644 index 0000000..5c4653c --- /dev/null +++ b/apemanager/grpc/service_frostfs_test.go @@ -0,0 +1,71 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package apemanager + +import ( + testing "testing" +) + +func FuzzProtoAddChainRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoAddChainRequest(data) + }) +} +func FuzzJSONAddChainRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONAddChainRequest(data) + }) +} +func FuzzProtoAddChainResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoAddChainResponse(data) + }) +} +func FuzzJSONAddChainResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONAddChainResponse(data) + }) +} +func FuzzProtoRemoveChainRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoRemoveChainRequest(data) + }) +} +func FuzzJSONRemoveChainRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONRemoveChainRequest(data) + }) +} +func FuzzProtoRemoveChainResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoRemoveChainResponse(data) + }) +} +func FuzzJSONRemoveChainResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONRemoveChainResponse(data) + }) +} +func FuzzProtoListChainsRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoListChainsRequest(data) + }) +} +func FuzzJSONListChainsRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONListChainsRequest(data) + }) +} +func FuzzProtoListChainsResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoListChainsResponse(data) + }) +} +func FuzzJSONListChainsResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONListChainsResponse(data) + }) +} diff --git a/container/grpc/service.go b/container/grpc/service.go deleted file mode 100644 index d19add1..0000000 --- a/container/grpc/service.go +++ /dev/null @@ -1,234 +0,0 @@ -package container - -import ( - acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -// SetContainer sets container of the request. -func (m *PutRequest_Body) SetContainer(v *Container) { - m.Container = v -} - -// SetSignature sets signature of the container structure. -func (m *PutRequest_Body) SetSignature(v *refs.SignatureRFC6979) { - m.Signature = v -} - -// SetBody sets body of the request. -func (m *PutRequest) SetBody(v *PutRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *PutRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *PutRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetContainerId sets identifier of the container. -func (m *PutResponse_Body) SetContainerId(v *refs.ContainerID) { - m.ContainerId = v -} - -// SetBody sets body of the response. -func (m *PutResponse) SetBody(v *PutResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *PutResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *PutResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetContainerId sets identifier of the container. -func (m *DeleteRequest_Body) SetContainerId(v *refs.ContainerID) { - m.ContainerId = v -} - -// SetSignature sets signature of the container identifier. -func (m *DeleteRequest_Body) SetSignature(v *refs.SignatureRFC6979) { - m.Signature = v -} - -// SetBody sets body of the request. -func (m *DeleteRequest) SetBody(v *DeleteRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *DeleteRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *DeleteRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetBody sets body of the response. -func (m *DeleteResponse) SetBody(v *DeleteResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *DeleteResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *DeleteResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetContainerId sets identifier of the container. -func (m *GetRequest_Body) SetContainerId(v *refs.ContainerID) { - m.ContainerId = v -} - -// SetBody sets body of the request. -func (m *GetRequest) SetBody(v *GetRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *GetRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *GetRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetContainer sets the container structure. -func (m *GetResponse_Body) SetContainer(v *Container) { - m.Container = v -} - -// SetSessionToken sets token of the session within which requested -// container was created. -func (m *GetResponse_Body) SetSessionToken(v *session.SessionToken) { - m.SessionToken = v -} - -// SetSignature sets signature of the container structure. -func (m *GetResponse_Body) SetSignature(v *refs.SignatureRFC6979) { - m.Signature = v -} - -// SetBody sets body of the response. -func (m *GetResponse) SetBody(v *GetResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *GetResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *GetResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetOwnerId sets identifier of the container owner. -func (m *ListRequest_Body) SetOwnerId(v *refs.OwnerID) { - m.OwnerId = v -} - -// SetBody sets body of the request. -func (m *ListRequest) SetBody(v *ListRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *ListRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *ListRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetContainerIds sets list of the container identifiers. -func (m *ListResponse_Body) SetContainerIds(v []*refs.ContainerID) { - m.ContainerIds = v -} - -// SetBody sets body of the response. -func (m *ListResponse) SetBody(v *ListResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *ListResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *ListResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetContainerId sets identifier of the container. -func (m *GetExtendedACLRequest_Body) SetContainerId(v *refs.ContainerID) { - m.ContainerId = v -} - -// SetBody sets body of the request. -func (m *GetExtendedACLRequest) SetBody(v *GetExtendedACLRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *GetExtendedACLRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *GetExtendedACLRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetEacl sets eACL table structure. -func (m *GetExtendedACLResponse_Body) SetEacl(v *acl.EACLTable) { - m.Eacl = v -} - -// SetSignature sets signature of the eACL table structure. -func (m *GetExtendedACLResponse_Body) SetSignature(v *refs.SignatureRFC6979) { - m.Signature = v -} - -// SetSessionToken sets token of the session within which requested -// eACl table was set. -func (m *GetExtendedACLResponse_Body) SetSessionToken(v *session.SessionToken) { - m.SessionToken = v -} - -// SetBody sets body of the response. -func (m *GetExtendedACLResponse) SetBody(v *GetExtendedACLResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *GetExtendedACLResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *GetExtendedACLResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} diff --git a/container/grpc/service.pb.go b/container/grpc/service.pb.go deleted file mode 100644 index 3bf1e14..0000000 Binary files a/container/grpc/service.pb.go and /dev/null differ diff --git a/container/grpc/service_frostfs.pb.go b/container/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..7590435 Binary files /dev/null and b/container/grpc/service_frostfs.pb.go differ diff --git a/container/grpc/service_frostfs_fuzz.go b/container/grpc/service_frostfs_fuzz.go new file mode 100644 index 0000000..496a2d6 --- /dev/null +++ b/container/grpc/service_frostfs_fuzz.go @@ -0,0 +1,197 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package container + +func DoFuzzProtoPutRequest(data []byte) int { + msg := new(PutRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPutRequest(data []byte) int { + msg := new(PutRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoPutResponse(data []byte) int { + msg := new(PutResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPutResponse(data []byte) int { + msg := new(PutResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoDeleteRequest(data []byte) int { + msg := new(DeleteRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONDeleteRequest(data []byte) int { + msg := new(DeleteRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoDeleteResponse(data []byte) int { + msg := new(DeleteResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONDeleteResponse(data []byte) int { + msg := new(DeleteResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetRequest(data []byte) int { + msg := new(GetRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetRequest(data []byte) int { + msg := new(GetRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetResponse(data []byte) int { + msg := new(GetResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetResponse(data []byte) int { + msg := new(GetResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoListRequest(data []byte) int { + msg := new(ListRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONListRequest(data []byte) int { + msg := new(ListRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoListResponse(data []byte) int { + msg := new(ListResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONListResponse(data []byte) int { + msg := new(ListResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetExtendedACLRequest(data []byte) int { + msg := new(GetExtendedACLRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetExtendedACLRequest(data []byte) int { + msg := new(GetExtendedACLRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetExtendedACLResponse(data []byte) int { + msg := new(GetExtendedACLResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetExtendedACLResponse(data []byte) int { + msg := new(GetExtendedACLResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/container/grpc/service_frostfs_test.go b/container/grpc/service_frostfs_test.go new file mode 100644 index 0000000..05eb48a --- /dev/null +++ b/container/grpc/service_frostfs_test.go @@ -0,0 +1,111 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package container + +import ( + testing "testing" +) + +func FuzzProtoPutRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPutRequest(data) + }) +} +func FuzzJSONPutRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPutRequest(data) + }) +} +func FuzzProtoPutResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPutResponse(data) + }) +} +func FuzzJSONPutResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPutResponse(data) + }) +} +func FuzzProtoDeleteRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoDeleteRequest(data) + }) +} +func FuzzJSONDeleteRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONDeleteRequest(data) + }) +} +func FuzzProtoDeleteResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoDeleteResponse(data) + }) +} +func FuzzJSONDeleteResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONDeleteResponse(data) + }) +} +func FuzzProtoGetRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetRequest(data) + }) +} +func FuzzJSONGetRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetRequest(data) + }) +} +func FuzzProtoGetResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetResponse(data) + }) +} +func FuzzJSONGetResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetResponse(data) + }) +} +func FuzzProtoListRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoListRequest(data) + }) +} +func FuzzJSONListRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONListRequest(data) + }) +} +func FuzzProtoListResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoListResponse(data) + }) +} +func FuzzJSONListResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONListResponse(data) + }) +} +func FuzzProtoGetExtendedACLRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetExtendedACLRequest(data) + }) +} +func FuzzJSONGetExtendedACLRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetExtendedACLRequest(data) + }) +} +func FuzzProtoGetExtendedACLResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetExtendedACLResponse(data) + }) +} +func FuzzJSONGetExtendedACLResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetExtendedACLResponse(data) + }) +} diff --git a/container/grpc/types.go b/container/grpc/types.go deleted file mode 100644 index 7308f9e..0000000 --- a/container/grpc/types.go +++ /dev/null @@ -1,46 +0,0 @@ -package container - -import ( - netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" -) - -// SetKey sets key to the container attribute. -func (m *Container_Attribute) SetKey(v string) { - m.Key = v -} - -// SetValue sets value of the container attribute. -func (m *Container_Attribute) SetValue(v string) { - m.Value = v -} - -// SetOwnerId sets identifier of the container owner, -func (m *Container) SetOwnerId(v *refs.OwnerID) { - m.OwnerId = v -} - -// SetNonce sets nonce of the container structure. -func (m *Container) SetNonce(v []byte) { - m.Nonce = v -} - -// SetBasicAcl sets basic ACL of the container. -func (m *Container) SetBasicAcl(v uint32) { - m.BasicAcl = v -} - -// SetAttributes sets list of the container attributes. -func (m *Container) SetAttributes(v []*Container_Attribute) { - m.Attributes = v -} - -// SetPlacementPolicy sets placement policy of the container. -func (m *Container) SetPlacementPolicy(v *netmap.PlacementPolicy) { - m.PlacementPolicy = v -} - -// SetVersion sets version of the container. -func (m *Container) SetVersion(v *refs.Version) { - m.Version = v -} diff --git a/container/grpc/types.pb.go b/container/grpc/types.pb.go deleted file mode 100644 index d0e19ec..0000000 Binary files a/container/grpc/types.pb.go and /dev/null differ diff --git a/container/grpc/types_frostfs.pb.go b/container/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..3e0d882 Binary files /dev/null and b/container/grpc/types_frostfs.pb.go differ diff --git a/container/grpc/types_frostfs_fuzz.go b/container/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..5551978 --- /dev/null +++ b/container/grpc/types_frostfs_fuzz.go @@ -0,0 +1,26 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package container + +func DoFuzzProtoContainer(data []byte) int { + msg := new(Container) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONContainer(data []byte) int { + msg := new(Container) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/container/grpc/types_frostfs_test.go b/container/grpc/types_frostfs_test.go new file mode 100644 index 0000000..64d840e --- /dev/null +++ b/container/grpc/types_frostfs_test.go @@ -0,0 +1,21 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package container + +import ( + testing "testing" +) + +func FuzzProtoContainer(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoContainer(data) + }) +} +func FuzzJSONContainer(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONContainer(data) + }) +} diff --git a/go.mod b/go.mod index e00f012..13fa1b7 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.20 require ( git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 + github.com/VictoriaMetrics/easyproto v0.1.4 + github.com/mailru/easyjson v0.7.7 github.com/stretchr/testify v1.8.3 golang.org/x/sync v0.6.0 google.golang.org/grpc v1.63.2 @@ -13,6 +15,7 @@ require ( require ( git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/kr/pretty v0.1.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/go.sum b/go.sum index 6ce46f7..620642f 100644 --- a/go.sum +++ b/go.sum @@ -2,15 +2,21 @@ git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSV git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0/go.mod h1:RUIKZATQLJ+TaYQa60X2fTDwfuhMfm8Ar60bQ5fr+vU= git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 h1:M2KR3iBj7WpY3hP10IevfIB9MURr4O9mwVfJ+SjT3HA= git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0/go.mod h1:okpbKfVYf/BpejtfFTfhZqFP+sZ8rsHrP8Rr/jYPNRc= +github.com/VictoriaMetrics/easyproto v0.1.4 h1:r8cNvo8o6sR4QShBXQd1bKw/VVLSQma/V2KhTBPf+Sc= +github.com/VictoriaMetrics/easyproto v0.1.4/go.mod h1:QlGlzaJnDfFd8Lk6Ci/fuLxfTo3/GThPs2KH23mv710= 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/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/lock/grpc/types.go b/lock/grpc/types.go deleted file mode 100644 index 9d5719f..0000000 --- a/lock/grpc/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package lock - -import refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - -// SetMembers sets `members` field. -func (x *Lock) SetMembers(ids []*refs.ObjectID) { - x.Members = ids -} diff --git a/lock/grpc/types.pb.go b/lock/grpc/types.pb.go deleted file mode 100644 index 38b62fe..0000000 Binary files a/lock/grpc/types.pb.go and /dev/null differ diff --git a/lock/grpc/types_frostfs.pb.go b/lock/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..3012111 Binary files /dev/null and b/lock/grpc/types_frostfs.pb.go differ diff --git a/lock/grpc/types_frostfs_fuzz.go b/lock/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..cb55151 --- /dev/null +++ b/lock/grpc/types_frostfs_fuzz.go @@ -0,0 +1,26 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package lock + +func DoFuzzProtoLock(data []byte) int { + msg := new(Lock) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONLock(data []byte) int { + msg := new(Lock) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/lock/grpc/types_frostfs_test.go b/lock/grpc/types_frostfs_test.go new file mode 100644 index 0000000..7c69064 --- /dev/null +++ b/lock/grpc/types_frostfs_test.go @@ -0,0 +1,21 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package lock + +import ( + testing "testing" +) + +func FuzzProtoLock(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoLock(data) + }) +} +func FuzzJSONLock(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONLock(data) + }) +} diff --git a/netmap/grpc/service.go b/netmap/grpc/service.go deleted file mode 100644 index 882db6b..0000000 --- a/netmap/grpc/service.go +++ /dev/null @@ -1,116 +0,0 @@ -package netmap - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -// SetBody sets body of the request. -func (m *LocalNodeInfoRequest) SetBody(v *LocalNodeInfoRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *LocalNodeInfoRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *LocalNodeInfoRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetVersion sets version of response body. -func (m *LocalNodeInfoResponse_Body) SetVersion(v *refs.Version) { - m.Version = v -} - -// SetNodeInfo sets node info of response body. -func (m *LocalNodeInfoResponse_Body) SetNodeInfo(v *NodeInfo) { - m.NodeInfo = v -} - -// SetBody sets body of the response. -func (m *LocalNodeInfoResponse) SetBody(v *LocalNodeInfoResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *LocalNodeInfoResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *LocalNodeInfoResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetBody sets body of the request. -func (x *NetworkInfoRequest) SetBody(v *NetworkInfoRequest_Body) { - x.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (x *NetworkInfoRequest) SetMetaHeader(v *session.RequestMetaHeader) { - x.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (x *NetworkInfoRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - x.VerifyHeader = v -} - -// SetNetworkInfo sets information about the network. -func (x *NetworkInfoResponse_Body) SetNetworkInfo(v *NetworkInfo) { - x.NetworkInfo = v -} - -// SetBody sets body of the response. -func (x *NetworkInfoResponse) SetBody(v *NetworkInfoResponse_Body) { - x.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (x *NetworkInfoResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - x.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (x *NetworkInfoResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - x.VerifyHeader = v -} - -// SetBody sets body of the request. -func (x *NetmapSnapshotRequest) SetBody(v *NetmapSnapshotRequest_Body) { - x.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (x *NetmapSnapshotRequest) SetMetaHeader(v *session.RequestMetaHeader) { - x.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (x *NetmapSnapshotRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - x.VerifyHeader = v -} - -// SetNetmap sets current Netmap. -func (x *NetmapSnapshotResponse_Body) SetNetmap(v *Netmap) { - x.Netmap = v -} - -// SetBody sets body of the response. -func (x *NetmapSnapshotResponse) SetBody(v *NetmapSnapshotResponse_Body) { - x.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (x *NetmapSnapshotResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - x.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (x *NetmapSnapshotResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - x.VerifyHeader = v -} diff --git a/netmap/grpc/service.pb.go b/netmap/grpc/service.pb.go deleted file mode 100644 index eb91862..0000000 Binary files a/netmap/grpc/service.pb.go and /dev/null differ diff --git a/netmap/grpc/service_frostfs.pb.go b/netmap/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..1ce80ff Binary files /dev/null and b/netmap/grpc/service_frostfs.pb.go differ diff --git a/netmap/grpc/service_frostfs_fuzz.go b/netmap/grpc/service_frostfs_fuzz.go new file mode 100644 index 0000000..ebb59bc --- /dev/null +++ b/netmap/grpc/service_frostfs_fuzz.go @@ -0,0 +1,121 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package netmap + +func DoFuzzProtoLocalNodeInfoRequest(data []byte) int { + msg := new(LocalNodeInfoRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONLocalNodeInfoRequest(data []byte) int { + msg := new(LocalNodeInfoRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoLocalNodeInfoResponse(data []byte) int { + msg := new(LocalNodeInfoResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONLocalNodeInfoResponse(data []byte) int { + msg := new(LocalNodeInfoResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoNetworkInfoRequest(data []byte) int { + msg := new(NetworkInfoRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONNetworkInfoRequest(data []byte) int { + msg := new(NetworkInfoRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoNetworkInfoResponse(data []byte) int { + msg := new(NetworkInfoResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONNetworkInfoResponse(data []byte) int { + msg := new(NetworkInfoResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoNetmapSnapshotRequest(data []byte) int { + msg := new(NetmapSnapshotRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONNetmapSnapshotRequest(data []byte) int { + msg := new(NetmapSnapshotRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoNetmapSnapshotResponse(data []byte) int { + msg := new(NetmapSnapshotResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONNetmapSnapshotResponse(data []byte) int { + msg := new(NetmapSnapshotResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/netmap/grpc/service_frostfs_test.go b/netmap/grpc/service_frostfs_test.go new file mode 100644 index 0000000..5c9035f --- /dev/null +++ b/netmap/grpc/service_frostfs_test.go @@ -0,0 +1,71 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package netmap + +import ( + testing "testing" +) + +func FuzzProtoLocalNodeInfoRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoLocalNodeInfoRequest(data) + }) +} +func FuzzJSONLocalNodeInfoRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONLocalNodeInfoRequest(data) + }) +} +func FuzzProtoLocalNodeInfoResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoLocalNodeInfoResponse(data) + }) +} +func FuzzJSONLocalNodeInfoResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONLocalNodeInfoResponse(data) + }) +} +func FuzzProtoNetworkInfoRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoNetworkInfoRequest(data) + }) +} +func FuzzJSONNetworkInfoRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONNetworkInfoRequest(data) + }) +} +func FuzzProtoNetworkInfoResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoNetworkInfoResponse(data) + }) +} +func FuzzJSONNetworkInfoResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONNetworkInfoResponse(data) + }) +} +func FuzzProtoNetmapSnapshotRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoNetmapSnapshotRequest(data) + }) +} +func FuzzJSONNetmapSnapshotRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONNetmapSnapshotRequest(data) + }) +} +func FuzzProtoNetmapSnapshotResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoNetmapSnapshotResponse(data) + }) +} +func FuzzJSONNetmapSnapshotResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONNetmapSnapshotResponse(data) + }) +} diff --git a/netmap/grpc/types.go b/netmap/grpc/types.go deleted file mode 100644 index f4e90f8..0000000 --- a/netmap/grpc/types.go +++ /dev/null @@ -1,212 +0,0 @@ -package netmap - -// SetReplicas of placement policy. -func (m *PlacementPolicy) SetReplicas(v []*Replica) { - m.Replicas = v -} - -// SetContainerBackupFactor of placement policy. -func (m *PlacementPolicy) SetContainerBackupFactor(v uint32) { - m.ContainerBackupFactor = v -} - -// SetSelectors of placement policy. -func (m *PlacementPolicy) SetSelectors(v []*Selector) { - m.Selectors = v -} - -// SetFilters of placement policy. -func (m *PlacementPolicy) SetFilters(v []*Filter) { - m.Filters = v -} - -// SetUnique of placement policy. -func (m *PlacementPolicy) SetUnique(unique bool) { - m.Unique = unique -} - -// SetName of placement filter. -func (m *Filter) SetName(v string) { - m.Name = v -} - -// SetKey of placement filter. -func (m *Filter) SetKey(v string) { - m.Key = v -} - -// SetOperation of placement filter. -func (m *Filter) SetOp(v Operation) { - m.Op = v -} - -// SetValue of placement filter. -func (m *Filter) SetValue(v string) { - m.Value = v -} - -// SetFilters sets sub-filters of placement filter. -func (m *Filter) SetFilters(v []*Filter) { - m.Filters = v -} - -// SetName of placement selector. -func (m *Selector) SetName(v string) { - m.Name = v -} - -// SetCount of nodes of placement selector. -func (m *Selector) SetCount(v uint32) { - m.Count = v -} - -// SetAttribute of nodes of placement selector. -func (m *Selector) SetAttribute(v string) { - m.Attribute = v -} - -// SetFilter of placement selector. -func (m *Selector) SetFilter(v string) { - m.Filter = v -} - -// SetClause of placement selector. -func (m *Selector) SetClause(v Clause) { - m.Clause = v -} - -// SetCount of object replica. -func (m *Replica) SetCount(v uint32) { - m.Count = v -} - -// SetSelector of object replica. -func (m *Replica) SetSelector(v string) { - m.Selector = v -} - -// SetKey sets key to the node attribute. -func (m *NodeInfo_Attribute) SetKey(v string) { - m.Key = v -} - -// SetValue sets value of the node attribute. -func (m *NodeInfo_Attribute) SetValue(v string) { - m.Value = v -} - -// SetParent sets value of the node parents. -func (m *NodeInfo_Attribute) SetParents(v []string) { - m.Parents = v -} - -// SetAddress sets node network address. -// -// Deprecated: use SetAddresses. -func (m *NodeInfo) SetAddress(v string) { - m.SetAddresses([]string{v}) -} - -// SetAddresses sets list of network addresses of the node. -func (m *NodeInfo) SetAddresses(v []string) { - m.Addresses = v -} - -// SetPublicKey sets node public key in a binary format. -func (m *NodeInfo) SetPublicKey(v []byte) { - m.PublicKey = v -} - -// SetAttributes sets list of the node attributes. -func (m *NodeInfo) SetAttributes(v []*NodeInfo_Attribute) { - m.Attributes = v -} - -// SetState sets node state. -func (m *NodeInfo) SetState(v NodeInfo_State) { - m.State = v -} - -// SetCurrentEpoch sets number of the current epoch. -func (x *NetworkInfo) SetCurrentEpoch(v uint64) { - x.CurrentEpoch = v -} - -// SetMagicNumber sets magic number of the sidechain. -func (x *NetworkInfo) SetMagicNumber(v uint64) { - x.MagicNumber = v -} - -// SetMsPerBlock sets MillisecondsPerBlock network parameter. -func (x *NetworkInfo) SetMsPerBlock(v int64) { - x.MsPerBlock = v -} - -// SetNetworkConfig sets NeoFS network configuration. -func (x *NetworkInfo) SetNetworkConfig(v *NetworkConfig) { - x.NetworkConfig = v -} - -// FromString parses Clause from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Clause) FromString(s string) bool { - i, ok := Clause_value[s] - if ok { - *x = Clause(i) - } - - return ok -} - -// FromString parses Operation from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Operation) FromString(s string) bool { - i, ok := Operation_value[s] - if ok { - *x = Operation(i) - } - - return ok -} - -// FromString parses NodeInfo_State from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *NodeInfo_State) FromString(s string) bool { - i, ok := NodeInfo_State_value[s] - if ok { - *x = NodeInfo_State(i) - } - - return ok -} - -// SetKey sets parameter key. -func (x *NetworkConfig_Parameter) SetKey(v []byte) { - x.Key = v -} - -// SetValue sets parameter value. -func (x *NetworkConfig_Parameter) SetValue(v []byte) { - x.Value = v -} - -// SetParameters sets NeoFS network parameters. -func (x *NetworkConfig) SetParameters(v []*NetworkConfig_Parameter) { - x.Parameters = v -} - -// SetEpoch sets revision number of the Netmap. -func (x *Netmap) SetEpoch(v uint64) { - x.Epoch = v -} - -// SetNodes sets nodes presented in the Netmap. -func (x *Netmap) SetNodes(v []*NodeInfo) { - x.Nodes = v -} diff --git a/netmap/grpc/types.pb.go b/netmap/grpc/types.pb.go deleted file mode 100644 index ae1f55f..0000000 Binary files a/netmap/grpc/types.pb.go and /dev/null differ diff --git a/netmap/grpc/types_frostfs.pb.go b/netmap/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..3bab079 Binary files /dev/null and b/netmap/grpc/types_frostfs.pb.go differ diff --git a/netmap/grpc/types_frostfs_fuzz.go b/netmap/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..89ccd74 --- /dev/null +++ b/netmap/grpc/types_frostfs_fuzz.go @@ -0,0 +1,159 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package netmap + +func DoFuzzProtoFilter(data []byte) int { + msg := new(Filter) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONFilter(data []byte) int { + msg := new(Filter) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoSelector(data []byte) int { + msg := new(Selector) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONSelector(data []byte) int { + msg := new(Selector) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoReplica(data []byte) int { + msg := new(Replica) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONReplica(data []byte) int { + msg := new(Replica) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoPlacementPolicy(data []byte) int { + msg := new(PlacementPolicy) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPlacementPolicy(data []byte) int { + msg := new(PlacementPolicy) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoNodeInfo(data []byte) int { + msg := new(NodeInfo) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONNodeInfo(data []byte) int { + msg := new(NodeInfo) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoNetmap(data []byte) int { + msg := new(Netmap) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONNetmap(data []byte) int { + msg := new(Netmap) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoNetworkConfig(data []byte) int { + msg := new(NetworkConfig) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONNetworkConfig(data []byte) int { + msg := new(NetworkConfig) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoNetworkInfo(data []byte) int { + msg := new(NetworkInfo) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONNetworkInfo(data []byte) int { + msg := new(NetworkInfo) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/netmap/grpc/types_frostfs_test.go b/netmap/grpc/types_frostfs_test.go new file mode 100644 index 0000000..9996dc9 --- /dev/null +++ b/netmap/grpc/types_frostfs_test.go @@ -0,0 +1,91 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package netmap + +import ( + testing "testing" +) + +func FuzzProtoFilter(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoFilter(data) + }) +} +func FuzzJSONFilter(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONFilter(data) + }) +} +func FuzzProtoSelector(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoSelector(data) + }) +} +func FuzzJSONSelector(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONSelector(data) + }) +} +func FuzzProtoReplica(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoReplica(data) + }) +} +func FuzzJSONReplica(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONReplica(data) + }) +} +func FuzzProtoPlacementPolicy(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPlacementPolicy(data) + }) +} +func FuzzJSONPlacementPolicy(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPlacementPolicy(data) + }) +} +func FuzzProtoNodeInfo(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoNodeInfo(data) + }) +} +func FuzzJSONNodeInfo(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONNodeInfo(data) + }) +} +func FuzzProtoNetmap(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoNetmap(data) + }) +} +func FuzzJSONNetmap(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONNetmap(data) + }) +} +func FuzzProtoNetworkConfig(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoNetworkConfig(data) + }) +} +func FuzzJSONNetworkConfig(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONNetworkConfig(data) + }) +} +func FuzzProtoNetworkInfo(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoNetworkInfo(data) + }) +} +func FuzzJSONNetworkInfo(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONNetworkInfo(data) + }) +} diff --git a/object/convert.go b/object/convert.go index 9814b58..e237883 100644 --- a/object/convert.go +++ b/object/convert.go @@ -2491,7 +2491,7 @@ func (r *PatchResponseBody) ToGRPCMessage() grpc.Message { if r != nil { m = new(object.PatchResponse_Body) - m.SetObjectID(r.ObjectID.ToGRPCMessage().(*refsGRPC.ObjectID)) + m.SetObjectId(r.ObjectID.ToGRPCMessage().(*refsGRPC.ObjectID)) } return m diff --git a/object/grpc/service.go b/object/grpc/service.go deleted file mode 100644 index ef6422e..0000000 --- a/object/grpc/service.go +++ /dev/null @@ -1,610 +0,0 @@ -package object - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -// SetAddress sets address of the requested object. -func (m *GetRequest_Body) SetAddress(v *refs.Address) { - m.Address = v -} - -// SetRaw sets raw flag of the request. -func (m *GetRequest_Body) SetRaw(v bool) { - m.Raw = v -} - -// SetBody sets body of the request. -func (m *GetRequest) SetBody(v *GetRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *GetRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *GetRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetObjectId sets identifier of the object. -func (m *GetResponse_Body_Init) SetObjectId(v *refs.ObjectID) { - m.ObjectId = v -} - -// SetSignature sets signature of the object identifier. -func (m *GetResponse_Body_Init) SetSignature(v *refs.Signature) { - m.Signature = v -} - -// SetHeader sets header of the object. -func (m *GetResponse_Body_Init) SetHeader(v *Header) { - m.Header = v -} - -// GetChunk returns chunk of the object payload bytes. -func (m *GetResponse_Body_Chunk) GetChunk() []byte { - if m != nil { - return m.Chunk - } - - return nil -} - -// SetChunk sets chunk of the object payload bytes. -func (m *GetResponse_Body_Chunk) SetChunk(v []byte) { - m.Chunk = v -} - -// SetInit sets initial part of the object. -func (m *GetResponse_Body) SetInit(v *GetResponse_Body_Init) { - m.ObjectPart = &GetResponse_Body_Init_{ - Init: v, - } -} - -// SetChunk sets part of the object payload. -func (m *GetResponse_Body) SetChunk(v *GetResponse_Body_Chunk) { - m.ObjectPart = v -} - -// SetSplitInfo sets part of the object payload. -func (m *GetResponse_Body) SetSplitInfo(v *SplitInfo) { - m.ObjectPart = &GetResponse_Body_SplitInfo{ - SplitInfo: v, - } -} - -// SetEcInfo sets part of the object payload. -func (m *GetResponse_Body) SetEcInfo(v *ECInfo) { - m.ObjectPart = &GetResponse_Body_EcInfo{ - EcInfo: v, - } -} - -// SetBody sets body of the response. -func (m *GetResponse) SetBody(v *GetResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *GetResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *GetResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetObjectId sets identifier of the object. -func (m *PutRequest_Body_Init) SetObjectId(v *refs.ObjectID) { - m.ObjectId = v -} - -// SetSignature sets signature of the object identifier. -func (m *PutRequest_Body_Init) SetSignature(v *refs.Signature) { - m.Signature = v -} - -// SetHeader sets header of the object. -func (m *PutRequest_Body_Init) SetHeader(v *Header) { - m.Header = v -} - -// SetCopiesNumber sets number of the copies to save. -func (m *PutRequest_Body_Init) SetCopiesNumber(v []uint32) { - m.CopiesNumber = v -} - -// GetChunk returns chunk of the object payload bytes. -func (m *PutRequest_Body_Chunk) GetChunk() []byte { - if m != nil { - return m.Chunk - } - - return nil -} - -// SetChunk sets chunk of the object payload bytes. -func (m *PutRequest_Body_Chunk) SetChunk(v []byte) { - m.Chunk = v -} - -// SetInit sets initial part of the object. -func (m *PutRequest_Body) SetInit(v *PutRequest_Body_Init) { - m.ObjectPart = &PutRequest_Body_Init_{ - Init: v, - } -} - -// SetChunk sets part of the object payload. -func (m *PutRequest_Body) SetChunk(v *PutRequest_Body_Chunk) { - m.ObjectPart = v -} - -// SetBody sets body of the request. -func (m *PutRequest) SetBody(v *PutRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *PutRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *PutRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetObjectId sets identifier of the saved object. -func (m *PutResponse_Body) SetObjectId(v *refs.ObjectID) { - m.ObjectId = v -} - -// SetBody sets body of the response. -func (m *PutResponse) SetBody(v *PutResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *PutResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *PutResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetAddress sets address of the object to delete. -func (m *DeleteRequest_Body) SetAddress(v *refs.Address) { - m.Address = v -} - -// SetBody sets body of the request. -func (m *DeleteRequest) SetBody(v *DeleteRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *DeleteRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *DeleteRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetTombstone sets tombstone address. -func (x *DeleteResponse_Body) SetTombstone(v *refs.Address) { - x.Tombstone = v -} - -// SetBody sets body of the response. -func (m *DeleteResponse) SetBody(v *DeleteResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *DeleteResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *DeleteResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetAddress sets address of the object with the requested header. -func (m *HeadRequest_Body) SetAddress(v *refs.Address) { - m.Address = v -} - -// SetMainOnly sets flag to return the minimal header subset. -func (m *HeadRequest_Body) SetMainOnly(v bool) { - m.MainOnly = v -} - -// SetRaw sets raw flag of the request. -func (m *HeadRequest_Body) SetRaw(v bool) { - m.Raw = v -} - -// SetBody sets body of the request. -func (m *HeadRequest) SetBody(v *HeadRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *HeadRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *HeadRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetHeader sets object header. -func (m *HeaderWithSignature) SetHeader(v *Header) { - m.Header = v -} - -// SetSignature of the header. -func (m *HeaderWithSignature) SetSignature(v *refs.Signature) { - m.Signature = v -} - -// SetHeader sets full header of the object. -func (m *HeadResponse_Body) SetHeader(v *HeaderWithSignature) { - m.Head = &HeadResponse_Body_Header{ - Header: v, - } -} - -// SetShortHeader sets short header of the object. -func (m *HeadResponse_Body) SetShortHeader(v *ShortHeader) { - m.Head = &HeadResponse_Body_ShortHeader{ - ShortHeader: v, - } -} - -// SetSplitInfo sets meta info about split hierarchy of the object. -func (m *HeadResponse_Body) SetSplitInfo(v *SplitInfo) { - m.Head = &HeadResponse_Body_SplitInfo{ - SplitInfo: v, - } -} - -// SetEcInfo sets meta info about the erasure coded object. -func (m *HeadResponse_Body) SetEcInfo(v *ECInfo) { - m.Head = &HeadResponse_Body_EcInfo{ - EcInfo: v, - } -} - -// SetBody sets body of the response. -func (m *HeadResponse) SetBody(v *HeadResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *HeadResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *HeadResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetMatchType sets match type of the filter. -func (m *SearchRequest_Body_Filter) SetMatchType(v MatchType) { - m.MatchType = v -} - -// SetKey sets key to the filtering header. -func (m *SearchRequest_Body_Filter) SetKey(v string) { - m.Key = v -} - -// SetValue sets value of the filtering header. -func (m *SearchRequest_Body_Filter) SetValue(v string) { - m.Value = v -} - -// SetVersion sets version of the search query. -func (m *SearchRequest_Body) SetVersion(v uint32) { - m.Version = v -} - -// SetFilters sets list of the query filters. -func (m *SearchRequest_Body) SetFilters(v []*SearchRequest_Body_Filter) { - m.Filters = v -} - -// SetContainerId sets container ID of the search requets. -func (m *SearchRequest_Body) SetContainerId(v *refs.ContainerID) { - m.ContainerId = v -} - -// SetBody sets body of the request. -func (m *SearchRequest) SetBody(v *SearchRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *SearchRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *SearchRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetIdList sets list of the identifiers of the matched objects. -func (m *SearchResponse_Body) SetIdList(v []*refs.ObjectID) { - m.IdList = v -} - -// SetBody sets body of the response. -func (m *SearchResponse) SetBody(v *SearchResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *SearchResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *SearchResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetOffset sets offset of the payload range. -func (m *Range) SetOffset(v uint64) { - m.Offset = v -} - -// SetLength sets length of the payload range. -func (m *Range) SetLength(v uint64) { - m.Length = v -} - -// SetAddress sets address of the object with the request payload range. -func (m *GetRangeRequest_Body) SetAddress(v *refs.Address) { - m.Address = v -} - -// SetRange sets range of the object payload. -func (m *GetRangeRequest_Body) SetRange(v *Range) { - m.Range = v -} - -// SetRaw sets raw flag of the request. -func (m *GetRangeRequest_Body) SetRaw(v bool) { - m.Raw = v -} - -// SetBody sets body of the request. -func (m *GetRangeRequest) SetBody(v *GetRangeRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *GetRangeRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *GetRangeRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// GetChunk returns chunk of the object payload range bytes. -func (m *GetRangeResponse_Body_Chunk) GetChunk() []byte { - if m != nil { - return m.Chunk - } - - return nil -} - -// SetChunk sets chunk of the object payload range bytes. -func (m *GetRangeResponse_Body_Chunk) SetChunk(v []byte) { - m.Chunk = v -} - -// SetChunk sets chunk of the object payload. -func (m *GetRangeResponse_Body) SetChunk(v *GetRangeResponse_Body_Chunk) { - m.RangePart = v -} - -// SetSplitInfo sets meta info about split hierarchy of the object. -func (m *GetRangeResponse_Body) SetSplitInfo(v *SplitInfo) { - m.RangePart = &GetRangeResponse_Body_SplitInfo{ - SplitInfo: v, - } -} - -// SetEcInfo sets meta info about the erasure-coded object. -func (m *GetRangeResponse_Body) SetEcInfo(v *ECInfo) { - m.RangePart = &GetRangeResponse_Body_EcInfo{ - EcInfo: v, - } -} - -// SetBody sets body of the response. -func (m *GetRangeResponse) SetBody(v *GetRangeResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *GetRangeResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *GetRangeResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetAddress sets address of the object with the request payload range. -func (m *GetRangeHashRequest_Body) SetAddress(v *refs.Address) { - m.Address = v -} - -// SetRanges sets list of the ranges of the object payload. -func (m *GetRangeHashRequest_Body) SetRanges(v []*Range) { - m.Ranges = v -} - -// SetSalt sets salt for the object payload ranges. -func (m *GetRangeHashRequest_Body) SetSalt(v []byte) { - m.Salt = v -} - -// Set sets salt for the object payload ranges. -func (m *GetRangeHashRequest_Body) SetType(v refs.ChecksumType) { - m.Type = v -} - -// SetBody sets body of the request. -func (m *GetRangeHashRequest) SetBody(v *GetRangeHashRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *GetRangeHashRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *GetRangeHashRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetHashList returns list of the range hashes. -func (m *GetRangeHashResponse_Body) SetHashList(v [][]byte) { - m.HashList = v -} - -// SetHashList returns list of the range hashes. -func (m *GetRangeHashResponse_Body) SetType(v refs.ChecksumType) { - m.Type = v -} - -// SetBody sets body of the response. -func (m *GetRangeHashResponse) SetBody(v *GetRangeHashResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *GetRangeHashResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *GetRangeHashResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -// SetObject set object of the body. -func (m *PutSingleRequest_Body) SetObject(o *Object) { - m.Object = o -} - -// SetCopiesNumber sets copies number of the body. -func (m *PutSingleRequest_Body) SetCopiesNumber(v []uint32) { - m.CopiesNumber = v -} - -// SetBody sets body of the request. -func (m *PutSingleRequest) SetBody(b *PutSingleRequest_Body) { - m.Body = b -} - -// SetMetaHeader sets meta header of the request. -func (m *PutSingleRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *PutSingleRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetBody sets body of the response. -func (m *PutSingleResponse) SetBody(b *PutSingleResponse_Body) { - m.Body = b -} - -// SetMetaHeader sets meta header of the response. -func (m *PutSingleResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *PutSingleResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} - -func (m *PatchRequest_Body) SetAddress(addr *refs.Address) { - m.Address = addr -} - -func (m *PatchRequest_Body) SetNewAttributes(attrs []*Header_Attribute) { - m.NewAttributes = attrs -} - -func (m *PatchRequest_Body) SetReplaceAttributes(replaceAttributes bool) { - m.ReplaceAttributes = replaceAttributes -} - -func (m *PatchRequest_Body) SetPatch(patch *PatchRequest_Body_Patch) { - m.Patch = patch -} - -func (m *PatchRequest_Body_Patch) SetSourceRange(r *Range) { - m.SourceRange = r -} - -func (m *PatchRequest_Body_Patch) SetChunk(chunk []byte) { - m.Chunk = chunk -} - -func (m *PatchRequest) SetBody(b *PatchRequest_Body) { - m.Body = b -} - -func (m *PatchRequest) SetMetaHeader(v *session.RequestMetaHeader) { - m.MetaHeader = v -} - -func (m *PatchRequest) SetVerifyHeader(v *session.RequestVerificationHeader) { - m.VerifyHeader = v -} - -func (m *PatchResponse_Body) SetObjectID(objectID *refs.ObjectID) { - m.ObjectId = objectID -} - -func (m *PatchResponse) SetBody(b *PatchResponse_Body) { - m.Body = b -} - -func (m *PatchResponse) SetMetaHeader(v *session.ResponseMetaHeader) { - m.MetaHeader = v -} - -func (m *PatchResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { - m.VerifyHeader = v -} diff --git a/object/grpc/service.pb.go b/object/grpc/service.pb.go deleted file mode 100644 index 979c932..0000000 Binary files a/object/grpc/service.pb.go and /dev/null differ diff --git a/object/grpc/service_frostfs.pb.go b/object/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..08b2860 Binary files /dev/null and b/object/grpc/service_frostfs.pb.go differ diff --git a/object/grpc/service_frostfs_fuzz.go b/object/grpc/service_frostfs_fuzz.go new file mode 100644 index 0000000..f58ee01 --- /dev/null +++ b/object/grpc/service_frostfs_fuzz.go @@ -0,0 +1,387 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package object + +func DoFuzzProtoGetRequest(data []byte) int { + msg := new(GetRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetRequest(data []byte) int { + msg := new(GetRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetResponse(data []byte) int { + msg := new(GetResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetResponse(data []byte) int { + msg := new(GetResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoPutRequest(data []byte) int { + msg := new(PutRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPutRequest(data []byte) int { + msg := new(PutRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoPutResponse(data []byte) int { + msg := new(PutResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPutResponse(data []byte) int { + msg := new(PutResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoDeleteRequest(data []byte) int { + msg := new(DeleteRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONDeleteRequest(data []byte) int { + msg := new(DeleteRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoDeleteResponse(data []byte) int { + msg := new(DeleteResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONDeleteResponse(data []byte) int { + msg := new(DeleteResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoHeadRequest(data []byte) int { + msg := new(HeadRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONHeadRequest(data []byte) int { + msg := new(HeadRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoHeaderWithSignature(data []byte) int { + msg := new(HeaderWithSignature) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONHeaderWithSignature(data []byte) int { + msg := new(HeaderWithSignature) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoHeadResponse(data []byte) int { + msg := new(HeadResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONHeadResponse(data []byte) int { + msg := new(HeadResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoSearchRequest(data []byte) int { + msg := new(SearchRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONSearchRequest(data []byte) int { + msg := new(SearchRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoSearchResponse(data []byte) int { + msg := new(SearchResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONSearchResponse(data []byte) int { + msg := new(SearchResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoRange(data []byte) int { + msg := new(Range) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONRange(data []byte) int { + msg := new(Range) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetRangeRequest(data []byte) int { + msg := new(GetRangeRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetRangeRequest(data []byte) int { + msg := new(GetRangeRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetRangeResponse(data []byte) int { + msg := new(GetRangeResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetRangeResponse(data []byte) int { + msg := new(GetRangeResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetRangeHashRequest(data []byte) int { + msg := new(GetRangeHashRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetRangeHashRequest(data []byte) int { + msg := new(GetRangeHashRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoGetRangeHashResponse(data []byte) int { + msg := new(GetRangeHashResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONGetRangeHashResponse(data []byte) int { + msg := new(GetRangeHashResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoPutSingleRequest(data []byte) int { + msg := new(PutSingleRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPutSingleRequest(data []byte) int { + msg := new(PutSingleRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoPutSingleResponse(data []byte) int { + msg := new(PutSingleResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPutSingleResponse(data []byte) int { + msg := new(PutSingleResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoPatchRequest(data []byte) int { + msg := new(PatchRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPatchRequest(data []byte) int { + msg := new(PatchRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoPatchResponse(data []byte) int { + msg := new(PatchResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONPatchResponse(data []byte) int { + msg := new(PatchResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/object/grpc/service_frostfs_test.go b/object/grpc/service_frostfs_test.go new file mode 100644 index 0000000..cb4baeb --- /dev/null +++ b/object/grpc/service_frostfs_test.go @@ -0,0 +1,211 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package object + +import ( + testing "testing" +) + +func FuzzProtoGetRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetRequest(data) + }) +} +func FuzzJSONGetRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetRequest(data) + }) +} +func FuzzProtoGetResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetResponse(data) + }) +} +func FuzzJSONGetResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetResponse(data) + }) +} +func FuzzProtoPutRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPutRequest(data) + }) +} +func FuzzJSONPutRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPutRequest(data) + }) +} +func FuzzProtoPutResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPutResponse(data) + }) +} +func FuzzJSONPutResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPutResponse(data) + }) +} +func FuzzProtoDeleteRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoDeleteRequest(data) + }) +} +func FuzzJSONDeleteRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONDeleteRequest(data) + }) +} +func FuzzProtoDeleteResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoDeleteResponse(data) + }) +} +func FuzzJSONDeleteResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONDeleteResponse(data) + }) +} +func FuzzProtoHeadRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoHeadRequest(data) + }) +} +func FuzzJSONHeadRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONHeadRequest(data) + }) +} +func FuzzProtoHeaderWithSignature(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoHeaderWithSignature(data) + }) +} +func FuzzJSONHeaderWithSignature(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONHeaderWithSignature(data) + }) +} +func FuzzProtoHeadResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoHeadResponse(data) + }) +} +func FuzzJSONHeadResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONHeadResponse(data) + }) +} +func FuzzProtoSearchRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoSearchRequest(data) + }) +} +func FuzzJSONSearchRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONSearchRequest(data) + }) +} +func FuzzProtoSearchResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoSearchResponse(data) + }) +} +func FuzzJSONSearchResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONSearchResponse(data) + }) +} +func FuzzProtoRange(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoRange(data) + }) +} +func FuzzJSONRange(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONRange(data) + }) +} +func FuzzProtoGetRangeRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetRangeRequest(data) + }) +} +func FuzzJSONGetRangeRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetRangeRequest(data) + }) +} +func FuzzProtoGetRangeResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetRangeResponse(data) + }) +} +func FuzzJSONGetRangeResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetRangeResponse(data) + }) +} +func FuzzProtoGetRangeHashRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetRangeHashRequest(data) + }) +} +func FuzzJSONGetRangeHashRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetRangeHashRequest(data) + }) +} +func FuzzProtoGetRangeHashResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoGetRangeHashResponse(data) + }) +} +func FuzzJSONGetRangeHashResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONGetRangeHashResponse(data) + }) +} +func FuzzProtoPutSingleRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPutSingleRequest(data) + }) +} +func FuzzJSONPutSingleRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPutSingleRequest(data) + }) +} +func FuzzProtoPutSingleResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPutSingleResponse(data) + }) +} +func FuzzJSONPutSingleResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPutSingleResponse(data) + }) +} +func FuzzProtoPatchRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPatchRequest(data) + }) +} +func FuzzJSONPatchRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPatchRequest(data) + }) +} +func FuzzProtoPatchResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoPatchResponse(data) + }) +} +func FuzzJSONPatchResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONPatchResponse(data) + }) +} diff --git a/object/grpc/service_grpc.pb.go b/object/grpc/service_grpc.pb.go index 2494be9..687df99 100644 Binary files a/object/grpc/service_grpc.pb.go and b/object/grpc/service_grpc.pb.go differ diff --git a/object/grpc/status.pb.go b/object/grpc/status.pb.go deleted file mode 100644 index 034fa1b..0000000 Binary files a/object/grpc/status.pb.go and /dev/null differ diff --git a/object/grpc/types.go b/object/grpc/types.go deleted file mode 100644 index 9a2cdea..0000000 --- a/object/grpc/types.go +++ /dev/null @@ -1,197 +0,0 @@ -package object - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -// SetKey sets key to the object attribute. -func (m *Header_Attribute) SetKey(v string) { - m.Key = v -} - -// SetValue sets value of the object attribute. -func (m *Header_Attribute) SetValue(v string) { - m.Value = v -} - -// SetParent sets identifier of the parent object. -func (m *Header_Split) SetParent(v *refs.ObjectID) { - m.Parent = v -} - -// SetPrevious sets identifier of the previous object in split-chain. -func (m *Header_Split) SetPrevious(v *refs.ObjectID) { - m.Previous = v -} - -// SetParentSignature sets signature of the parent object header. -func (m *Header_Split) SetParentSignature(v *refs.Signature) { - m.ParentSignature = v -} - -// SetParentHeader sets parent header structure. -func (m *Header_Split) SetParentHeader(v *Header) { - m.ParentHeader = v -} - -// SetChildren sets list of the identifiers of the child objects. -func (m *Header_Split) SetChildren(v []*refs.ObjectID) { - m.Children = v -} - -// SetSplitId sets split ID of the object. -func (m *Header_Split) SetSplitId(v []byte) { - m.SplitId = v -} - -// SetContainerId sets identifier of the container. -func (m *Header) SetContainerId(v *refs.ContainerID) { - m.ContainerId = v -} - -// SetOwnerId sets identifier of the object owner. -func (m *Header) SetOwnerId(v *refs.OwnerID) { - m.OwnerId = v -} - -// SetCreationEpoch sets creation epoch number. -func (m *Header) SetCreationEpoch(v uint64) { - m.CreationEpoch = v -} - -// SetVersion sets version of the object format. -func (m *Header) SetVersion(v *refs.Version) { - m.Version = v -} - -// SetPayloadLength sets length of the object payload. -func (m *Header) SetPayloadLength(v uint64) { - m.PayloadLength = v -} - -// SetPayloadHash sets hash of the object payload. -func (m *Header) SetPayloadHash(v *refs.Checksum) { - m.PayloadHash = v -} - -// SetObjectType sets type of the object. -func (m *Header) SetObjectType(v ObjectType) { - m.ObjectType = v -} - -// SetHomomorphicHash sets homomorphic hash of the object payload. -func (m *Header) SetHomomorphicHash(v *refs.Checksum) { - m.HomomorphicHash = v -} - -// SetSessionToken sets session token. -func (m *Header) SetSessionToken(v *session.SessionToken) { - m.SessionToken = v -} - -// SetAttributes sets list of the object attributes. -func (m *Header) SetAttributes(v []*Header_Attribute) { - m.Attributes = v -} - -// SetSplit sets split header. -func (m *Header) SetSplit(v *Header_Split) { - m.Split = v -} - -// SetObjectId sets identifier of the object. -func (m *Object) SetObjectId(v *refs.ObjectID) { - m.ObjectId = v -} - -// SetSignature sets signature of the object identifier. -func (m *Object) SetSignature(v *refs.Signature) { - m.Signature = v -} - -// SetHeader sets header of the object. -func (m *Object) SetHeader(v *Header) { - m.Header = v -} - -// SetPayload sets payload bytes of the object. -func (m *Object) SetPayload(v []byte) { - m.Payload = v -} - -// SetVersion sets version of the object. -func (m *ShortHeader) SetVersion(v *refs.Version) { - m.Version = v -} - -// SetCreationEpoch sets creation epoch number. -func (m *ShortHeader) SetCreationEpoch(v uint64) { - m.CreationEpoch = v -} - -// SetOwnerId sets identifier of the object owner. -func (m *ShortHeader) SetOwnerId(v *refs.OwnerID) { - m.OwnerId = v -} - -// SetObjectType sets type of the object. -func (m *ShortHeader) SetObjectType(v ObjectType) { - m.ObjectType = v -} - -// SetPayloadLength sets length of the object payload. -func (m *ShortHeader) SetPayloadLength(v uint64) { - m.PayloadLength = v -} - -// SetPayloadHash sets hash of the object payload. -func (m *ShortHeader) SetPayloadHash(v *refs.Checksum) { - m.PayloadHash = v -} - -// SetHomomorphicHash sets homomorphic hash of the object payload. -func (m *ShortHeader) SetHomomorphicHash(v *refs.Checksum) { - m.HomomorphicHash = v -} - -// SetSplitId sets id of split hierarchy. -func (m *SplitInfo) SetSplitId(v []byte) { - m.SplitId = v -} - -// SetLastPart sets id of most right child in split hierarchy. -func (m *SplitInfo) SetLastPart(v *refs.ObjectID) { - m.LastPart = v -} - -// SetLink sets id of linking object in split hierarchy. -func (m *SplitInfo) SetLink(v *refs.ObjectID) { - m.Link = v -} - -// FromString parses ObjectType from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *ObjectType) FromString(s string) bool { - i, ok := ObjectType_value[s] - if ok { - *x = ObjectType(i) - } - - return ok -} - -// FromString parses MatchType from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *MatchType) FromString(s string) bool { - i, ok := MatchType_value[s] - if ok { - *x = MatchType(i) - } - - return ok -} diff --git a/object/grpc/types.pb.go b/object/grpc/types.pb.go deleted file mode 100644 index 2a5a2f9..0000000 Binary files a/object/grpc/types.pb.go and /dev/null differ diff --git a/object/grpc/types_frostfs.pb.go b/object/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..492ee48 Binary files /dev/null and b/object/grpc/types_frostfs.pb.go differ diff --git a/object/grpc/types_frostfs_fuzz.go b/object/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..8491638 --- /dev/null +++ b/object/grpc/types_frostfs_fuzz.go @@ -0,0 +1,102 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package object + +func DoFuzzProtoShortHeader(data []byte) int { + msg := new(ShortHeader) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONShortHeader(data []byte) int { + msg := new(ShortHeader) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoHeader(data []byte) int { + msg := new(Header) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONHeader(data []byte) int { + msg := new(Header) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoObject(data []byte) int { + msg := new(Object) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONObject(data []byte) int { + msg := new(Object) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoSplitInfo(data []byte) int { + msg := new(SplitInfo) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONSplitInfo(data []byte) int { + msg := new(SplitInfo) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoECInfo(data []byte) int { + msg := new(ECInfo) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONECInfo(data []byte) int { + msg := new(ECInfo) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/object/grpc/types_frostfs_test.go b/object/grpc/types_frostfs_test.go new file mode 100644 index 0000000..11825be --- /dev/null +++ b/object/grpc/types_frostfs_test.go @@ -0,0 +1,61 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package object + +import ( + testing "testing" +) + +func FuzzProtoShortHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoShortHeader(data) + }) +} +func FuzzJSONShortHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONShortHeader(data) + }) +} +func FuzzProtoHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoHeader(data) + }) +} +func FuzzJSONHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONHeader(data) + }) +} +func FuzzProtoObject(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoObject(data) + }) +} +func FuzzJSONObject(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONObject(data) + }) +} +func FuzzProtoSplitInfo(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoSplitInfo(data) + }) +} +func FuzzJSONSplitInfo(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONSplitInfo(data) + }) +} +func FuzzProtoECInfo(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoECInfo(data) + }) +} +func FuzzJSONECInfo(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONECInfo(data) + }) +} diff --git a/refs/grpc/types.go b/refs/grpc/types.go deleted file mode 100644 index cdb69aa..0000000 --- a/refs/grpc/types.go +++ /dev/null @@ -1,97 +0,0 @@ -package refs - -// SetValue sets container identifier in a binary format. -func (x *ContainerID) SetValue(v []byte) { - x.Value = v -} - -// SetValue sets object identifier in a binary format. -func (x *ObjectID) SetValue(v []byte) { - x.Value = v -} - -// SetValue sets owner identifier in a binary format. -func (x *OwnerID) SetValue(v []byte) { - x.Value = v -} - -// SetContainerId sets container identifier of the address. -func (x *Address) SetContainerId(v *ContainerID) { - x.ContainerId = v -} - -// SetObjectId sets object identifier of the address. -func (x *Address) SetObjectId(v *ObjectID) { - x.ObjectId = v -} - -// SetType in generic checksum structure. -func (x *Checksum) SetType(v ChecksumType) { - x.Type = v -} - -// SetSum in generic checksum structure. -func (x *Checksum) SetSum(v []byte) { - x.Sum = v -} - -// SetMajor sets major version number. -func (x *Version) SetMajor(v uint32) { - x.Major = v -} - -// SetMinor sets minor version number. -func (x *Version) SetMinor(v uint32) { - x.Minor = v -} - -// SetKey sets public key in a binary format. -func (x *Signature) SetKey(v []byte) { - x.Key = v -} - -// SetSign sets signature. -func (x *Signature) SetSign(v []byte) { - x.Sign = v -} - -// SetScheme sets signature scheme. -func (x *Signature) SetScheme(s SignatureScheme) { - x.Scheme = s -} - -// SetKey sets public key in a binary format. -func (x *SignatureRFC6979) SetKey(v []byte) { - x.Key = v -} - -// SetSign sets signature. -func (x *SignatureRFC6979) SetSign(v []byte) { - x.Sign = v -} - -// FromString parses SignatureScheme from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *SignatureScheme) FromString(s string) bool { - i, ok := SignatureScheme_value[s] - if ok { - *x = SignatureScheme(i) - } - - return ok -} - -// FromString parses ChecksumType from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *ChecksumType) FromString(s string) bool { - i, ok := ChecksumType_value[s] - if ok { - *x = ChecksumType(i) - } - - return ok -} diff --git a/refs/grpc/types.pb.go b/refs/grpc/types.pb.go deleted file mode 100644 index ab3ae42..0000000 Binary files a/refs/grpc/types.pb.go and /dev/null differ diff --git a/refs/grpc/types_frostfs.pb.go b/refs/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..881a06f Binary files /dev/null and b/refs/grpc/types_frostfs.pb.go differ diff --git a/refs/grpc/types_frostfs_fuzz.go b/refs/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..a64a9bf --- /dev/null +++ b/refs/grpc/types_frostfs_fuzz.go @@ -0,0 +1,159 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package refs + +func DoFuzzProtoAddress(data []byte) int { + msg := new(Address) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONAddress(data []byte) int { + msg := new(Address) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoObjectID(data []byte) int { + msg := new(ObjectID) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONObjectID(data []byte) int { + msg := new(ObjectID) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoContainerID(data []byte) int { + msg := new(ContainerID) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONContainerID(data []byte) int { + msg := new(ContainerID) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoOwnerID(data []byte) int { + msg := new(OwnerID) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONOwnerID(data []byte) int { + msg := new(OwnerID) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoVersion(data []byte) int { + msg := new(Version) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONVersion(data []byte) int { + msg := new(Version) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoSignature(data []byte) int { + msg := new(Signature) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONSignature(data []byte) int { + msg := new(Signature) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoSignatureRFC6979(data []byte) int { + msg := new(SignatureRFC6979) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONSignatureRFC6979(data []byte) int { + msg := new(SignatureRFC6979) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoChecksum(data []byte) int { + msg := new(Checksum) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONChecksum(data []byte) int { + msg := new(Checksum) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/refs/grpc/types_frostfs_test.go b/refs/grpc/types_frostfs_test.go new file mode 100644 index 0000000..9b19892 --- /dev/null +++ b/refs/grpc/types_frostfs_test.go @@ -0,0 +1,91 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package refs + +import ( + testing "testing" +) + +func FuzzProtoAddress(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoAddress(data) + }) +} +func FuzzJSONAddress(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONAddress(data) + }) +} +func FuzzProtoObjectID(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoObjectID(data) + }) +} +func FuzzJSONObjectID(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONObjectID(data) + }) +} +func FuzzProtoContainerID(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoContainerID(data) + }) +} +func FuzzJSONContainerID(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONContainerID(data) + }) +} +func FuzzProtoOwnerID(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoOwnerID(data) + }) +} +func FuzzJSONOwnerID(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONOwnerID(data) + }) +} +func FuzzProtoVersion(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoVersion(data) + }) +} +func FuzzJSONVersion(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONVersion(data) + }) +} +func FuzzProtoSignature(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoSignature(data) + }) +} +func FuzzJSONSignature(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONSignature(data) + }) +} +func FuzzProtoSignatureRFC6979(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoSignatureRFC6979(data) + }) +} +func FuzzJSONSignatureRFC6979(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONSignatureRFC6979(data) + }) +} +func FuzzProtoChecksum(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoChecksum(data) + }) +} +func FuzzJSONChecksum(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONChecksum(data) + }) +} diff --git a/rpc/client/client.go b/rpc/client/client.go index 7e914db..d9ce2fc 100644 --- a/rpc/client/client.go +++ b/rpc/client/client.go @@ -1,6 +1,7 @@ package client import ( + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/encoding" "google.golang.org/grpc" "google.golang.org/grpc/credentials" ) @@ -20,6 +21,7 @@ func New(opts ...Option) *Client { opt(&c.cfg) } + c.grpcDialOpts = append(c.grpcDialOpts, grpc.WithDefaultCallOptions(grpc.ForceCodec(encoding.ProtoCodec{}))) if c.tlsCfg != nil { c.grpcDialOpts = append(c.grpcDialOpts, grpc.WithTransportCredentials(credentials.NewTLS(c.tlsCfg))) } diff --git a/rpc/message/encoding.go b/rpc/message/encoding.go index 715f015..d656acd 100644 --- a/rpc/message/encoding.go +++ b/rpc/message/encoding.go @@ -1,17 +1,14 @@ package message import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/proto" + "encoding/json" ) // GRPCConvertedMessage is an interface // of the gRPC message that is used // for Message encoding/decoding. type GRPCConvertedMessage interface { - grpc.Message - proto.Message + UnmarshalProtobuf([]byte) error } // Unmarshal decodes m from its Protobuf binary representation @@ -19,7 +16,7 @@ type GRPCConvertedMessage interface { // // gm should be tof the same type as the m.ToGRPCMessage() return. func Unmarshal(m Message, data []byte, gm GRPCConvertedMessage) error { - if err := proto.Unmarshal(data, gm); err != nil { + if err := gm.UnmarshalProtobuf(data); err != nil { return err } @@ -28,21 +25,16 @@ func Unmarshal(m Message, data []byte, gm GRPCConvertedMessage) error { // MarshalJSON encodes m to Protobuf JSON representation. func MarshalJSON(m Message) ([]byte, error) { - return protojson.MarshalOptions{ - EmitUnpopulated: true, - }.Marshal( - m.ToGRPCMessage().(proto.Message), - ) + return json.Marshal(m.ToGRPCMessage()) } // UnmarshalJSON decodes m from its Protobuf JSON representation // via related gRPC message. // // gm should be tof the same type as the m.ToGRPCMessage() return. -func UnmarshalJSON(m Message, data []byte, gm GRPCConvertedMessage) error { - if err := protojson.Unmarshal(data, gm); err != nil { +func UnmarshalJSON(m Message, data []byte, gm any) error { + if err := json.Unmarshal(data, gm); err != nil { return err } - return m.FromGRPCMessage(gm) } diff --git a/rpc/netmap.go b/rpc/netmap.go index 38bdd6d..8119477 100644 --- a/rpc/netmap.go +++ b/rpc/netmap.go @@ -37,7 +37,6 @@ func NetworkInfo( opts ...client.CallOption, ) (*netmap.NetworkInfoResponse, error) { resp := new(netmap.NetworkInfoResponse) - err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceNetmap, rpcNetmapNetInfo), req, resp, opts...) if err != nil { return nil, err diff --git a/session/convert.go b/session/convert.go index 4197935..b7f334e 100644 --- a/session/convert.go +++ b/session/convert.go @@ -460,7 +460,7 @@ func (r *RequestMetaHeader) FromGRPCMessage(m grpc.Message) error { r.epoch = v.GetEpoch() r.ttl = v.GetTtl() - r.netMagic = v.GetNetworkMagic() + r.netMagic = v.GetMagicNumber() return nil } diff --git a/session/grpc/service.go b/session/grpc/service.go deleted file mode 100644 index 6e02328..0000000 --- a/session/grpc/service.go +++ /dev/null @@ -1,55 +0,0 @@ -package session - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" -) - -// SetOwnerId sets identifier of the session initiator. -func (m *CreateRequest_Body) SetOwnerId(v *refs.OwnerID) { - m.OwnerId = v -} - -// SetExpiration sets lifetime of the session. -func (m *CreateRequest_Body) SetExpiration(v uint64) { - m.Expiration = v -} - -// SetBody sets body of the request. -func (m *CreateRequest) SetBody(v *CreateRequest_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the request. -func (m *CreateRequest) SetMetaHeader(v *RequestMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the request. -func (m *CreateRequest) SetVerifyHeader(v *RequestVerificationHeader) { - m.VerifyHeader = v -} - -// SetId sets identifier of the session token. -func (m *CreateResponse_Body) SetId(v []byte) { - m.Id = v -} - -// SetSessionKey sets session public key in a binary format. -func (m *CreateResponse_Body) SetSessionKey(v []byte) { - m.SessionKey = v -} - -// SetBody sets body of the response. -func (m *CreateResponse) SetBody(v *CreateResponse_Body) { - m.Body = v -} - -// SetMetaHeader sets meta header of the response. -func (m *CreateResponse) SetMetaHeader(v *ResponseMetaHeader) { - m.MetaHeader = v -} - -// SetVerifyHeader sets verification header of the response. -func (m *CreateResponse) SetVerifyHeader(v *ResponseVerificationHeader) { - m.VerifyHeader = v -} diff --git a/session/grpc/service.pb.go b/session/grpc/service.pb.go deleted file mode 100644 index b5e999f..0000000 Binary files a/session/grpc/service.pb.go and /dev/null differ diff --git a/session/grpc/service_frostfs.pb.go b/session/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..cfec4d6 Binary files /dev/null and b/session/grpc/service_frostfs.pb.go differ diff --git a/session/grpc/service_frostfs_fuzz.go b/session/grpc/service_frostfs_fuzz.go new file mode 100644 index 0000000..759361c --- /dev/null +++ b/session/grpc/service_frostfs_fuzz.go @@ -0,0 +1,45 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package session + +func DoFuzzProtoCreateRequest(data []byte) int { + msg := new(CreateRequest) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONCreateRequest(data []byte) int { + msg := new(CreateRequest) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoCreateResponse(data []byte) int { + msg := new(CreateResponse) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONCreateResponse(data []byte) int { + msg := new(CreateResponse) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/session/grpc/service_frostfs_test.go b/session/grpc/service_frostfs_test.go new file mode 100644 index 0000000..fc8664e --- /dev/null +++ b/session/grpc/service_frostfs_test.go @@ -0,0 +1,31 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package session + +import ( + testing "testing" +) + +func FuzzProtoCreateRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoCreateRequest(data) + }) +} +func FuzzJSONCreateRequest(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONCreateRequest(data) + }) +} +func FuzzProtoCreateResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoCreateResponse(data) + }) +} +func FuzzJSONCreateResponse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONCreateResponse(data) + }) +} diff --git a/session/grpc/types.go b/session/grpc/types.go deleted file mode 100644 index 857c45e..0000000 --- a/session/grpc/types.go +++ /dev/null @@ -1,246 +0,0 @@ -package session - -import ( - acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - status "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc" -) - -// SetKey sets key to the X-Header. -func (m *XHeader) SetKey(v string) { - m.Key = v -} - -// SetValue sets value of the X-Header. -func (m *XHeader) SetValue(v string) { - m.Value = v -} - -// SetExp sets epoch number of the token expiration. -func (m *SessionToken_Body_TokenLifetime) SetExp(v uint64) { - m.Exp = v -} - -// SetNbf sets starting epoch number of the token. -func (m *SessionToken_Body_TokenLifetime) SetNbf(v uint64) { - m.Nbf = v -} - -// SetIat sets the number of the epoch in which the token was issued. -func (m *SessionToken_Body_TokenLifetime) SetIat(v uint64) { - m.Iat = v -} - -// SetId sets identifier of the session token. -func (m *SessionToken_Body) SetId(v []byte) { - m.Id = v -} - -// SetOwnerId sets identifier of the session token owner. -func (m *SessionToken_Body) SetOwnerId(v *refs.OwnerID) { - m.OwnerId = v -} - -// SetLifetime sets lifetime of the session token. -func (m *SessionToken_Body) SetLifetime(v *SessionToken_Body_TokenLifetime) { - m.Lifetime = v -} - -// SetSessionKey sets public session key in a binary format. -func (m *SessionToken_Body) SetSessionKey(v []byte) { - m.SessionKey = v -} - -// SetObjectAddressContext sets object context of the session token. -func (m *SessionToken_Body) SetObject(v *ObjectSessionContext) { - m.Context = &SessionToken_Body_Object{ - Object: v, - } -} - -// SetContainer sets container context of the session token. -func (m *SessionToken_Body) SetContainer(v *ContainerSessionContext) { - m.Context = &SessionToken_Body_Container{ - Container: v, - } -} - -// SetTarget specifies objects involved in the object session. -func (m *ObjectSessionContext) SetTarget(tgt *ObjectSessionContext_Target) { - m.Target = tgt -} - -// SetVerb sets type of request for which the token is issued. -func (m *ObjectSessionContext) SetVerb(v ObjectSessionContext_Verb) { - m.Verb = v -} - -// SetVerb sets type of request for which the token is issued. -func (x *ContainerSessionContext) SetVerb(v ContainerSessionContext_Verb) { - x.Verb = v -} - -// SetWildcard sets wildcard flag of the container session. -func (x *ContainerSessionContext) SetWildcard(v bool) { - x.Wildcard = v -} - -// SetContainerId sets identifier of the container related to the session. -func (x *ContainerSessionContext) SetContainerId(v *refs.ContainerID) { - x.ContainerId = v -} - -// SetBody sets session token body. -func (m *SessionToken) SetBody(v *SessionToken_Body) { - m.Body = v -} - -// SetSignature sets session token signature. -func (m *SessionToken) SetSignature(v *refs.Signature) { - m.Signature = v -} - -// SetVersion sets client protocol version. -func (m *RequestMetaHeader) SetVersion(v *refs.Version) { - m.Version = v -} - -// SetEpoch sets client local epoch. -func (m *RequestMetaHeader) SetEpoch(v uint64) { - m.Epoch = v -} - -// SetTtl sets request TTL. -func (m *RequestMetaHeader) SetTtl(v uint32) { - m.Ttl = v -} - -// SetXHeaders sets request X-Headers. -func (m *RequestMetaHeader) SetXHeaders(v []*XHeader) { - m.XHeaders = v -} - -// SetSessionToken sets session token of the request. -func (m *RequestMetaHeader) SetSessionToken(v *SessionToken) { - m.SessionToken = v -} - -// SetBearerToken sets bearer token of the request. -func (m *RequestMetaHeader) SetBearerToken(v *acl.BearerToken) { - m.BearerToken = v -} - -// SetOrigin sets origin request meta header. -func (m *RequestMetaHeader) SetOrigin(v *RequestMetaHeader) { - m.Origin = v -} - -// GetNetworkMagic returns NeoFS network magic. -func (m *RequestMetaHeader) GetNetworkMagic() uint64 { - if m != nil { - return m.MagicNumber - } - - return 0 -} - -// SetMagicNumber sets NeoFS network magic. -func (m *RequestMetaHeader) SetMagicNumber(v uint64) { - m.MagicNumber = v -} - -// SetVersion sets server protocol version. -func (m *ResponseMetaHeader) SetVersion(v *refs.Version) { - m.Version = v -} - -// SetEpoch sets server local epoch. -func (m *ResponseMetaHeader) SetEpoch(v uint64) { - m.Epoch = v -} - -// SetTtl sets response TTL. -func (m *ResponseMetaHeader) SetTtl(v uint32) { - m.Ttl = v -} - -// SetXHeaders sets response X-Headers. -func (m *ResponseMetaHeader) SetXHeaders(v []*XHeader) { - m.XHeaders = v -} - -// SetOrigin sets origin response meta header. -func (m *ResponseMetaHeader) SetOrigin(v *ResponseMetaHeader) { - m.Origin = v -} - -// SetStatus sets response status. -func (m *ResponseMetaHeader) SetStatus(v *status.Status) { - m.Status = v -} - -// SetBodySignature sets signature of the request body. -func (m *RequestVerificationHeader) SetBodySignature(v *refs.Signature) { - m.BodySignature = v -} - -// SetMetaSignature sets signature of the request meta. -func (m *RequestVerificationHeader) SetMetaSignature(v *refs.Signature) { - m.MetaSignature = v -} - -// SetOriginSignature sets signature of the origin verification header of the request. -func (m *RequestVerificationHeader) SetOriginSignature(v *refs.Signature) { - m.OriginSignature = v -} - -// SetOrigin sets origin verification header of the request. -func (m *RequestVerificationHeader) SetOrigin(v *RequestVerificationHeader) { - m.Origin = v -} - -// SetBodySignature sets signature of the response body. -func (m *ResponseVerificationHeader) SetBodySignature(v *refs.Signature) { - m.BodySignature = v -} - -// SetMetaSignature sets signature of the response meta. -func (m *ResponseVerificationHeader) SetMetaSignature(v *refs.Signature) { - m.MetaSignature = v -} - -// SetOriginSignature sets signature of the origin verification header of the response. -func (m *ResponseVerificationHeader) SetOriginSignature(v *refs.Signature) { - m.OriginSignature = v -} - -// SetOrigin sets origin verification header of the response. -func (m *ResponseVerificationHeader) SetOrigin(v *ResponseVerificationHeader) { - m.Origin = v -} - -// FromString parses ObjectSessionContext_Verb from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *ObjectSessionContext_Verb) FromString(s string) bool { - i, ok := ObjectSessionContext_Verb_value[s] - if ok { - *x = ObjectSessionContext_Verb(i) - } - - return ok -} - -// FromString parses ContainerSessionContext_Verb from a string representation, -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *ContainerSessionContext_Verb) FromString(s string) bool { - i, ok := ContainerSessionContext_Verb_value[s] - if ok { - *x = ContainerSessionContext_Verb(i) - } - - return ok -} diff --git a/session/grpc/types.pb.go b/session/grpc/types.pb.go deleted file mode 100644 index 9f51743..0000000 Binary files a/session/grpc/types.pb.go and /dev/null differ diff --git a/session/grpc/types_frostfs.pb.go b/session/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..6a0d75c Binary files /dev/null and b/session/grpc/types_frostfs.pb.go differ diff --git a/session/grpc/types_frostfs_fuzz.go b/session/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..fae4a05 --- /dev/null +++ b/session/grpc/types_frostfs_fuzz.go @@ -0,0 +1,159 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package session + +func DoFuzzProtoObjectSessionContext(data []byte) int { + msg := new(ObjectSessionContext) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONObjectSessionContext(data []byte) int { + msg := new(ObjectSessionContext) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoContainerSessionContext(data []byte) int { + msg := new(ContainerSessionContext) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONContainerSessionContext(data []byte) int { + msg := new(ContainerSessionContext) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoSessionToken(data []byte) int { + msg := new(SessionToken) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONSessionToken(data []byte) int { + msg := new(SessionToken) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoXHeader(data []byte) int { + msg := new(XHeader) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONXHeader(data []byte) int { + msg := new(XHeader) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoRequestMetaHeader(data []byte) int { + msg := new(RequestMetaHeader) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONRequestMetaHeader(data []byte) int { + msg := new(RequestMetaHeader) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoResponseMetaHeader(data []byte) int { + msg := new(ResponseMetaHeader) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONResponseMetaHeader(data []byte) int { + msg := new(ResponseMetaHeader) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoRequestVerificationHeader(data []byte) int { + msg := new(RequestVerificationHeader) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONRequestVerificationHeader(data []byte) int { + msg := new(RequestVerificationHeader) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} +func DoFuzzProtoResponseVerificationHeader(data []byte) int { + msg := new(ResponseVerificationHeader) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONResponseVerificationHeader(data []byte) int { + msg := new(ResponseVerificationHeader) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/session/grpc/types_frostfs_test.go b/session/grpc/types_frostfs_test.go new file mode 100644 index 0000000..5c9b6c2 --- /dev/null +++ b/session/grpc/types_frostfs_test.go @@ -0,0 +1,91 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package session + +import ( + testing "testing" +) + +func FuzzProtoObjectSessionContext(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoObjectSessionContext(data) + }) +} +func FuzzJSONObjectSessionContext(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONObjectSessionContext(data) + }) +} +func FuzzProtoContainerSessionContext(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoContainerSessionContext(data) + }) +} +func FuzzJSONContainerSessionContext(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONContainerSessionContext(data) + }) +} +func FuzzProtoSessionToken(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoSessionToken(data) + }) +} +func FuzzJSONSessionToken(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONSessionToken(data) + }) +} +func FuzzProtoXHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoXHeader(data) + }) +} +func FuzzJSONXHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONXHeader(data) + }) +} +func FuzzProtoRequestMetaHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoRequestMetaHeader(data) + }) +} +func FuzzJSONRequestMetaHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONRequestMetaHeader(data) + }) +} +func FuzzProtoResponseMetaHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoResponseMetaHeader(data) + }) +} +func FuzzJSONResponseMetaHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONResponseMetaHeader(data) + }) +} +func FuzzProtoRequestVerificationHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoRequestVerificationHeader(data) + }) +} +func FuzzJSONRequestVerificationHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONRequestVerificationHeader(data) + }) +} +func FuzzProtoResponseVerificationHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoResponseVerificationHeader(data) + }) +} +func FuzzJSONResponseVerificationHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONResponseVerificationHeader(data) + }) +} diff --git a/status/grpc/types.go b/status/grpc/types.go deleted file mode 100644 index 993f632..0000000 --- a/status/grpc/types.go +++ /dev/null @@ -1,26 +0,0 @@ -package status - -// SetId sets identifier of the Status_Detail. -func (x *Status_Detail) SetId(v uint32) { - x.Id = v -} - -// SetValue sets value of the Status_Detail. -func (x *Status_Detail) SetValue(v []byte) { - x.Value = v -} - -// SetCode sets code of the Status. -func (x *Status) SetCode(v uint32) { - x.Code = v -} - -// SetMessage sets message about the Status. -func (x *Status) SetMessage(v string) { - x.Message = v -} - -// SetDetails sets details of the Status. -func (x *Status) SetDetails(v []*Status_Detail) { - x.Details = v -} diff --git a/status/grpc/types.pb.go b/status/grpc/types.pb.go deleted file mode 100644 index b6b081b..0000000 Binary files a/status/grpc/types.pb.go and /dev/null differ diff --git a/status/grpc/types_frostfs.pb.go b/status/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..a12ab55 Binary files /dev/null and b/status/grpc/types_frostfs.pb.go differ diff --git a/status/grpc/types_frostfs_fuzz.go b/status/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..ce9d84e --- /dev/null +++ b/status/grpc/types_frostfs_fuzz.go @@ -0,0 +1,26 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package status + +func DoFuzzProtoStatus(data []byte) int { + msg := new(Status) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONStatus(data []byte) int { + msg := new(Status) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/status/grpc/types_frostfs_test.go b/status/grpc/types_frostfs_test.go new file mode 100644 index 0000000..dfc5631 --- /dev/null +++ b/status/grpc/types_frostfs_test.go @@ -0,0 +1,21 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package status + +import ( + testing "testing" +) + +func FuzzProtoStatus(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoStatus(data) + }) +} +func FuzzJSONStatus(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONStatus(data) + }) +} diff --git a/tombstone/grpc/types.go b/tombstone/grpc/types.go deleted file mode 100644 index 9b4b744..0000000 --- a/tombstone/grpc/types.go +++ /dev/null @@ -1,20 +0,0 @@ -package tombstone - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" -) - -// SetExpirationEpoch sets number of tombstone expiration epoch. -func (x *Tombstone) SetExpirationEpoch(v uint64) { - x.ExpirationEpoch = v -} - -// SetSplitId sets identifier of split object hierarchy. -func (x *Tombstone) SetSplitId(v []byte) { - x.SplitId = v -} - -// SetMembers sets list of objects to be deleted. -func (x *Tombstone) SetMembers(v []*refs.ObjectID) { - x.Members = v -} diff --git a/tombstone/grpc/types.pb.go b/tombstone/grpc/types.pb.go deleted file mode 100644 index 7d416fe..0000000 Binary files a/tombstone/grpc/types.pb.go and /dev/null differ diff --git a/tombstone/grpc/types_frostfs.pb.go b/tombstone/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..b0924c0 Binary files /dev/null and b/tombstone/grpc/types_frostfs.pb.go differ diff --git a/tombstone/grpc/types_frostfs_fuzz.go b/tombstone/grpc/types_frostfs_fuzz.go new file mode 100644 index 0000000..57cfb58 --- /dev/null +++ b/tombstone/grpc/types_frostfs_fuzz.go @@ -0,0 +1,26 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package tombstone + +func DoFuzzProtoTombstone(data []byte) int { + msg := new(Tombstone) + if err := msg.UnmarshalProtobuf(data); err != nil { + return 0 + } + _ = msg.MarshalProtobuf(nil) + return 1 +} +func DoFuzzJSONTombstone(data []byte) int { + msg := new(Tombstone) + if err := msg.UnmarshalJSON(data); err != nil { + return 0 + } + _, err := msg.MarshalJSON() + if err != nil { + panic(err) + } + return 1 +} diff --git a/tombstone/grpc/types_frostfs_test.go b/tombstone/grpc/types_frostfs_test.go new file mode 100644 index 0000000..8264824 --- /dev/null +++ b/tombstone/grpc/types_frostfs_test.go @@ -0,0 +1,21 @@ +//go:build gofuzz +// +build gofuzz + +// Code generated by protoc-gen-go-frostfs. DO NOT EDIT. + +package tombstone + +import ( + testing "testing" +) + +func FuzzProtoTombstone(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzProtoTombstone(data) + }) +} +func FuzzJSONTombstone(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzJSONTombstone(data) + }) +} diff --git a/util/pool/marshal.go b/util/pool/marshal.go new file mode 100644 index 0000000..107df28 --- /dev/null +++ b/util/pool/marshal.go @@ -0,0 +1,7 @@ +package pool + +import ( + "github.com/VictoriaMetrics/easyproto" +) + +var MarshalerPool easyproto.MarshalerPool diff --git a/util/proto/encoding/compat.go b/util/proto/encoding/compat.go new file mode 100644 index 0000000..09d45e6 --- /dev/null +++ b/util/proto/encoding/compat.go @@ -0,0 +1,22 @@ +package encoding + +import ( + _ "google.golang.org/grpc/encoding/proto" // Ensure default codec is registered before our one. + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/protoadapt" +) + +// messageV2Of converts v to a proto.Message. +// This is needed for this library to continue working in presence of external gRPC packages, +// such as opentelemetry gRPC exporter. +// Copied from https://github.com/grpc/grpc-go/blob/e524655becd8d4c7ba9e8687faef456e495e341e/encoding/proto/proto.go#L59. +func messageV2Of(v any) proto.Message { + switch v := v.(type) { + case protoadapt.MessageV1: + return protoadapt.MessageV2Of(v) + case protoadapt.MessageV2: + return v + } + + return nil +} diff --git a/util/proto/encoding/json.go b/util/proto/encoding/json.go new file mode 100644 index 0000000..3456a40 --- /dev/null +++ b/util/proto/encoding/json.go @@ -0,0 +1,48 @@ +package encoding + +import ( + "encoding/json" + "fmt" + + "google.golang.org/grpc/encoding" + "google.golang.org/protobuf/encoding/protojson" +) + +// JSONCodec is easyjson codec used for code generated by protogen. +// It is binary-level compatible with the standard protojson format, thus uses the same name. +type JSONCodec struct{} + +var _ encoding.Codec = JSONCodec{} + +func init() { + encoding.RegisterCodec(JSONCodec{}) +} + +// Name implements the encoding.Codec interface. +func (JSONCodec) Name() string { return "json" } + +// Marshal implements the encoding.Codec interface. +func (JSONCodec) Marshal(v any) ([]byte, error) { + switch v := v.(type) { + case json.Marshaler: + return json.Marshal(v) + default: + if v := messageV2Of(v); v != nil { + return protojson.Marshal(v) + } + return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v) + } +} + +// Unmarshal implements the encoding.Codec interface. +func (JSONCodec) Unmarshal(data []byte, v any) error { + switch v := v.(type) { + case json.Unmarshaler: + return json.Unmarshal(data, v) + default: + if v := messageV2Of(v); v != nil { + return protojson.Unmarshal(data, v) + } + return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v) + } +} diff --git a/util/proto/encoding/proto.go b/util/proto/encoding/proto.go new file mode 100644 index 0000000..5f3c556 --- /dev/null +++ b/util/proto/encoding/proto.go @@ -0,0 +1,57 @@ +package encoding + +import ( + "fmt" + + "google.golang.org/grpc/encoding" + "google.golang.org/protobuf/proto" +) + +// ProtoCodec is easyproto codec used for code generated by protogen. +// It is binary-level compatible with the standard proto codec, thus uses the same name. +type ProtoCodec struct{} + +// ProtoMarshaler is an interface accepted by ProtoCodec.Marshal. +type ProtoMarshaler interface { + MarshalProtobuf([]byte) []byte +} + +// ProtoUnmarshaler is an interface accepted by ProtoCodec.Unmarshal. +type ProtoUnmarshaler interface { + UnmarshalProtobuf([]byte) error +} + +var _ encoding.Codec = ProtoCodec{} + +func init() { + encoding.RegisterCodec(ProtoCodec{}) +} + +// Name implements the encoding.Codec interface. +func (ProtoCodec) Name() string { return "proto" } + +// Marshal implements the encoding.Codec interface. +func (ProtoCodec) Marshal(v any) ([]byte, error) { + switch v := v.(type) { + case ProtoMarshaler: + return v.MarshalProtobuf(nil), nil + default: + if v := messageV2Of(v); v != nil { + return proto.Marshal(v) + } + return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v) + } +} + +// Unmarshal implements the encoding.Codec interface. +func (ProtoCodec) Unmarshal(data []byte, v any) error { + switch v := v.(type) { + case ProtoUnmarshaler: + return v.UnmarshalProtobuf(data) + default: + if v := messageV2Of(v); v != nil { + return proto.Unmarshal(data, v) + } + return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v) + } +} diff --git a/util/proto/marshal.go b/util/proto/marshal.go index 42c6a91..5016255 100644 --- a/util/proto/marshal.go +++ b/util/proto/marshal.go @@ -17,6 +17,10 @@ import ( type ( stableMarshaler interface { StableMarshal([]byte) []byte + stableSizer + } + + stableSizer interface { StableSize() int } @@ -277,6 +281,11 @@ type ptrStableMarshaler[T any] interface { ~*T } +type ptrStableSizer[T any] interface { + stableSizer + ~*T +} + func NestedStructureMarshal[T any, M ptrStableMarshaler[T]](field int64, buf []byte, v M) int { if v == nil { return 0 @@ -320,7 +329,7 @@ func NestedStructureSetMarshalData[T any, M setMarshalData[T]](field int64, pare return offset + n } -func NestedStructureSize[T any, M ptrStableMarshaler[T]](field int64, v M) (size int) { +func NestedStructureSize[T any, M ptrStableSizer[T]](field int64, v M) (size int) { if v == nil { return 0 } @@ -328,7 +337,7 @@ func NestedStructureSize[T any, M ptrStableMarshaler[T]](field int64, v M) (size return NestedStructureSizeUnchecked(field, v) } -func NestedStructureSizeUnchecked[T stableMarshaler](field int64, v T) int { +func NestedStructureSizeUnchecked[T stableSizer](field int64, v T) int { n := v.StableSize() return protowire.SizeGroup(protowire.Number(field), protowire.SizeBytes(n)) } diff --git a/util/proto/marshal_test.go b/util/proto/marshal_test.go index 56d9594..e565b7c 100644 --- a/util/proto/marshal_test.go +++ b/util/proto/marshal_test.go @@ -6,6 +6,7 @@ import ( "testing" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/test" + generated "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/test/custom" "github.com/stretchr/testify/require" goproto "google.golang.org/protobuf/proto" ) @@ -24,39 +25,43 @@ func nonZero[T protoInt]() T { func TestStableMarshalSingle(t *testing.T) { t.Run("empty", func(t *testing.T) { - input := &test.Primitives{} + input := &generated.Primitives{} require.Zero(t, input.StableSize()) - r := input.StableMarshal(nil) + r := input.MarshalProtobuf(nil) require.Empty(t, r) }) marshalCases := []struct { name string - input *test.Primitives + input *generated.Primitives }{ - {name: "bytes", input: &test.Primitives{FieldA: []byte{1, 2, 3}}}, - {name: "string", input: &test.Primitives{FieldB: "123"}}, - {name: "bool", input: &test.Primitives{FieldC: true}}, - {name: "int32", input: &test.Primitives{FieldD: nonZero[int32]()}}, - {name: "uint32", input: &test.Primitives{FieldE: nonZero[uint32]()}}, - {name: "int64", input: &test.Primitives{FieldF: nonZero[int64]()}}, - {name: "uint64", input: &test.Primitives{FieldG: nonZero[uint64]()}}, - {name: "uint64", input: &test.Primitives{FieldI: nonZero[uint64]()}}, - {name: "float64", input: &test.Primitives{FieldJ: math.Float64frombits(12345677890)}}, - {name: "fixed32", input: &test.Primitives{FieldK: nonZero[uint32]()}}, - {name: "enum, positive", input: &test.Primitives{FieldH: test.Primitives_POSITIVE}}, - {name: "enum, negative", input: &test.Primitives{FieldH: test.Primitives_NEGATIVE}}, + {name: "bytes", input: &generated.Primitives{FieldA: []byte{1, 2, 3}}}, + {name: "string", input: &generated.Primitives{FieldB: "123"}}, + {name: "bool", input: &generated.Primitives{FieldC: true}}, + {name: "int32", input: &generated.Primitives{FieldD: -10}}, + {name: "uint32", input: &generated.Primitives{FieldE: nonZero[uint32]()}}, + {name: "int64", input: &generated.Primitives{FieldF: nonZero[int64]()}}, + {name: "uint64", input: &generated.Primitives{FieldG: nonZero[uint64]()}}, + {name: "uint64", input: &generated.Primitives{FieldI: nonZero[uint64]()}}, + {name: "float64", input: &generated.Primitives{FieldJ: math.Float64frombits(12345677890)}}, + {name: "fixed32", input: &generated.Primitives{FieldK: nonZero[uint32]()}}, + {name: "enum, positive", input: &generated.Primitives{FieldH: generated.Primitives_POSITIVE}}, + {name: "enum, negative", input: &generated.Primitives{FieldH: generated.Primitives_NEGATIVE}}, } for _, tc := range marshalCases { t.Run(tc.name, func(t *testing.T) { - r := tc.input.StableMarshal(nil) + r := tc.input.MarshalProtobuf(nil) require.Equal(t, len(r), tc.input.StableSize()) require.NotEmpty(t, r) var actual test.Primitives require.NoError(t, goproto.Unmarshal(r, &actual)) + var actualFrostfs generated.Primitives + require.NoError(t, actualFrostfs.UnmarshalProtobuf(r)) + require.Equal(t, tc.input, &actualFrostfs) + // Compare each field directly, because proto-generated code has private fields. require.Equal(t, tc.input.FieldA, actual.FieldA) require.Equal(t, tc.input.FieldB, actual.FieldB) @@ -68,7 +73,7 @@ func TestStableMarshalSingle(t *testing.T) { require.Equal(t, tc.input.FieldI, actual.FieldI) require.Equal(t, tc.input.FieldJ, actual.FieldJ) require.Equal(t, tc.input.FieldK, actual.FieldK) - require.Equal(t, tc.input.FieldH, actual.FieldH) + require.EqualValues(t, tc.input.FieldH, actual.FieldH) }) } } @@ -91,51 +96,53 @@ func TestStableMarshalRep(t *testing.T) { t.Run("empty", func(t *testing.T) { marshalCases := []struct { name string - input *test.RepPrimitives + input *generated.RepPrimitives }{ - {name: "default", input: &test.RepPrimitives{}}, - {name: "bytes", input: &test.RepPrimitives{FieldA: [][]byte{}}}, - {name: "string", input: &test.RepPrimitives{FieldB: []string{}}}, - {name: "int32", input: &test.RepPrimitives{FieldC: []int32{}}}, - {name: "uint32", input: &test.RepPrimitives{FieldD: []uint32{}}}, - {name: "int64", input: &test.RepPrimitives{FieldE: []int64{}}}, - {name: "uint64", input: &test.RepPrimitives{FieldF: []uint64{}}}, - {name: "uint64", input: &test.RepPrimitives{FieldFu: []uint64{}}}, + {name: "default", input: &generated.RepPrimitives{}}, + {name: "bytes", input: &generated.RepPrimitives{FieldA: [][]byte{}}}, + {name: "string", input: &generated.RepPrimitives{FieldB: []string{}}}, + {name: "int32", input: &generated.RepPrimitives{FieldC: []int32{}}}, + {name: "uint32", input: &generated.RepPrimitives{FieldD: []uint32{}}}, + {name: "int64", input: &generated.RepPrimitives{FieldE: []int64{}}}, + {name: "uint64", input: &generated.RepPrimitives{FieldF: []uint64{}}}, + {name: "uint64", input: &generated.RepPrimitives{FieldFu: []uint64{}}}, } for _, tc := range marshalCases { - require.Zero(t, tc.input.StableSize()) + t.Run(tc.name, func(t *testing.T) { + require.Zero(t, tc.input.StableSize()) - r := tc.input.StableMarshal(nil) - require.Empty(t, r) + r := tc.input.MarshalProtobuf(nil) + require.Empty(t, r) + }) } }) marshalCases := []struct { name string - input *test.RepPrimitives + input *generated.RepPrimitives }{ - {name: "bytes", input: &test.RepPrimitives{FieldA: [][]byte{{1, 2, 3}}}}, - {name: "string", input: &test.RepPrimitives{FieldB: []string{"123"}}}, - {name: "int32", input: &test.RepPrimitives{FieldC: randIntSlice[int32](1, true)}}, - {name: "int32", input: &test.RepPrimitives{FieldC: randIntSlice[int32](2, true)}}, - {name: "int32", input: &test.RepPrimitives{FieldC: randIntSlice[int32](2, false)}}, - {name: "uint32", input: &test.RepPrimitives{FieldD: randIntSlice[uint32](1, true)}}, - {name: "uint32", input: &test.RepPrimitives{FieldD: randIntSlice[uint32](2, true)}}, - {name: "uint32", input: &test.RepPrimitives{FieldD: randIntSlice[uint32](2, false)}}, - {name: "int64", input: &test.RepPrimitives{FieldE: randIntSlice[int64](1, true)}}, - {name: "int64", input: &test.RepPrimitives{FieldE: randIntSlice[int64](2, true)}}, - {name: "int64", input: &test.RepPrimitives{FieldE: randIntSlice[int64](2, false)}}, - {name: "uint64", input: &test.RepPrimitives{FieldF: randIntSlice[uint64](1, true)}}, - {name: "uint64", input: &test.RepPrimitives{FieldF: randIntSlice[uint64](2, true)}}, - {name: "uint64", input: &test.RepPrimitives{FieldF: randIntSlice[uint64](2, false)}}, - {name: "uint64", input: &test.RepPrimitives{FieldFu: randIntSlice[uint64](1, true)}}, - {name: "uint64", input: &test.RepPrimitives{FieldFu: randIntSlice[uint64](2, true)}}, - {name: "uint64", input: &test.RepPrimitives{FieldFu: randIntSlice[uint64](2, false)}}, + {name: "bytes", input: &generated.RepPrimitives{FieldA: [][]byte{{1, 2, 3}}}}, + {name: "string", input: &generated.RepPrimitives{FieldB: []string{"123"}}}, + {name: "int32", input: &generated.RepPrimitives{FieldC: randIntSlice[int32](1, true)}}, + {name: "int32", input: &generated.RepPrimitives{FieldC: randIntSlice[int32](2, true)}}, + {name: "int32", input: &generated.RepPrimitives{FieldC: randIntSlice[int32](2, false)}}, + {name: "uint32", input: &generated.RepPrimitives{FieldD: randIntSlice[uint32](1, true)}}, + {name: "uint32", input: &generated.RepPrimitives{FieldD: randIntSlice[uint32](2, true)}}, + {name: "uint32", input: &generated.RepPrimitives{FieldD: randIntSlice[uint32](2, false)}}, + {name: "int64", input: &generated.RepPrimitives{FieldE: randIntSlice[int64](1, true)}}, + {name: "int64", input: &generated.RepPrimitives{FieldE: randIntSlice[int64](2, true)}}, + {name: "int64", input: &generated.RepPrimitives{FieldE: randIntSlice[int64](2, false)}}, + {name: "uint64", input: &generated.RepPrimitives{FieldF: randIntSlice[uint64](1, true)}}, + {name: "uint64", input: &generated.RepPrimitives{FieldF: randIntSlice[uint64](2, true)}}, + {name: "uint64", input: &generated.RepPrimitives{FieldF: randIntSlice[uint64](2, false)}}, + {name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](1, true)}}, + {name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](2, true)}}, + {name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](2, false)}}, } for _, tc := range marshalCases { t.Run(tc.name, func(t *testing.T) { - r := tc.input.StableMarshal(nil) + r := tc.input.MarshalProtobuf(nil) require.Equal(t, len(r), tc.input.StableSize()) require.NotEmpty(t, r) diff --git a/util/proto/test/custom/test_frostfs.pb.go b/util/proto/test/custom/test_frostfs.pb.go new file mode 100644 index 0000000..28a3044 Binary files /dev/null and b/util/proto/test/custom/test_frostfs.pb.go differ diff --git a/util/proto/test/test_frostfs.pb.go b/util/proto/test/test_frostfs.pb.go deleted file mode 100644 index 47c6d60..0000000 Binary files a/util/proto/test/test_frostfs.pb.go and /dev/null differ diff --git a/util/protogen/internalgengo/file.go b/util/protogen/internalgengo/file.go new file mode 100644 index 0000000..b5b351c --- /dev/null +++ b/util/protogen/internalgengo/file.go @@ -0,0 +1,250 @@ +package internalgengo + +import ( + "fmt" + "sort" + "strconv" + "strings" + + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/reflect/protoreflect" +) + +var ( + strconvPackage = protogen.GoImportPath("strconv") + fmtPackage = protogen.GoImportPath("fmt") + jsonPackage = protogen.GoImportPath("encoding/json") + easyprotoPackage = protogen.GoImportPath("github.com/VictoriaMetrics/easyproto") + mpPackage = protogen.GoImportPath("git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/pool") + protoPackage = protogen.GoImportPath("git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto") + encodingPackage = protogen.GoImportPath("git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/encoding") + + mp = mpPackage.Ident("MarshalerPool") +) + +// GenerateFile generates a *.pb.go file enforcing field-order serialization. +func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile { + filename := file.GeneratedFilenamePrefix + "_frostfs.pb.go" + g := gen.NewGeneratedFile(filename, file.GoImportPath) + + g.P("// Code generated by protoc-gen-go-frostfs. DO NOT EDIT.") + g.P() + g.P("package ", file.GoPackageName) + g.P() + g.Import(encodingPackage) + + // Doesn't work for multiple files in a single package, use external pool. + // g.P("var mp ", easyprotoPackage.Ident("MarshalerPool")) + + for _, e := range file.Enums { + emitEnum(g, e) + } + for _, msg := range file.Messages { + emitEasyProto(g, msg) + } + return g +} + +func emitEnum(g *protogen.GeneratedFile, e *protogen.Enum) { + g.P("type " + e.GoIdent.GoName + " int32") + g.P("const (") + for _, ev := range e.Values { + g.P(ev.GoIdent.GoName, " ", e.GoIdent.GoName, " = ", ev.Desc.Number()) + } + g.P(")") + + g.P("var (") + g.P(e.GoIdent.GoName+"_name", " = map[int32]string{") + for _, value := range e.Values { + g.P(value.Desc.Number(), ": ", strconv.Quote(string(value.Desc.Name())), ",") + } + g.P("}") + g.P(e.GoIdent.GoName+"_value", " = map[string]int32{") + for _, value := range e.Values { + g.P(strconv.Quote(string(value.Desc.Name())), ": ", value.Desc.Number(), ",") + } + g.P("}") + g.P(")") + g.P() + + g.P("func (x ", e.GoIdent.GoName, ") String() string {") + g.P("if v, ok := ", e.GoIdent.GoName+"_name[int32(x)]; ok {") + g.P("return v") + g.P("}") + g.P("return ", strconvPackage.Ident("FormatInt"), "(int64(x), 10)") + g.P("}") + + g.P("func (x *", e.GoIdent.GoName, ") FromString(s string) bool {") + g.P("if v, ok := ", e.GoIdent.GoName+"_value[s]; ok {") + g.P("*x = ", e.GoIdent.GoName, "(v)") + g.P("return true") + g.P("}") + g.P("return false") + g.P("}") +} + +func emitEasyProto(g *protogen.GeneratedFile, msg *protogen.Message) { + for _, e := range msg.Enums { + emitEnum(g, e) + } + for _, m := range msg.Messages { + emitEasyProto(g, m) + } + + g.P("type " + msg.GoIdent.GoName + " struct {") + emitMessageFields(g, msg) + g.P("}") + + g.P("var (") + g.P("_ ", encodingPackage.Ident("ProtoMarshaler"), " = (*", msg.GoIdent.GoName, ")(nil)") + g.P("_ ", encodingPackage.Ident("ProtoUnmarshaler"), " = (*", msg.GoIdent.GoName, ")(nil)") + g.P("_ ", jsonPackage.Ident("Marshaler"), " = (*", msg.GoIdent.GoName, ")(nil)") + g.P("_ ", jsonPackage.Ident("Unmarshaler"), " = (*", msg.GoIdent.GoName, ")(nil)") + g.P(")") + + emitStableSize(g, msg) + if strings.HasSuffix(msg.GoIdent.GoName, "Request") || strings.HasSuffix(msg.GoIdent.GoName, "Response") { + emitSignatureMethods(g, msg) + } + + emitProtoMethods(g, msg) + emitGettersSetters(g, msg) + emitJSONMethods(g, msg) + + for _, f := range msg.Fields { + if isFirstOneof(f) { + genOneof(g, f) + } + } +} + +func isFirstOneof(f *protogen.Field) bool { + return f.Oneof != nil && f == f.Oneof.Fields[0] +} + +func emitOneofGettersSetters(g *protogen.GeneratedFile, msg *protogen.Message, ff *protogen.Field) { + // For some reason protoc generates different code for oneof message/non-message fields: + // 1. For message we have 2 level struct wrapping and setters use inner type. + // 2. For other types we also have 2 level wrapping, but setters use outer type. + if ff.Desc.Kind() == protoreflect.MessageKind { + ft := fieldType(g, ff) + + g.P("func (x *", msg.GoIdent.GoName, ") Get", ff.GoName, "() ", ft, " {") + g.P("if xx, ok := x.Get", ff.Oneof.GoName, "().(*", ff.GoIdent, "); ok { return xx.", ff.GoName, " }") + g.P("return nil") + g.P("}") + + g.P("func (x *", msg.GoIdent.GoName, ") Set", ff.GoName, "(v ", ft, ") {") + g.P("x.", ff.Oneof.GoName, " = &", ff.GoIdent, "{", ff.GoName, ": v}") + g.P("}") + } else { + g.P("func (x *", msg.GoIdent.GoName, ") Get", ff.GoName, "() *", ff.GoIdent, " {") + g.P("if xx, ok := x.Get", ff.Oneof.GoName, "().(*", ff.GoIdent, "); ok { return xx }") + g.P("return nil") + g.P("}") + + g.P("func (x *", msg.GoIdent.GoName, ") Set", ff.GoName, "(v *", ff.GoIdent, ") {") + g.P("x.", ff.Oneof.GoName, " = v") + g.P("}") + + ft := fieldType(g, ff) + emitGetterSetter(g, ff.GoIdent.GoName, ff.GoName, ft.String(), "nil") + } +} + +func emitGettersSetters(g *protogen.GeneratedFile, msg *protogen.Message) { + for _, f := range msg.Fields { + if f.Oneof != nil { + if f.Oneof.Fields[0] == f { + emitGetterSetter(g, msg.GoIdent.GoName, f.Oneof.GoName, oneOfDescriptor(f.Oneof), "nil") + for _, ff := range f.Oneof.Fields { + emitOneofGettersSetters(g, msg, ff) + } + } + continue + } + + ft := fieldType(g, f) + emitGetterSetter(g, msg.GoIdent.GoName, f.GoName, ft.String(), fieldDefaultValue(f)) + } +} + +func emitMessageFields(g *protogen.GeneratedFile, msg *protogen.Message) { + for _, field := range msg.Fields { + genMessageField(g, field) + } +} + +func genMessageField(g *protogen.GeneratedFile, field *protogen.Field) { + if field.Oneof != nil { + if field.Oneof.Fields[0] == field { + g.P(field.Oneof.GoName, " ", oneOfDescriptor(field.Oneof)) + } + return + } + + typ := fieldType(g, field) + g.P(field.GoName, " ", typ, fmt.Sprintf(" `json:%q`", fieldJSONName(field))) +} + +func oneOfDescriptor(oneof *protogen.Oneof) string { + return "is" + oneof.GoIdent.GoName +} + +func genOneof(g *protogen.GeneratedFile, field *protogen.Field) { + ifName := oneOfDescriptor(field.Oneof) + g.P("type ", ifName, " interface {") + g.P(ifName, "()") + g.P("}") + g.P() + for _, field := range field.Oneof.Fields { + g.P("type ", field.GoIdent, " struct {") + + ft := fieldType(g, field) + g.P(field.GoName, " ", ft) + g.P("}") + g.P() + } + for _, field := range field.Oneof.Fields { + g.P("func (*", field.GoIdent, ") ", ifName, "() {}") + g.P() + } +} + +func fieldDefaultValue(field *protogen.Field) string { + if field.Desc.Cardinality() == protoreflect.Repeated { + return "nil" + } + + switch field.Desc.Kind() { + case protoreflect.MessageKind, protoreflect.BytesKind: + return "nil" + case protoreflect.BoolKind: + return "false" + case protoreflect.StringKind: + return `""` + default: + return "0" + } +} + +func castFieldName(f *protogen.Field) string { + if f.Oneof != nil { + return "x." + f.Oneof.GoName + } + + name := "x." + f.GoName + if f.Desc.Kind() != protoreflect.EnumKind { + return name + } + return "int32(" + name + ")" +} + +func sortFields(fs []*protogen.Field) []*protogen.Field { + res := make([]*protogen.Field, len(fs)) + copy(res, fs) + sort.Slice(res, func(i, j int) bool { + return res[i].Desc.Number() < res[j].Desc.Number() + }) + return res +} diff --git a/util/protogen/internalgengo/fuzz.go b/util/protogen/internalgengo/fuzz.go new file mode 100644 index 0000000..ec99692 --- /dev/null +++ b/util/protogen/internalgengo/fuzz.go @@ -0,0 +1,69 @@ +package internalgengo + +import ( + "google.golang.org/protobuf/compiler/protogen" +) + +var testingPackage = protogen.GoImportPath("testing") + +func GenerateFuzzTests(gen *protogen.Plugin, file *protogen.File) { + { + filename := file.GeneratedFilenamePrefix + "_frostfs_fuzz.go" + g := gen.NewGeneratedFile(filename, file.GoImportPath) + + g.P("//go:build gofuzz") + g.P("// +build gofuzz") + g.P("// Code generated by protoc-gen-go-frostfs. DO NOT EDIT.") + g.P() + g.P("package ", file.GoPackageName) + g.P() + + for _, msg := range file.Messages { + emitFuzzWrappers(g, msg) + } + } + { + filename := file.GeneratedFilenamePrefix + "_frostfs_test.go" + g := gen.NewGeneratedFile(filename, file.GoImportPath) + + g.P("//go:build gofuzz") + g.P("// +build gofuzz") + g.P("// Code generated by protoc-gen-go-frostfs. DO NOT EDIT.") + g.P() + g.P("package ", file.GoPackageName) + g.P() + + for _, msg := range file.Messages { + emitFuzzTests(g, msg) + } + } +} + +func emitFuzzWrappers(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("func DoFuzzProto", msg.GoIdent.GoName, "(data []byte) int {") + g.P("msg := new(", msg.GoIdent.GoName, ")") + g.P("if err := msg.UnmarshalProtobuf(data); err != nil { return 0 }") + g.P("_ = msg.MarshalProtobuf(nil)") + g.P("return 1") + g.P("}") + + g.P("func DoFuzzJSON", msg.GoIdent.GoName, "(data []byte) int {") + g.P("msg := new(", msg.GoIdent.GoName, ")") + g.P("if err := msg.UnmarshalJSON(data); err != nil { return 0 }") + g.P("_, err := msg.MarshalJSON()") + g.P("if err != nil { panic(err) }") + g.P("return 1") + g.P("}") +} + +func emitFuzzTests(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("func FuzzProto", msg.GoIdent.GoName, "(f *", testingPackage.Ident("F"), ") {") + g.P("f.Fuzz(func(t *", testingPackage.Ident("T"), ", data []byte) {") + g.P("DoFuzzProto", msg.GoIdent.GoName, "(data)") + g.P("})}") + + g.P("func FuzzJSON", msg.GoIdent.GoName, "(f *", testingPackage.Ident("F"), ") {") + g.P("f.Fuzz(func(t *", testingPackage.Ident("T"), ", data []byte) {") + g.P("DoFuzzJSON", msg.GoIdent.GoName, "(data)") + g.P("})}") +} diff --git a/util/protogen/internalgengo/getter.go b/util/protogen/internalgengo/getter.go new file mode 100644 index 0000000..78deef7 --- /dev/null +++ b/util/protogen/internalgengo/getter.go @@ -0,0 +1,14 @@ +package internalgengo + +import "google.golang.org/protobuf/compiler/protogen" + +func emitGetterSetter(g *protogen.GeneratedFile, typeName string, fieldName string, fieldType string, defaultValue string) { + g.P("func (x *", typeName, ") Get", fieldName, "() ", fieldType, " {") + g.P("if x != nil { return x.", fieldName, "}") + g.P("return ", defaultValue) + g.P("}") + + g.P("func (x *", typeName, ") Set", fieldName, "(v ", fieldType, ") {") + g.P("x.", fieldName, " = v") + g.P("}") +} diff --git a/util/protogen/internalgengo/json.go b/util/protogen/internalgengo/json.go new file mode 100644 index 0000000..ad43fc8 --- /dev/null +++ b/util/protogen/internalgengo/json.go @@ -0,0 +1,230 @@ +package internalgengo + +import ( + "fmt" + + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/reflect/protoreflect" +) + +var ( + jwriterPackage = protogen.GoImportPath("github.com/mailru/easyjson/jwriter") + jlexerPackage = protogen.GoImportPath("github.com/mailru/easyjson/jlexer") +) + +func emitJSONMethods(g *protogen.GeneratedFile, msg *protogen.Message) { + emitJSONMarshal(g, msg) + emitJSONUnmarshal(g, msg) +} + +func emitJSONUnmarshal(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("// UnmarshalJSON implements the json.Unmarshaler interface.") + g.P("func (x *", msg.GoIdent.GoName, ") UnmarshalJSON(data []byte) error {") + g.P("r := ", jlexerPackage.Ident("Lexer"), "{Data: data}") + g.P("x.UnmarshalEasyJSON(&r)") + g.P("return r.Error()") + g.P("}") + + g.P("func (x *", msg.GoIdent.GoName, ") UnmarshalEasyJSON(in *", jlexerPackage.Ident("Lexer"), ") {") + + g.P("isTopLevel := in.IsStart()") + g.P("if in.IsNull() {") + g.P("if isTopLevel { in.Consumed() }") + g.P("in.Skip()") + g.P("return") + g.P("}") + + g.P("in.Delim('{')") + g.P("for !in.IsDelim('}') {") + + g.P("key := in.UnsafeFieldName(false)") + g.P("in.WantColon()") + g.P("if in.IsNull() { in.Skip(); in.WantComma(); continue }") + g.P("switch key {") + for _, f := range msg.Fields { + g.P(`case "`, fieldJSONName(f), `":`) + if f.Oneof != nil { + g.P("xx := new(", f.GoIdent, ")") + g.P("x." + f.Oneof.GoName + " = xx") + emitJSONFieldRead(g, f, "xx") + continue + } + emitJSONFieldRead(g, f, "x") + } + g.P("}") + g.P("in.WantComma()") + g.P("}") + g.P("in.Delim('}')") + g.P("if isTopLevel { in.Consumed() }") + g.P("}") +} + +func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string) { + g.P("{") + defer g.P("}") + + if f.Desc.IsList() { + g.P("var f ", fieldType(g, f)[2:]) + g.P("var list ", fieldType(g, f)) + g.P("in.Delim('[')") + defer g.P("in.Delim(']')") + + g.P("for !in.IsDelim(']') {") + } else { + g.P("var f ", fieldType(g, f)) + } + + var template string + switch f.Desc.Kind() { + case protoreflect.BoolKind: + template = "%s = in.Bool()" + case protoreflect.EnumKind: + g.Import(strconvPackage) + + enumType := fieldType(g, f).String() + g.P("var parsedValue " + enumType) + g.P(`switch v := in.Interface().(type) { + case string: + if vv, ok := `+enumType+`_value[v]; ok { + parsedValue = `+enumType+`(vv) + break + } + vv, err := `, strconvPackage.Ident("ParseInt"), `(v, 10, 32) + if err != nil { + in.AddError(err) + return + } + parsedValue = `+enumType+`(vv) + case float64: + parsedValue = `+enumType+`(v) + }`) + template = "%s = parsedValue" + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + template = "%s = in.Int32()" + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: + template = "%s = in.Uint32()" + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + template = "%s = in.Int64()" + case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + template = "%s = in.Uint64()" + case protoreflect.FloatKind: + template = "%s = in.Float32()" + case protoreflect.DoubleKind: + template = "%s = in.Float64()" + case protoreflect.StringKind: + template = "%s = in.String()" + case protoreflect.BytesKind: + template = "%s = in.Bytes()" + case protoreflect.MessageKind: + if f.Desc.IsList() { + g.P("f = new(", fieldType(g, f)[3:], ")") + } else { + g.P("f = new(", fieldType(g, f)[1:], ")") + } + template = "%s.UnmarshalEasyJSON(in)" + case protoreflect.GroupKind: + panic("unimplemented") + } + g.P(fmt.Sprintf(template, "f")) + if f.Desc.IsList() { + g.P("list = append(list, f)") + g.P("in.WantComma()") + g.P("}") + g.P(name, ".", f.GoName, " = list") + } else { + g.P(name, ".", f.GoName, " = f") + } +} + +func emitJSONMarshal(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("// MarshalJSON implements the json.Marshaler interface.") + g.P("func (x *", msg.GoIdent.GoName, ") MarshalJSON() ([]byte, error) {") + g.P("w := ", jwriterPackage.Ident("Writer"), "{}") + g.P("x.MarshalEasyJSON(&w)") + g.P("return w.Buffer.BuildBytes(), w.Error") + g.P("}") + + g.P("func (x *", msg.GoIdent.GoName, ") MarshalEasyJSON(out *", jwriterPackage.Ident("Writer"), ") {") + g.P(`if x == nil { out.RawString("null"); return }`) + + g.P("out.RawByte('{')") + for i, f := range msg.Fields { + if f.Oneof != nil { + if f.Oneof.Fields[0] != f { + continue + } + + g.P("switch xx := x.", f.Oneof.GoName, ".(type) {") + for _, ff := range f.Oneof.Fields { + g.P("case *", ff.GoIdent, ":") + emitJSONFieldWrite(g, ff, "xx", i == 0) + } + g.P("default:") + g.P(`out.RawString("null")`) + g.P("}") + continue + } + emitJSONFieldWrite(g, f, "x", i == 0) + } + g.P("out.RawByte('}')") + g.P("}") +} + +func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name string, first bool) { + g.P("{") + defer g.P("}") + + g.P("const prefix string = ", `",\"`, fieldJSONName(f), `\":"`) + if first { + g.P("out.RawString(prefix[1:])") + } else { + g.P("out.RawString(prefix)") + } + + selector := name + "." + f.GoName + if f.Desc.IsList() { + selector += "[i]" + g.P("out.RawByte('[')") + defer g.P("out.RawByte(']')") + + g.P("for i := range ", name, ".", f.GoName, " {") + g.P("if i != 0 { out.RawByte(',') }") + defer g.P("}") + } + + var template string + switch f.Desc.Kind() { + case protoreflect.BoolKind: + template = "out.Bool(%s)" + case protoreflect.EnumKind: + template = "out.Int32(int32(%s))" + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + template = "out.Int32(%s)" + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: + template = "out.Uint32(%s)" + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + template = "out.Int64(%s)" + case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + template = "out.Uint64(%s)" + case protoreflect.FloatKind: + template = "out.Float32(%s)" + case protoreflect.DoubleKind: + template = "out.Float64(%s)" + case protoreflect.StringKind: + template = "out.String(%s)" + case protoreflect.BytesKind: + template = "out.Base64Bytes(%s)" + case protoreflect.MessageKind: + template = "%s.MarshalEasyJSON(out)" + case protoreflect.GroupKind: + panic("unimplemented") + } + g.P(fmt.Sprintf(template, selector)) +} + +func fieldJSONName(f *protogen.Field) string { + if f.Desc.HasJSONName() { + return f.Desc.JSONName() + } + return string(f.Desc.Name()) +} diff --git a/util/protogen/internalgengo/options.go b/util/protogen/internalgengo/options.go new file mode 100644 index 0000000..8aab8f0 --- /dev/null +++ b/util/protogen/internalgengo/options.go @@ -0,0 +1,7 @@ +package internalgengo + +type Options struct { + Fuzz bool `yaml:"fuzz"` + JSON bool `yaml:"json"` + MessageData []string `yaml:"message_data"` +} diff --git a/util/protogen/internalgengo/proto.go b/util/protogen/internalgengo/proto.go new file mode 100644 index 0000000..8e5e967 --- /dev/null +++ b/util/protogen/internalgengo/proto.go @@ -0,0 +1,201 @@ +package internalgengo + +import ( + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/reflect/protoreflect" +) + +func emitProtoMethods(g *protogen.GeneratedFile, msg *protogen.Message) { + emitMarshalProtobuf(g, msg) + emitUnmarshalProtobuf(g, msg) +} + +func emitUnmarshalProtobuf(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("// UnmarshalProtobuf implements the encoding.ProtoUnmarshaler interface.") + g.P("func (x *", msg.GoIdent.GoName, ") UnmarshalProtobuf(src []byte) (err error) {") + g.P("var fc ", easyprotoPackage.Ident("FieldContext")) + g.P("for len(src) > 0 {") + { + g.P("src, err = fc.NextField(src)") + g.P("if err != nil { return ", fmtPackage.Ident("Errorf"), `("cannot read next field in %s", "`, msg.GoIdent.GoName, `")}`) + g.P("switch fc.FieldNum {") + { + for _, f := range msg.Fields { + g.P("case ", f.Desc.Number(), ":", " // ", f.GoName) + emitFieldUnmarshal(g, f) + } + } + g.P("}") + } + g.P("}") + + g.P("return nil") + g.P("}") +} + +func emitFieldUnmarshal(g *protogen.GeneratedFile, f *protogen.Field) { + name := castFieldName(f) + if f.Desc.Kind() == protoreflect.MessageKind { + g.P("data, ok := fc.MessageData()") + g.P(`if !ok { return fmt.Errorf("cannot unmarshal field %s", "`, f.GoName, `") }`) + if f.Desc.IsList() { + g.P(name, " = append(", name, ", new(", fieldType(g, f)[3:], "))") + g.P("ff := ", name, "[len(", name, ")-1]") + name = "ff" + } else if f.Oneof != nil { + const tmp = "oneofField" + g.P(tmp, " := &", f.GoIdent, "{", f.GoName, ": ", "new(", fieldType(g, f)[1:], ")}") + defer g.P(name, " = ", tmp) + + name = tmp + "." + f.GoName + } else { + g.P(name, " = new(", fieldType(g, f)[1:], ")") + } + + g.P(`if err := `, name, `.UnmarshalProtobuf(data); err != nil { return fmt.Errorf("unmarshal: %w", err)}`) + return + } + + getter, _ := easyprotoKindInfo(f.Desc.Kind()) + + if f.Desc.IsList() && (f.Desc.Kind() == protoreflect.BytesKind || f.Desc.Kind() == protoreflect.StringKind || f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()) { + g.P("data, ok := fc.", getter, "()") + g.P(`if !ok { return fmt.Errorf("cannot unmarshal field %s", "`, f.GoName, `") }`) + g.P(name, " = append(", name, ", data)") + return + } + + if f.Desc.IsList() { + g.P("data, ok := fc.Unpack", getter, "s(nil)") + } else { + g.P("data, ok := fc.", getter, "()") + } + + g.P(`if !ok { return fmt.Errorf("cannot unmarshal field %s", "`, f.GoName, `") }`) + value := "data" + if f.Desc.Kind() == protoreflect.EnumKind { + value = fieldType(g, f).String() + "(data)" + } + + if f.Oneof == nil { + g.P("x.", f.GoName, " = ", value) + } else { + g.P("x.", f.Oneof.GoName, " = &", f.GoIdent, "{", f.GoName, ": data}") + } +} + +func emitMarshalProtobuf(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("// MarshalProtobuf implements the encoding.ProtoMarshaler interface.") + g.P("func (x *", msg.GoIdent.GoName, ") MarshalProtobuf(dst []byte) []byte {") + g.P("m := ", mp, ".Get()") + g.P("defer ", mp, ".Put(m)") + g.P("x.EmitProtobuf(m.MessageMarshaler())") + g.P("dst = m.Marshal(dst)") + g.P("return dst") + g.P("}\n") + + g.P("func (x *", msg.GoIdent.GoName, ") EmitProtobuf(mm *", easyprotoPackage.Ident("MessageMarshaler"), ") {") + if len(msg.Fields) != 0 { + fs := sortFields(msg.Fields) + + g.P("if x == nil { return }") + for _, f := range fs { + emitFieldMarshal(g, f) + } + } + g.P("}") +} + +func emitMarshalOneof(g *protogen.GeneratedFile, f *protogen.Field) { + name := "x." + f.Oneof.GoName + g.P("if inner, ok := ", name, ".(*", f.GoIdent.GoName, "); ok {") + defer g.P("}") + emitMarshalRaw(g, f, "inner."+f.GoName) +} + +// easyprotoKindInfo returns string name for kind, used in easyproto methods. +// The second return value is a condition to test for the default value of kind. +func easyprotoKindInfo(kind protoreflect.Kind) (string, func(string) string) { + switch kind { + case protoreflect.BoolKind: + return "Bool", identity + case protoreflect.EnumKind: + return "Int32", notZero + case protoreflect.Int32Kind: + return "Int32", notZero + case protoreflect.Sint32Kind: + return "Sint32", notZero + case protoreflect.Uint32Kind: + return "Uint32", notZero + case protoreflect.Int64Kind: + return "Int64", notZero + case protoreflect.Sint64Kind: + return "Sint64", notZero + case protoreflect.Uint64Kind: + return "Uint64", notZero + case protoreflect.Sfixed32Kind: + return "Sfixed32", notZero + case protoreflect.Fixed32Kind: + return "Fixed32", notZero + case protoreflect.FloatKind: + return "Float", notZero + case protoreflect.Sfixed64Kind: + return "Sfixed64", notZero + case protoreflect.Fixed64Kind: + return "Fixed64", notZero + case protoreflect.DoubleKind: + return "Double", notZero + case protoreflect.StringKind: + return "String", notEmpty + case protoreflect.BytesKind: + return "Bytes", notEmpty + case protoreflect.GroupKind: + panic("unimplemented") + default: + panic("unreachable") + } +} + +func emitFieldMarshal(g *protogen.GeneratedFile, f *protogen.Field) { + if f.Oneof != nil { + emitMarshalOneof(g, f) + return + } + + emitMarshalRaw(g, f, castFieldName(f)) +} + +func emitMarshalRaw(g *protogen.GeneratedFile, f *protogen.Field, name string) { + if f.Desc.Kind() == protoreflect.MessageKind { + if f.Desc.IsList() { + g.P("for i := range ", name, " {") + defer g.P("}") + + name += "[i]" + } + + g.P("if ", notNil(name), " && ", name, ".StableSize() != 0 {") + g.P(name, ".EmitProtobuf(mm.AppendMessage(", f.Desc.Number(), "))") + g.P("}") + return + } + + method, cond := easyprotoKindInfo(f.Desc.Kind()) + method = "Append" + method + if f.Desc.IsList() && !f.Desc.IsPacked() { + g.P("for j := range ", name, " {") + g.P("mm.", method, "(", f.Desc.Number(), ", ", name, "[j])") + g.P("}") + return + } + + if f.Desc.IsList() { + method += "s" + g.P("if ", notEmpty(name), "{") + } else { + g.P("if ", cond(name), " {") + } + + g.P("mm.", method, "(", f.Desc.Number(), ", ", name, ")") + g.P("}") +} diff --git a/util/protogen/internalgengo/proto_field_type.go b/util/protogen/internalgengo/proto_field_type.go new file mode 100644 index 0000000..09f6884 --- /dev/null +++ b/util/protogen/internalgengo/proto_field_type.go @@ -0,0 +1,56 @@ +package internalgengo + +import ( + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/reflect/protoreflect" +) + +type structField string + +func (f structField) String() string { + return string(f) +} + +func (f structField) PointerTo() structField { + return "*" + f +} + +func (f structField) SliceOf() structField { + return "[]" + f +} + +func fieldType(g *protogen.GeneratedFile, field *protogen.Field) structField { + var typ structField + switch field.Desc.Kind() { + case protoreflect.BoolKind: + typ = "bool" + case protoreflect.EnumKind: + typ = structField(g.QualifiedGoIdent(field.Enum.GoIdent)) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + typ = "int32" + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: + typ = "uint32" + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + typ = "int64" + case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + typ = "uint64" + case protoreflect.FloatKind: + typ = "float32" + case protoreflect.DoubleKind: + typ = "float64" + case protoreflect.StringKind: + typ = "string" + case protoreflect.BytesKind: + typ = "[]byte" + case protoreflect.MessageKind: + typ = structField(g.QualifiedGoIdent(field.Message.GoIdent)).PointerTo() + case protoreflect.GroupKind: + panic("unimplemented") + } + + if field.Desc.IsList() { + typ = "[]" + typ + } + + return typ +} diff --git a/util/protogen/internalgengo/proto_stable_compat.go b/util/protogen/internalgengo/proto_stable_compat.go new file mode 100644 index 0000000..c27b9d8 --- /dev/null +++ b/util/protogen/internalgengo/proto_stable_compat.go @@ -0,0 +1,124 @@ +package internalgengo + +import ( + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/reflect/protoreflect" +) + +var protowirePackage = protogen.GoImportPath("google.golang.org/protobuf/encoding/protowire") + +func emitStableSize(g *protogen.GeneratedFile, msg *protogen.Message) { + fs := sortFields(msg.Fields) + + g.P("// StableSize returns the size of x in protobuf format.") + g.P("//") + g.P("// Structures with the same field values have the same binary size.") + g.P("func (x *", msg.GoIdent.GoName, ") StableSize() (size int) {") + g.P("if x == nil { return 0 }") + if len(fs) != 0 { + for _, f := range fs { + if f.Desc.IsList() && marshalers[f.Desc.Kind()].RepeatedDouble && !(f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()) { + g.P("var n int") + break + } + } + for _, f := range fs { + emitFieldSize(g, f) + } + } + g.P("return size") + g.P("}\n") +} + +func emitSignatureMethods(g *protogen.GeneratedFile, msg *protogen.Message) { + // SignedDataSize implementation (only for requests and responses). + g.P("// ReadSignedData fills buf with signed data of x.") + g.P("// If buffer length is less than x.SignedDataSize(), new buffer is allocated.") + g.P("//") + g.P("// Returns any error encountered which did not allow writing the data completely.") + g.P("// Otherwise, returns the buffer in which the data is written.") + g.P("//") + g.P("// Structures with the same field values have the same signed data.") + g.P("func (x *", msg.GoIdent.GoName, ") SignedDataSize() int {") + g.P("return x.GetBody().StableSize()") + g.P("}\n") + + // ReadSignedData implementation (only for requests and responses). + g.P("// SignedDataSize returns size of the request signed data in bytes.") + g.P("//") + g.P("// Structures with the same field values have the same signed data size.") + g.P("func (x *", msg.GoIdent.GoName, ") ReadSignedData(buf []byte) ([]byte, error) {") + g.P("return x.GetBody().MarshalProtobuf(buf), nil") + g.P("}\n") +} + +func emitFieldSize(g *protogen.GeneratedFile, f *protogen.Field) { + m := marshalers[f.Desc.Kind()] + if m.Prefix == "" { + g.P("// FIXME missing field marshaler: ", f.GoName, " of type ", f.Desc.Kind().String()) + g.P(`panic("unimplemented")`) + return + } + + name := castFieldName(f) + if f.Oneof != nil { + name = "x." + f.Oneof.GoName + g.P("if inner, ok := ", name, ".(*", f.GoIdent.GoName, "); ok {") + defer g.P("}") + name = "inner." + f.GoName + } + + switch { + case f.Desc.IsList() && (f.Desc.Kind() == protoreflect.MessageKind || f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()): + g.P("for i := range ", name, "{") + if f.Desc.Kind() == protoreflect.MessageKind { + g.P("size += ", protoPackage.Ident("NestedStructureSize"), "(", f.Desc.Number(), ", ", name, "[i])") + } else { + if f.Desc.Kind() != protoreflect.Uint64Kind { + panic("only uint64 unpacked primitive is supported") + } + + g.P("size += ", protowirePackage.Ident("SizeGroup"), "(", + protowirePackage.Ident("Number"), "(", f.Desc.Number(), "), ", + protowirePackage.Ident("SizeVarint"), "(", name, "[i]))") + } + g.P("}") + + case f.Desc.IsList(): + if m.RepeatedDouble { + g.P("n, _ = ", protoPackage.Ident("Repeated"+m.Prefix+"Size"), "(", f.Desc.Number(), ", ", name, ")") + g.P("size += n") + } else { + g.P("size += ", protoPackage.Ident("Repeated"+m.Prefix+"Size"), "(", f.Desc.Number(), ", ", name, ")") + } + default: + g.P("size += ", protoPackage.Ident(m.Prefix+"Size"), "(", f.Desc.Number(), ", ", name, ")") + } +} + +type marshalerDesc struct { + Prefix string + RepeatedDouble bool +} + +// Unused kinds are commented. +var marshalers = map[protoreflect.Kind]marshalerDesc{ + protoreflect.BoolKind: {Prefix: "Bool"}, + protoreflect.EnumKind: {Prefix: "Enum"}, + protoreflect.Int32Kind: {Prefix: "Int32", RepeatedDouble: true}, + // protoreflect.Sint32Kind: "", + protoreflect.Uint32Kind: {Prefix: "UInt32", RepeatedDouble: true}, + protoreflect.Int64Kind: {Prefix: "Int64", RepeatedDouble: true}, + // protoreflect.Sint64Kind: "", + protoreflect.Uint64Kind: {Prefix: "UInt64", RepeatedDouble: true}, + // protoreflect.Sfixed32Kind: "", + protoreflect.Fixed32Kind: {Prefix: "Fixed32", RepeatedDouble: true}, + // protoreflect.FloatKind: "", + // protoreflect.Sfixed64Kind: "", + protoreflect.Fixed64Kind: {Prefix: "Fixed64", RepeatedDouble: true}, + protoreflect.DoubleKind: {Prefix: "Float64"}, + protoreflect.StringKind: {Prefix: "String"}, + protoreflect.BytesKind: {Prefix: "Bytes"}, + protoreflect.MessageKind: {Prefix: "NestedStructure"}, + // protoreflect.GroupKind: "", +} diff --git a/util/protogen/internalgengo/writer.go b/util/protogen/internalgengo/writer.go new file mode 100644 index 0000000..7b0d4f1 --- /dev/null +++ b/util/protogen/internalgengo/writer.go @@ -0,0 +1,30 @@ +package internalgengo + +import ( + "fmt" +) + +type condition = func(string) string + +var ( + _ condition = notZero + _ condition = notEmpty + _ condition = identity + _ condition = notNil +) + +func notZero(name string) string { + return fmt.Sprintf("%s != 0", name) +} + +func notEmpty(name string) string { + return fmt.Sprintf("len(%s) != 0", name) +} + +func identity(name string) string { + return name +} + +func notNil(name string) string { + return fmt.Sprintf("%s != nil", name) +} diff --git a/util/protogen/main.go b/util/protogen/main.go index 0f2a7ca..bfce1bf 100644 --- a/util/protogen/main.go +++ b/util/protogen/main.go @@ -1,258 +1,37 @@ package main import ( - "sort" - "strings" + "flag" + "fmt" + "os" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/protogen/internalgengo" "google.golang.org/protobuf/compiler/protogen" - "google.golang.org/protobuf/reflect/protoreflect" -) - -var ( - protowirePackage = protogen.GoImportPath("google.golang.org/protobuf/encoding/protowire") - binaryPackage = protogen.GoImportPath("encoding/binary") ) func main() { - protogen.Options{}.Run(func(gen *protogen.Plugin) error { + var flags flag.FlagSet + genFuzz := flags.Bool("fuzz", false, "generate fuzz tests") + yamlConfigPath := flags.String("config", "", "path to the configuration") + + protogen.Options{ + ParamFunc: flags.Set, + }.Run(func(gen *protogen.Plugin) error { + if *yamlConfigPath != "" { + s, e := os.Getwd() + fmt.Fprintln(os.Stderr, s, e) + data, err := os.ReadFile(*yamlConfigPath) + fmt.Fprintln(os.Stderr, string(data), err) + } + for _, f := range gen.Files { if f.Generate { - generateFile(gen, f) + internalgengo.GenerateFile(gen, f) + if *genFuzz { + internalgengo.GenerateFuzzTests(gen, f) + } } } return nil }) } - -// generateFile generates a *.pb.go file enforcing field-order serialization. -func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile { - filename := file.GeneratedFilenamePrefix + "_frostfs.pb.go" - g := gen.NewGeneratedFile(filename, file.GoImportPath) - g.P("// Code generated by protoc-gen-go-frostfs. DO NOT EDIT.") - g.P() - g.P("package ", file.GoPackageName) - g.P() - g.P(`import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"`) - - //for _, e := range file.Enums { - // g.P("type " + e.GoIdent.GoName + " int32") - // g.P("const (") - // for _, ev := range e.Values { - // g.P(ev.GoIdent.GoName, " = ", ev.Desc.Number()) - // } - // g.P(")") - //} - for _, msg := range file.Messages { - emitMessage(g, msg) - } - return g -} - -func emitMessage(g *protogen.GeneratedFile, msg *protogen.Message) { - for _, inner := range msg.Messages { - emitMessage(g, inner) - } - - fs := sortFields(msg.Fields) - - // StableSize implementation. - g.P("// StableSize returns the size of x in protobuf format.") - g.P("//") - g.P("// Structures with the same field values have the same binary size.") - g.P("func (x *", msg.GoIdent.GoName, ") StableSize() (size int) {") - g.P("if x == nil { return 0 }") - if len(fs) != 0 { - for _, f := range fs { - if f.Desc.IsList() && marshalers[f.Desc.Kind()].RepeatedDouble && !(f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()) { - g.P("var n int") - break - } - } - for _, f := range fs { - emitFieldSize(g, f) - } - } - g.P("return size") - g.P("}\n") - - // StableMarshal implementation. - g.P("// StableMarshal marshals x in protobuf binary format with stable field order.") - g.P("//") - g.P("// If buffer length is less than x.StableSize(), new buffer is allocated.") - g.P("//") - g.P("// Returns any error encountered which did not allow writing the data completely.") - g.P("// Otherwise, returns the buffer in which the data is written.") - g.P("//") - g.P("// Structures with the same field values have the same binary format.") - g.P("func (x *", msg.GoIdent.GoName, ") StableMarshal(buf []byte) []byte {") - if len(fs) != 0 { - g.P("if x == nil { return []byte{} }") - g.P("if buf == nil { buf = make([]byte, x.StableSize()) }") - g.P("var offset int") - for _, f := range fs { - emitFieldMarshal(g, f) - } - } - g.P("return buf") - g.P("}\n") - - if strings.HasSuffix(msg.GoIdent.GoName, "Request") || strings.HasSuffix(msg.GoIdent.GoName, "Response") { - // SignedDataSize implementation (only for requests and responses). - g.P("// ReadSignedData fills buf with signed data of x.") - g.P("// If buffer length is less than x.SignedDataSize(), new buffer is allocated.") - g.P("//") - g.P("// Returns any error encountered which did not allow writing the data completely.") - g.P("// Otherwise, returns the buffer in which the data is written.") - g.P("//") - g.P("// Structures with the same field values have the same signed data.") - g.P("func (x *", msg.GoIdent.GoName, ") SignedDataSize() int {") - g.P("return x.GetBody().StableSize()") - g.P("}\n") - - // ReadSignedData implementation (only for requests and responses). - g.P("// SignedDataSize returns size of the request signed data in bytes.") - g.P("//") - g.P("// Structures with the same field values have the same signed data size.") - g.P("func (x *", msg.GoIdent.GoName, ") ReadSignedData(buf []byte) ([]byte, error) {") - g.P("return x.GetBody().StableMarshal(buf), nil") - g.P("}\n") - - // Signature setters and getters. - g.P("func (x *", msg.GoIdent.GoName, ") SetSignature(sig *Signature) {") - g.P("x.Signature = sig") - g.P("}\n") - } -} - -func emitFieldSize(g *protogen.GeneratedFile, f *protogen.Field) { - m := marshalers[f.Desc.Kind()] - if m.Prefix == "" { - g.P("// FIXME missing field marshaler: ", f.GoName, " of type ", f.Desc.Kind().String()) - g.P(`panic("unimplemented")`) - return - } - - name := castFieldName(f) - if f.Oneof != nil { - name = "x." + f.Oneof.GoName - g.P("if inner, ok := ", name, ".(*", f.GoIdent.GoName, "); ok {") - defer g.P("}") - name = "inner." + f.GoName - } - - switch { - case f.Desc.IsList() && (f.Desc.Kind() == protoreflect.MessageKind || f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()): - g.P("for i := range ", name, "{") - if f.Desc.Kind() == protoreflect.MessageKind { - g.P("size += proto.NestedStructureSize(", f.Desc.Number(), ", ", name, "[i])") - } else { - if f.Desc.Kind() != protoreflect.Uint64Kind { - panic("only uint64 unpacked primitive is supported") - } - - g.P("size += ", protowirePackage.Ident("SizeGroup"), "(", - protowirePackage.Ident("Number"), "(", f.Desc.Number(), "), ", - protowirePackage.Ident("SizeVarint"), "(", name, "[i]))") - } - g.P("}") - case f.Desc.IsList(): - if m.RepeatedDouble { - g.P("n, _ = proto.Repeated", m.Prefix, "Size(", f.Desc.Number(), ", ", name, ")") - g.P("size += n") - } else { - g.P("size += proto.Repeated", m.Prefix, "Size(", f.Desc.Number(), ", ", name, ")") - } - default: - g.P("size += proto.", m.Prefix, "Size(", f.Desc.Number(), ", ", name, ")") - } -} - -func emitFieldMarshal(g *protogen.GeneratedFile, f *protogen.Field) { - m := marshalers[f.Desc.Kind()] - if m.Prefix == "" { - g.P("// FIXME missing field marshaler: ", f.GoName, " of type ", f.Desc.Kind().String()) - g.P(`panic("unimplemented")`) - return - } - - name := castFieldName(f) - if f.Oneof != nil { - name = "x." + f.Oneof.GoName - g.P("if inner, ok := ", name, ".(*", f.GoIdent.GoName, "); ok {") - defer g.P("}") - name = "inner." + f.GoName - } - - prefix := m.Prefix - if f.Desc.IsList() { - prefix = "Repeated" + m.Prefix - } - switch { - case f.Desc.IsList() && (f.Desc.Kind() == protoreflect.MessageKind || f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()): - g.P("for i := range ", name, "{") - if f.Desc.Kind() == protoreflect.MessageKind { - g.P("offset += proto.NestedStructureMarshal(", f.Desc.Number(), ", buf[offset:], ", name, "[i])") - } else { - if f.Desc.Kind() != protoreflect.Uint64Kind { - panic("only uint64 unpacked primitive is supported") - } - g.P("{") - g.P("prefix := ", protowirePackage.Ident("EncodeTag"), "(", - protowirePackage.Ident("Number"), "(", f.Desc.Number(), "), ", - protowirePackage.Ident("VarintType"), ")") - g.P("offset += ", binaryPackage.Ident("PutUvarint"), "(buf[offset:], uint64(prefix))") - g.P("offset += ", binaryPackage.Ident("PutUvarint"), "(buf[offset:], ", name, "[i])") - g.P("}") - } - g.P("}") - case f.Desc.IsList(): - g.P("offset += proto.Repeated", m.Prefix, "Marshal(", f.Desc.Number(), ", buf[offset:], ", name, ")") - default: - g.P("offset += proto.", prefix, "Marshal(", f.Desc.Number(), ", buf[offset:], ", name, ")") - } -} - -func castFieldName(f *protogen.Field) string { - name := "x." + f.GoName - if f.Desc.Kind() != protoreflect.EnumKind { - return name - } - return "int32(" + name + ")" -} - -type marshalerDesc struct { - Prefix string - RepeatedDouble bool -} - -// Unused kinds are commented. -var marshalers = map[protoreflect.Kind]marshalerDesc{ - protoreflect.BoolKind: {Prefix: "Bool"}, - protoreflect.EnumKind: {Prefix: "Enum"}, - - protoreflect.Int32Kind: {Prefix: "Int32", RepeatedDouble: true}, - // protoreflect.Sint32Kind: "", - protoreflect.Uint32Kind: {Prefix: "UInt32", RepeatedDouble: true}, - protoreflect.Int64Kind: {Prefix: "Int64", RepeatedDouble: true}, - // protoreflect.Sint64Kind: "", - protoreflect.Uint64Kind: {Prefix: "UInt64", RepeatedDouble: true}, - // protoreflect.Sfixed32Kind: "", - protoreflect.Fixed32Kind: {Prefix: "Fixed32", RepeatedDouble: true}, - // protoreflect.FloatKind: "", - // protoreflect.Sfixed64Kind: "", - protoreflect.Fixed64Kind: {Prefix: "Fixed64", RepeatedDouble: true}, - protoreflect.DoubleKind: {Prefix: "Float64"}, - protoreflect.StringKind: {Prefix: "String"}, - protoreflect.BytesKind: {Prefix: "Bytes"}, - protoreflect.MessageKind: {Prefix: "NestedStructure"}, - // protoreflect.GroupKind: "", -} - -func sortFields(fs []*protogen.Field) []*protogen.Field { - res := make([]*protogen.Field, len(fs)) - copy(res, fs) - sort.Slice(res, func(i, j int) bool { - return res[i].Desc.Number() < res[j].Desc.Number() - }) - return res -} diff --git a/util/signature/data.go b/util/signature/data.go index 5e7c310..62c3eaf 100644 --- a/util/signature/data.go +++ b/util/signature/data.go @@ -63,12 +63,6 @@ func SignDataWithHandler(key *ecdsa.PrivateKey, src DataSource, handler KeySigna } func VerifyDataWithSource(dataSrc DataSource, sigSrc KeySignatureSource, opts ...SignOption) error { - cfg := defaultCfg() - - for i := range opts { - opts[i](cfg) - } - buffer := buffersPool.Get(uint32(dataSrc.SignedDataSize())) defer buffersPool.Put(buffer) @@ -77,7 +71,7 @@ func VerifyDataWithSource(dataSrc DataSource, sigSrc KeySignatureSource, opts .. return err } - return verify(cfg, data, sigSrc()) + return VerifyDataSlice(data, sigSrc, opts...) } func SignData(key *ecdsa.PrivateKey, v DataWithSignature, opts ...SignOption) error { @@ -87,3 +81,13 @@ func SignData(key *ecdsa.PrivateKey, v DataWithSignature, opts ...SignOption) er func VerifyData(src DataWithSignature, opts ...SignOption) error { return VerifyDataWithSource(src, src.GetSignature, opts...) } + +func VerifyDataSlice(data []byte, sigSrc KeySignatureSource, opts ...SignOption) error { + cfg := defaultCfg() + + for i := range opts { + opts[i](cfg) + } + + return verify(cfg, data, sigSrc()) +}