diff --git a/internal/evaluator/builder.go b/internal/evaluator/builder.go index 6e44b6a..509802a 100644 --- a/internal/evaluator/builder.go +++ b/internal/evaluator/builder.go @@ -235,6 +235,7 @@ func (bldr *Builder) buildValue( bldr.processEnumConstraints, bldr.processMapConstraints, bldr.processRepeatedConstraints, + bldr.processTimestampConstraints, } for _, step := range steps { @@ -464,6 +465,29 @@ func (bldr *Builder) processRepeatedConstraints( return nil } +func (bldr *Builder) processTimestampConstraints( + fdesc protoreflect.FieldDescriptor, + fieldConstraints *validate.FieldConstraints, + _ bool, + valEval *value, + _ MessageCache, +) error { + if fdesc.Kind() != protoreflect.MessageKind || + fdesc.Message().FullName() != "google.protobuf.Timestamp" { + return nil + } + + secondsDesc := fdesc.Message().Fields().ByName("seconds") + nanosDesc := fdesc.Message().Fields().ByName("nanos") + timestampEval := timestampPB{ + SecondsDescriptor: secondsDesc, + NanosDescriptor: nanosDesc, + Valid: fieldConstraints.GetTimestamp().GetValid(), + } + valEval.Append(timestampEval) + return nil +} + type MessageCache map[protoreflect.MessageDescriptor]*message func (c MessageCache) Clone() MessageCache { diff --git a/internal/evaluator/timestamp.go b/internal/evaluator/timestamp.go new file mode 100644 index 0000000..cd33234 --- /dev/null +++ b/internal/evaluator/timestamp.go @@ -0,0 +1,64 @@ +// Copyright 2023 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package evaluator + +import ( + "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" + "github.com/bufbuild/protovalidate-go/internal/errors" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/known/timestamppb" +) + +// timestampPB is a specialized evaluator for applying some validate.TimestampRules (only the +// `valid` rule currently) to a google.protobuf.Timestamp message. This is handled outside +// CEL which handles google.protobuf.Timestamp as an abstract type, thus not allowing access +// to the message fields. +type timestampPB struct { + SecondsDescriptor protoreflect.FieldDescriptor + NanosDescriptor protoreflect.FieldDescriptor + Valid bool +} + +func (t timestampPB) Evaluate(val protoreflect.Value, failFast bool) error { + seconds := val.Message().Get(t.SecondsDescriptor).Int() + nanos := val.Message().Get(t.NanosDescriptor).Int() + + timestamp := ×tamppb.Timestamp{Seconds: seconds, Nanos: int32(nanos)} + + err := &errors.ValidationError{Violations: []*validate.Violation{}} + if t.Valid { + terr := timestamp.CheckValid() + if terr != nil { + err.Violations = append(err.Violations, &validate.Violation{ + ConstraintId: "timestamp.valid", + Message: terr.Error(), + }) + if failFast { + return err + } + } + } + + if len(err.Violations) > 0 { + return err + } + return nil +} + +func (t timestampPB) Tautology() bool { + return !t.Valid +} + +var _ evaluator = timestampPB{} diff --git a/internal/gen/tests/example/v1/validations.pb.go b/internal/gen/tests/example/v1/validations.pb.go index 8787061..54e30b0 100644 --- a/internal/gen/tests/example/v1/validations.pb.go +++ b/internal/gen/tests/example/v1/validations.pb.go @@ -26,6 +26,7 @@ import ( protoimpl "google.golang.org/protobuf/runtime/protoimpl" apipb "google.golang.org/protobuf/types/known/apipb" fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" reflect "reflect" sync "sync" ) @@ -556,6 +557,53 @@ func (x *MultipleStepsTransitiveFieldConstraints) GetApi() *apipb.Api { return nil } +type MsgHasTimestamp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Timestamp *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` +} + +func (x *MsgHasTimestamp) Reset() { + *x = MsgHasTimestamp{} + if protoimpl.UnsafeEnabled { + mi := &file_tests_example_v1_validations_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgHasTimestamp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgHasTimestamp) ProtoMessage() {} + +func (x *MsgHasTimestamp) ProtoReflect() protoreflect.Message { + mi := &file_tests_example_v1_validations_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MsgHasTimestamp.ProtoReflect.Descriptor instead. +func (*MsgHasTimestamp) Descriptor() ([]byte, []int) { + return file_tests_example_v1_validations_proto_rawDescGZIP(), []int{9} +} + +func (x *MsgHasTimestamp) GetTimestamp() *timestamppb.Timestamp { + if x != nil { + return x.Timestamp + } + return nil +} + var File_tests_example_v1_validations_proto protoreflect.FileDescriptor var file_tests_example_v1_validations_proto_rawDesc = []byte{ @@ -568,141 +616,149 @@ var file_tests_example_v1_validations_proto_rawDesc = []byte{ 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x6d, 0x61, 0x73, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0x8d, 0x02, 0x0a, 0x0b, 0x48, 0x61, 0x73, 0x4d, 0x73, 0x67, 0x45, 0x78, 0x70, 0x72, 0x73, - 0x12, 0x7f, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x42, 0x71, 0xba, 0x48, 0x6e, - 0xba, 0x01, 0x27, 0x0a, 0x06, 0x78, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x12, 0x0e, 0x78, 0x20, 0x6d, - 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x1a, 0x0d, 0x74, 0x68, 0x69, - 0x73, 0x20, 0x25, 0x20, 0x32, 0x20, 0x3d, 0x3d, 0x20, 0x30, 0xba, 0x01, 0x41, 0x0a, 0x0b, 0x78, - 0x5f, 0x63, 0x6f, 0x70, 0x72, 0x69, 0x6d, 0x65, 0x5f, 0x33, 0x1a, 0x32, 0x74, 0x68, 0x69, 0x73, - 0x20, 0x25, 0x20, 0x33, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x20, 0x3f, 0x20, 0x27, 0x27, 0x3a, 0x20, - 0x27, 0x78, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x64, - 0x69, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x20, 0x62, 0x79, 0x20, 0x33, 0x27, 0x52, 0x01, - 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x3a, - 0x6f, 0xba, 0x48, 0x6c, 0x1a, 0x30, 0x0a, 0x06, 0x78, 0x5f, 0x6c, 0x74, 0x5f, 0x79, 0x12, 0x15, - 0x78, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x74, - 0x68, 0x61, 0x6e, 0x20, 0x79, 0x1a, 0x0f, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x78, 0x20, 0x3c, 0x20, - 0x74, 0x68, 0x69, 0x73, 0x2e, 0x79, 0x1a, 0x38, 0x0a, 0x07, 0x79, 0x5f, 0x67, 0x74, 0x5f, 0x34, - 0x32, 0x1a, 0x2d, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x79, 0x20, 0x3e, 0x20, 0x34, 0x32, 0x20, 0x3f, - 0x20, 0x27, 0x27, 0x3a, 0x20, 0x27, 0x79, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, - 0x67, 0x72, 0x65, 0x61, 0x74, 0x65, 0x72, 0x20, 0x74, 0x68, 0x61, 0x6e, 0x20, 0x34, 0x32, 0x27, - 0x22, 0xfe, 0x01, 0x0a, 0x0d, 0x53, 0x65, 0x6c, 0x66, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, - 0x76, 0x65, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78, - 0x12, 0x8d, 0x01, 0x0a, 0x06, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x1f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x6c, 0x66, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, - 0x76, 0x65, 0x42, 0x54, 0xba, 0x48, 0x51, 0xba, 0x01, 0x4e, 0x0a, 0x14, 0x6e, 0x6f, 0x6e, 0x5f, - 0x7a, 0x65, 0x72, 0x6f, 0x5f, 0x62, 0x61, 0x62, 0x79, 0x5f, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, - 0x12, 0x2a, 0x65, 0x6d, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x74, 0x75, 0x72, 0x74, 0x6c, - 0x65, 0x27, 0x73, 0x20, 0x78, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x6d, 0x75, 0x73, 0x74, - 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x7a, 0x65, 0x72, 0x6f, 0x1a, 0x0a, 0x74, 0x68, - 0x69, 0x73, 0x2e, 0x78, 0x20, 0x3e, 0x20, 0x30, 0x52, 0x06, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, - 0x3a, 0x4f, 0xba, 0x48, 0x4c, 0x1a, 0x4a, 0x0a, 0x0e, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x5f, - 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, 0x73, 0x12, 0x1f, 0x61, 0x64, 0x6a, 0x61, 0x63, 0x65, 0x6e, - 0x74, 0x20, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, 0x73, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, - 0x65, 0x20, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x1a, 0x17, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x78, - 0x20, 0x21, 0x3d, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, 0x2e, - 0x78, 0x22, 0x40, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, - 0x76, 0x65, 0x41, 0x12, 0x2e, 0x0a, 0x01, 0x62, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, - 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, - 0x31, 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x42, - 0x52, 0x01, 0x62, 0x22, 0x40, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, - 0x73, 0x69, 0x76, 0x65, 0x42, 0x12, 0x2e, 0x0a, 0x01, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x20, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, - 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, - 0x65, 0x41, 0x52, 0x01, 0x61, 0x22, 0xfb, 0x01, 0x0a, 0x0b, 0x4d, 0x73, 0x67, 0x48, 0x61, 0x73, - 0x4f, 0x6e, 0x65, 0x6f, 0x66, 0x12, 0x1a, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x42, 0x0a, 0xba, 0x48, 0x07, 0x72, 0x05, 0x3a, 0x03, 0x66, 0x6f, 0x6f, 0x48, 0x00, 0x52, 0x01, - 0x78, 0x12, 0x17, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x42, 0x07, 0xba, 0x48, - 0x04, 0x1a, 0x02, 0x20, 0x00, 0x48, 0x00, 0x52, 0x01, 0x79, 0x12, 0x31, 0x0a, 0x03, 0x6d, 0x73, - 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x61, 0x73, 0x4d, 0x73, - 0x67, 0x45, 0x78, 0x70, 0x72, 0x73, 0x48, 0x00, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x3a, 0x78, 0xba, - 0x48, 0x75, 0x1a, 0x5c, 0x0a, 0x06, 0x74, 0x65, 0x73, 0x74, 0x20, 0x78, 0x1a, 0x52, 0x74, 0x68, - 0x69, 0x73, 0x2e, 0x78, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x3f, 0x20, 0x27, 0x27, 0x20, - 0x3a, 0x20, 0x0a, 0x21, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x78, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, - 0x73, 0x57, 0x69, 0x74, 0x68, 0x28, 0x27, 0x66, 0x6f, 0x6f, 0x27, 0x29, 0x20, 0x3f, 0x20, 0x27, - 0x64, 0x6f, 0x65, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x70, 0x72, - 0x65, 0x66, 0x69, 0x78, 0x20, 0x60, 0x66, 0x6f, 0x6f, 0x60, 0x27, 0x20, 0x3a, 0x20, 0x27, 0x27, - 0x1a, 0x15, 0x0a, 0x06, 0x74, 0x65, 0x78, 0x74, 0x20, 0x79, 0x1a, 0x0b, 0x74, 0x68, 0x69, 0x73, - 0x2e, 0x79, 0x20, 0x3e, 0x3d, 0x20, 0x30, 0x42, 0x0a, 0x0a, 0x01, 0x6f, 0x12, 0x05, 0xba, 0x48, - 0x02, 0x08, 0x01, 0x22, 0xa0, 0x01, 0x0a, 0x0e, 0x4d, 0x73, 0x67, 0x48, 0x61, 0x73, 0x52, 0x65, - 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x3f, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x02, 0x42, 0x31, 0xba, 0x48, 0x2e, 0x92, 0x01, 0x2b, 0x08, 0x01, 0x10, 0x03, 0x18, 0x01, 0x22, - 0x23, 0xba, 0x01, 0x19, 0x12, 0x11, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x6f, 0x6e, 0x61, - 0x6c, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x1a, 0x04, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x05, 0x25, - 0x00, 0x00, 0x00, 0x00, 0x52, 0x01, 0x78, 0x12, 0x16, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x03, - 0x28, 0x09, 0x42, 0x08, 0xba, 0x48, 0x05, 0x92, 0x01, 0x02, 0x18, 0x01, 0x52, 0x01, 0x79, 0x12, - 0x35, 0x0a, 0x01, 0x7a, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x65, 0x73, - 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x61, - 0x73, 0x4d, 0x73, 0x67, 0x45, 0x78, 0x70, 0x72, 0x73, 0x42, 0x08, 0xba, 0x48, 0x05, 0x92, 0x01, - 0x02, 0x10, 0x02, 0x52, 0x01, 0x7a, 0x22, 0xf1, 0x03, 0x0a, 0x09, 0x4d, 0x73, 0x67, 0x48, 0x61, - 0x73, 0x4d, 0x61, 0x70, 0x12, 0x5b, 0x0a, 0x08, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x6d, 0x61, 0x70, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, + 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x8d, 0x02, 0x0a, 0x0b, 0x48, 0x61, 0x73, 0x4d, 0x73, 0x67, 0x45, 0x78, 0x70, 0x72, + 0x73, 0x12, 0x7f, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x42, 0x71, 0xba, 0x48, + 0x6e, 0xba, 0x01, 0x27, 0x0a, 0x06, 0x78, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x12, 0x0e, 0x78, 0x20, + 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x1a, 0x0d, 0x74, 0x68, + 0x69, 0x73, 0x20, 0x25, 0x20, 0x32, 0x20, 0x3d, 0x3d, 0x20, 0x30, 0xba, 0x01, 0x41, 0x0a, 0x0b, + 0x78, 0x5f, 0x63, 0x6f, 0x70, 0x72, 0x69, 0x6d, 0x65, 0x5f, 0x33, 0x1a, 0x32, 0x74, 0x68, 0x69, + 0x73, 0x20, 0x25, 0x20, 0x33, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x20, 0x3f, 0x20, 0x27, 0x27, 0x3a, + 0x20, 0x27, 0x78, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, + 0x64, 0x69, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x20, 0x62, 0x79, 0x20, 0x33, 0x27, 0x52, + 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, + 0x3a, 0x6f, 0xba, 0x48, 0x6c, 0x1a, 0x30, 0x0a, 0x06, 0x78, 0x5f, 0x6c, 0x74, 0x5f, 0x79, 0x12, + 0x15, 0x78, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x6c, 0x65, 0x73, 0x73, 0x20, + 0x74, 0x68, 0x61, 0x6e, 0x20, 0x79, 0x1a, 0x0f, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x78, 0x20, 0x3c, + 0x20, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x79, 0x1a, 0x38, 0x0a, 0x07, 0x79, 0x5f, 0x67, 0x74, 0x5f, + 0x34, 0x32, 0x1a, 0x2d, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x79, 0x20, 0x3e, 0x20, 0x34, 0x32, 0x20, + 0x3f, 0x20, 0x27, 0x27, 0x3a, 0x20, 0x27, 0x79, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, + 0x20, 0x67, 0x72, 0x65, 0x61, 0x74, 0x65, 0x72, 0x20, 0x74, 0x68, 0x61, 0x6e, 0x20, 0x34, 0x32, + 0x27, 0x22, 0xfe, 0x01, 0x0a, 0x0d, 0x53, 0x65, 0x6c, 0x66, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, + 0x69, 0x76, 0x65, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, + 0x78, 0x12, 0x8d, 0x01, 0x0a, 0x06, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, + 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x6c, 0x66, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, + 0x69, 0x76, 0x65, 0x42, 0x54, 0xba, 0x48, 0x51, 0xba, 0x01, 0x4e, 0x0a, 0x14, 0x6e, 0x6f, 0x6e, + 0x5f, 0x7a, 0x65, 0x72, 0x6f, 0x5f, 0x62, 0x61, 0x62, 0x79, 0x5f, 0x74, 0x75, 0x72, 0x74, 0x6c, + 0x65, 0x12, 0x2a, 0x65, 0x6d, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x74, 0x75, 0x72, 0x74, + 0x6c, 0x65, 0x27, 0x73, 0x20, 0x78, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x6d, 0x75, 0x73, + 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x7a, 0x65, 0x72, 0x6f, 0x1a, 0x0a, 0x74, + 0x68, 0x69, 0x73, 0x2e, 0x78, 0x20, 0x3e, 0x20, 0x30, 0x52, 0x06, 0x74, 0x75, 0x72, 0x74, 0x6c, + 0x65, 0x3a, 0x4f, 0xba, 0x48, 0x4c, 0x1a, 0x4a, 0x0a, 0x0e, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, + 0x5f, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, 0x73, 0x12, 0x1f, 0x61, 0x64, 0x6a, 0x61, 0x63, 0x65, + 0x6e, 0x74, 0x20, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, 0x73, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, + 0x62, 0x65, 0x20, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x1a, 0x17, 0x74, 0x68, 0x69, 0x73, 0x2e, + 0x78, 0x20, 0x21, 0x3d, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x74, 0x75, 0x72, 0x74, 0x6c, 0x65, + 0x2e, 0x78, 0x22, 0x40, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, + 0x69, 0x76, 0x65, 0x41, 0x12, 0x2e, 0x0a, 0x01, 0x62, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x20, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, + 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, + 0x42, 0x52, 0x01, 0x62, 0x22, 0x40, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, + 0x72, 0x73, 0x69, 0x76, 0x65, 0x42, 0x12, 0x2e, 0x0a, 0x01, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x20, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, + 0x76, 0x65, 0x41, 0x52, 0x01, 0x61, 0x22, 0xfb, 0x01, 0x0a, 0x0b, 0x4d, 0x73, 0x67, 0x48, 0x61, + 0x73, 0x4f, 0x6e, 0x65, 0x6f, 0x66, 0x12, 0x1a, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x0a, 0xba, 0x48, 0x07, 0x72, 0x05, 0x3a, 0x03, 0x66, 0x6f, 0x6f, 0x48, 0x00, 0x52, + 0x01, 0x78, 0x12, 0x17, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x42, 0x07, 0xba, + 0x48, 0x04, 0x1a, 0x02, 0x20, 0x00, 0x48, 0x00, 0x52, 0x01, 0x79, 0x12, 0x31, 0x0a, 0x03, 0x6d, + 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, + 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x61, 0x73, 0x4d, + 0x73, 0x67, 0x45, 0x78, 0x70, 0x72, 0x73, 0x48, 0x00, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x3a, 0x78, + 0xba, 0x48, 0x75, 0x1a, 0x5c, 0x0a, 0x06, 0x74, 0x65, 0x73, 0x74, 0x20, 0x78, 0x1a, 0x52, 0x74, + 0x68, 0x69, 0x73, 0x2e, 0x78, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x3f, 0x20, 0x27, 0x27, + 0x20, 0x3a, 0x20, 0x0a, 0x21, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x78, 0x2e, 0x73, 0x74, 0x61, 0x72, + 0x74, 0x73, 0x57, 0x69, 0x74, 0x68, 0x28, 0x27, 0x66, 0x6f, 0x6f, 0x27, 0x29, 0x20, 0x3f, 0x20, + 0x27, 0x64, 0x6f, 0x65, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x70, + 0x72, 0x65, 0x66, 0x69, 0x78, 0x20, 0x60, 0x66, 0x6f, 0x6f, 0x60, 0x27, 0x20, 0x3a, 0x20, 0x27, + 0x27, 0x1a, 0x15, 0x0a, 0x06, 0x74, 0x65, 0x78, 0x74, 0x20, 0x79, 0x1a, 0x0b, 0x74, 0x68, 0x69, + 0x73, 0x2e, 0x79, 0x20, 0x3e, 0x3d, 0x20, 0x30, 0x42, 0x0a, 0x0a, 0x01, 0x6f, 0x12, 0x05, 0xba, + 0x48, 0x02, 0x08, 0x01, 0x22, 0xa0, 0x01, 0x0a, 0x0e, 0x4d, 0x73, 0x67, 0x48, 0x61, 0x73, 0x52, + 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x3f, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x02, 0x42, 0x31, 0xba, 0x48, 0x2e, 0x92, 0x01, 0x2b, 0x08, 0x01, 0x10, 0x03, 0x18, 0x01, + 0x22, 0x23, 0xba, 0x01, 0x19, 0x12, 0x11, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x6f, 0x6e, + 0x61, 0x6c, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x1a, 0x04, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x05, + 0x25, 0x00, 0x00, 0x00, 0x00, 0x52, 0x01, 0x78, 0x12, 0x16, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, + 0x03, 0x28, 0x09, 0x42, 0x08, 0xba, 0x48, 0x05, 0x92, 0x01, 0x02, 0x18, 0x01, 0x52, 0x01, 0x79, + 0x12, 0x35, 0x0a, 0x01, 0x7a, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x65, + 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x48, + 0x61, 0x73, 0x4d, 0x73, 0x67, 0x45, 0x78, 0x70, 0x72, 0x73, 0x42, 0x08, 0xba, 0x48, 0x05, 0x92, + 0x01, 0x02, 0x10, 0x02, 0x52, 0x01, 0x7a, 0x22, 0xf1, 0x03, 0x0a, 0x09, 0x4d, 0x73, 0x67, 0x48, + 0x61, 0x73, 0x4d, 0x61, 0x70, 0x12, 0x5b, 0x0a, 0x08, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x6d, 0x61, + 0x70, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, + 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x48, 0x61, + 0x73, 0x4d, 0x61, 0x70, 0x2e, 0x49, 0x6e, 0x74, 0x33, 0x32, 0x6d, 0x61, 0x70, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x42, 0x14, 0xba, 0x48, 0x11, 0x9a, 0x01, 0x0e, 0x08, 0x03, 0x22, 0x04, 0x1a, 0x02, + 0x20, 0x00, 0x2a, 0x04, 0x1a, 0x02, 0x10, 0x00, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x6d, + 0x61, 0x70, 0x12, 0x53, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x70, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x48, 0x61, 0x73, - 0x4d, 0x61, 0x70, 0x2e, 0x49, 0x6e, 0x74, 0x33, 0x32, 0x6d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x42, 0x14, 0xba, 0x48, 0x11, 0x9a, 0x01, 0x0e, 0x08, 0x03, 0x22, 0x04, 0x1a, 0x02, 0x20, - 0x00, 0x2a, 0x04, 0x1a, 0x02, 0x10, 0x00, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x6d, 0x61, - 0x70, 0x12, 0x53, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x70, 0x18, - 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x48, 0x61, 0x73, 0x4d, - 0x61, 0x70, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x42, 0x08, 0xba, 0x48, 0x05, 0x9a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x09, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x4d, 0x61, 0x70, 0x12, 0x56, 0x0a, 0x0b, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x74, 0x65, - 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4d, - 0x73, 0x67, 0x48, 0x61, 0x73, 0x4d, 0x61, 0x70, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x42, 0x08, 0xba, 0x48, 0x05, 0x9a, 0x01, 0x02, - 0x08, 0x02, 0x52, 0x0a, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4d, 0x61, 0x70, 0x1a, 0x3b, - 0x0a, 0x0d, 0x49, 0x6e, 0x74, 0x33, 0x32, 0x6d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, - 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, - 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3c, 0x0a, 0x0e, 0x53, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x5f, 0x0a, 0x0f, 0x4d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x36, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, - 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, - 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x41, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x8e, 0x01, 0x0a, 0x19, 0x54, - 0x72, 0x61, 0x6e, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x43, 0x6f, - 0x6e, 0x73, 0x74, 0x72, 0x61, 0x69, 0x6e, 0x74, 0x12, 0x71, 0x0a, 0x04, 0x6d, 0x61, 0x73, 0x6b, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4d, 0x61, - 0x73, 0x6b, 0x42, 0x41, 0xba, 0x48, 0x3e, 0xba, 0x01, 0x3b, 0x0a, 0x0a, 0x6d, 0x61, 0x73, 0x6b, - 0x2e, 0x70, 0x61, 0x74, 0x68, 0x73, 0x12, 0x1c, 0x6d, 0x61, 0x73, 0x6b, 0x2e, 0x70, 0x61, 0x74, - 0x68, 0x73, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x65, - 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0f, 0x68, 0x61, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x70, - 0x61, 0x74, 0x68, 0x73, 0x29, 0x52, 0x04, 0x6d, 0x61, 0x73, 0x6b, 0x22, 0xce, 0x01, 0x0a, 0x27, - 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x53, 0x74, 0x65, 0x70, 0x73, 0x54, 0x72, 0x61, - 0x6e, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x43, 0x6f, 0x6e, 0x73, - 0x74, 0x72, 0x61, 0x69, 0x6e, 0x74, 0x73, 0x12, 0xa2, 0x01, 0x0a, 0x03, 0x61, 0x70, 0x69, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x70, 0x69, 0x42, 0x7a, 0xba, 0x48, 0x77, - 0xba, 0x01, 0x74, 0x0a, 0x1c, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, - 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x6e, 0x61, 0x6d, - 0x65, 0x12, 0x30, 0x61, 0x70, 0x69, 0x27, 0x73, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, - 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x6e, 0x61, 0x6d, - 0x65, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x65, 0x6d, - 0x70, 0x74, 0x79, 0x1a, 0x22, 0x68, 0x61, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x2e, 0x66, 0x69, 0x6c, - 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x52, 0x03, 0x61, 0x70, 0x69, 0x42, 0xd8, 0x01, 0x0a, - 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x10, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x4c, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2d, 0x67, 0x6f, 0x2f, - 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x74, 0x65, 0x73, - 0x74, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x54, 0x45, 0x58, 0xaa, 0x02, 0x10, - 0x54, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x56, 0x31, - 0xca, 0x02, 0x10, 0x54, 0x65, 0x73, 0x74, 0x73, 0x5c, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, - 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x54, 0x65, 0x73, 0x74, 0x73, 0x5c, 0x45, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0xea, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x73, 0x3a, 0x3a, 0x45, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x4d, 0x61, 0x70, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x42, 0x08, 0xba, 0x48, 0x05, 0x9a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x09, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x61, 0x70, 0x12, 0x56, 0x0a, 0x0b, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, + 0x4d, 0x73, 0x67, 0x48, 0x61, 0x73, 0x4d, 0x61, 0x70, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x42, 0x08, 0xba, 0x48, 0x05, 0x9a, 0x01, + 0x02, 0x08, 0x02, 0x52, 0x0a, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4d, 0x61, 0x70, 0x1a, + 0x3b, 0x0a, 0x0d, 0x49, 0x6e, 0x74, 0x33, 0x32, 0x6d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3c, 0x0a, 0x0e, + 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x5f, 0x0a, 0x0f, 0x4d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x36, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, + 0x31, 0x2e, 0x4c, 0x6f, 0x6f, 0x70, 0x52, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x41, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x8e, 0x01, 0x0a, 0x19, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x43, + 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x61, 0x69, 0x6e, 0x74, 0x12, 0x71, 0x0a, 0x04, 0x6d, 0x61, 0x73, + 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4d, + 0x61, 0x73, 0x6b, 0x42, 0x41, 0xba, 0x48, 0x3e, 0xba, 0x01, 0x3b, 0x0a, 0x0a, 0x6d, 0x61, 0x73, + 0x6b, 0x2e, 0x70, 0x61, 0x74, 0x68, 0x73, 0x12, 0x1c, 0x6d, 0x61, 0x73, 0x6b, 0x2e, 0x70, 0x61, + 0x74, 0x68, 0x73, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, + 0x65, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0f, 0x68, 0x61, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2e, + 0x70, 0x61, 0x74, 0x68, 0x73, 0x29, 0x52, 0x04, 0x6d, 0x61, 0x73, 0x6b, 0x22, 0xce, 0x01, 0x0a, + 0x27, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x53, 0x74, 0x65, 0x70, 0x73, 0x54, 0x72, + 0x61, 0x6e, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x43, 0x6f, 0x6e, + 0x73, 0x74, 0x72, 0x61, 0x69, 0x6e, 0x74, 0x73, 0x12, 0xa2, 0x01, 0x0a, 0x03, 0x61, 0x70, 0x69, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x70, 0x69, 0x42, 0x7a, 0xba, 0x48, + 0x77, 0xba, 0x01, 0x74, 0x0a, 0x1c, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x30, 0x61, 0x70, 0x69, 0x27, 0x73, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x65, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x22, 0x68, 0x61, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x73, + 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x2e, 0x66, 0x69, + 0x6c, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x52, 0x03, 0x61, 0x70, 0x69, 0x22, 0x55, 0x0a, + 0x0f, 0x4d, 0x73, 0x67, 0x48, 0x61, 0x73, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x12, 0x42, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, + 0x08, 0xba, 0x48, 0x05, 0xb2, 0x01, 0x02, 0x50, 0x01, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x42, 0xd8, 0x01, 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x73, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x10, 0x56, + 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x4c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, + 0x66, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x76, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x65, 0x2d, 0x67, 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, + 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x76, 0x31, 0xa2, + 0x02, 0x03, 0x54, 0x45, 0x58, 0xaa, 0x02, 0x10, 0x54, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x45, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x10, 0x54, 0x65, 0x73, 0x74, 0x73, + 0x5c, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x54, 0x65, + 0x73, 0x74, 0x73, 0x5c, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, + 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x12, 0x54, 0x65, 0x73, + 0x74, 0x73, 0x3a, 0x3a, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -717,7 +773,7 @@ func file_tests_example_v1_validations_proto_rawDescGZIP() []byte { return file_tests_example_v1_validations_proto_rawDescData } -var file_tests_example_v1_validations_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_tests_example_v1_validations_proto_msgTypes = make([]protoimpl.MessageInfo, 13) var file_tests_example_v1_validations_proto_goTypes = []interface{}{ (*HasMsgExprs)(nil), // 0: tests.example.v1.HasMsgExprs (*SelfRecursive)(nil), // 1: tests.example.v1.SelfRecursive @@ -728,11 +784,13 @@ var file_tests_example_v1_validations_proto_goTypes = []interface{}{ (*MsgHasMap)(nil), // 6: tests.example.v1.MsgHasMap (*TransitiveFieldConstraint)(nil), // 7: tests.example.v1.TransitiveFieldConstraint (*MultipleStepsTransitiveFieldConstraints)(nil), // 8: tests.example.v1.MultipleStepsTransitiveFieldConstraints - nil, // 9: tests.example.v1.MsgHasMap.Int32mapEntry - nil, // 10: tests.example.v1.MsgHasMap.StringMapEntry - nil, // 11: tests.example.v1.MsgHasMap.MessageMapEntry - (*fieldmaskpb.FieldMask)(nil), // 12: google.protobuf.FieldMask - (*apipb.Api)(nil), // 13: google.protobuf.Api + (*MsgHasTimestamp)(nil), // 9: tests.example.v1.MsgHasTimestamp + nil, // 10: tests.example.v1.MsgHasMap.Int32mapEntry + nil, // 11: tests.example.v1.MsgHasMap.StringMapEntry + nil, // 12: tests.example.v1.MsgHasMap.MessageMapEntry + (*fieldmaskpb.FieldMask)(nil), // 13: google.protobuf.FieldMask + (*apipb.Api)(nil), // 14: google.protobuf.Api + (*timestamppb.Timestamp)(nil), // 15: google.protobuf.Timestamp } var file_tests_example_v1_validations_proto_depIdxs = []int32{ 1, // 0: tests.example.v1.SelfRecursive.turtle:type_name -> tests.example.v1.SelfRecursive @@ -740,17 +798,18 @@ var file_tests_example_v1_validations_proto_depIdxs = []int32{ 2, // 2: tests.example.v1.LoopRecursiveB.a:type_name -> tests.example.v1.LoopRecursiveA 0, // 3: tests.example.v1.MsgHasOneof.msg:type_name -> tests.example.v1.HasMsgExprs 0, // 4: tests.example.v1.MsgHasRepeated.z:type_name -> tests.example.v1.HasMsgExprs - 9, // 5: tests.example.v1.MsgHasMap.int32map:type_name -> tests.example.v1.MsgHasMap.Int32mapEntry - 10, // 6: tests.example.v1.MsgHasMap.string_map:type_name -> tests.example.v1.MsgHasMap.StringMapEntry - 11, // 7: tests.example.v1.MsgHasMap.message_map:type_name -> tests.example.v1.MsgHasMap.MessageMapEntry - 12, // 8: tests.example.v1.TransitiveFieldConstraint.mask:type_name -> google.protobuf.FieldMask - 13, // 9: tests.example.v1.MultipleStepsTransitiveFieldConstraints.api:type_name -> google.protobuf.Api - 2, // 10: tests.example.v1.MsgHasMap.MessageMapEntry.value:type_name -> tests.example.v1.LoopRecursiveA - 11, // [11:11] is the sub-list for method output_type - 11, // [11:11] is the sub-list for method input_type - 11, // [11:11] is the sub-list for extension type_name - 11, // [11:11] is the sub-list for extension extendee - 0, // [0:11] is the sub-list for field type_name + 10, // 5: tests.example.v1.MsgHasMap.int32map:type_name -> tests.example.v1.MsgHasMap.Int32mapEntry + 11, // 6: tests.example.v1.MsgHasMap.string_map:type_name -> tests.example.v1.MsgHasMap.StringMapEntry + 12, // 7: tests.example.v1.MsgHasMap.message_map:type_name -> tests.example.v1.MsgHasMap.MessageMapEntry + 13, // 8: tests.example.v1.TransitiveFieldConstraint.mask:type_name -> google.protobuf.FieldMask + 14, // 9: tests.example.v1.MultipleStepsTransitiveFieldConstraints.api:type_name -> google.protobuf.Api + 15, // 10: tests.example.v1.MsgHasTimestamp.timestamp:type_name -> google.protobuf.Timestamp + 2, // 11: tests.example.v1.MsgHasMap.MessageMapEntry.value:type_name -> tests.example.v1.LoopRecursiveA + 12, // [12:12] is the sub-list for method output_type + 12, // [12:12] is the sub-list for method input_type + 12, // [12:12] is the sub-list for extension type_name + 12, // [12:12] is the sub-list for extension extendee + 0, // [0:12] is the sub-list for field type_name } func init() { file_tests_example_v1_validations_proto_init() } @@ -867,6 +926,18 @@ func file_tests_example_v1_validations_proto_init() { return nil } } + file_tests_example_v1_validations_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgHasTimestamp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } file_tests_example_v1_validations_proto_msgTypes[4].OneofWrappers = []interface{}{ (*MsgHasOneof_X)(nil), @@ -879,7 +950,7 @@ func file_tests_example_v1_validations_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_tests_example_v1_validations_proto_rawDesc, NumEnums: 0, - NumMessages: 12, + NumMessages: 13, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/tests/example/v1/validations.proto b/proto/tests/example/v1/validations.proto index 8248e65..2f50d07 100644 --- a/proto/tests/example/v1/validations.proto +++ b/proto/tests/example/v1/validations.proto @@ -19,6 +19,7 @@ package tests.example.v1; import "buf/validate/validate.proto"; import "google/protobuf/api.proto"; import "google/protobuf/field_mask.proto"; +import "google/protobuf/timestamp.proto"; message HasMsgExprs { option (buf.validate.message).cel = { @@ -140,3 +141,7 @@ message MultipleStepsTransitiveFieldConstraints { expression: "has(this.source_context.file_name)" }]; } + +message MsgHasTimestamp { + google.protobuf.Timestamp timestamp = 1 [(buf.validate.field).timestamp.valid = true]; +} diff --git a/validator_test.go b/validator_test.go index cd5d1ec..6192920 100644 --- a/validator_test.go +++ b/validator_test.go @@ -23,6 +23,7 @@ import ( "google.golang.org/protobuf/types/known/apipb" "google.golang.org/protobuf/types/known/fieldmaskpb" "google.golang.org/protobuf/types/known/sourcecontextpb" + "google.golang.org/protobuf/types/known/timestamppb" ) func TestValidator_Validate(t *testing.T) { @@ -114,6 +115,35 @@ func TestValidator_ValidateRepeatedFoo(t *testing.T) { require.NoError(t, err) } +func TestValidator_ValidateTimestamp(t *testing.T) { + minTimestampSeconds := -62135596800 + maxTimestampSeconds := +253402300799 + t.Parallel() + val, err := New() + require.NoError(t, err) + timestampMessage := &pb.MsgHasTimestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: 0}} + err = val.Validate(timestampMessage) + assert.NoError(t, err) + timestampMessage = &pb.MsgHasTimestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: -1}} + err = val.Validate(timestampMessage) + assert.Error(t, err) + timestampMessage = &pb.MsgHasTimestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: 1e9}} + err = val.Validate(timestampMessage) + assert.Error(t, err) + timestampMessage = &pb.MsgHasTimestamp{Timestamp: ×tamppb.Timestamp{Seconds: int64(minTimestampSeconds), Nanos: 0}} + err = val.Validate(timestampMessage) + assert.NoError(t, err) + timestampMessage = &pb.MsgHasTimestamp{Timestamp: ×tamppb.Timestamp{Seconds: int64(minTimestampSeconds) - 1, Nanos: 0}} + err = val.Validate(timestampMessage) + assert.Error(t, err) + timestampMessage = &pb.MsgHasTimestamp{Timestamp: ×tamppb.Timestamp{Seconds: int64(maxTimestampSeconds), Nanos: 0}} + err = val.Validate(timestampMessage) + assert.NoError(t, err) + timestampMessage = &pb.MsgHasTimestamp{Timestamp: ×tamppb.Timestamp{Seconds: int64(maxTimestampSeconds) + 1, Nanos: 0}} + err = val.Validate(timestampMessage) + assert.Error(t, err) +} + func TestValidator_ValidateMapFoo(t *testing.T) { t.Parallel() val, err := New()