From 5405b7ad28f8df80b08ddd17d60a9178f6334240 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 14 Jun 2023 09:23:35 +0200 Subject: [PATCH] feat: use not-deprecated protobuf package, and move to internal --- examples/go.mod | 2 +- examples/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- ipns/internal/pb/record.pb.go | 281 ++++++++++ ipns/pb/Makefile | 11 - ipns/pb/ipns.pb.go | 992 ---------------------------------- ipns/pb/ipns.proto | 36 -- ipns/proto/record.proto | 21 + ipns/record.go | 21 +- ipns/record_test.go | 10 +- ipns/validation.go | 9 +- 12 files changed, 329 insertions(+), 1064 deletions(-) create mode 100644 ipns/internal/pb/record.pb.go delete mode 100644 ipns/pb/Makefile delete mode 100644 ipns/pb/ipns.pb.go delete mode 100644 ipns/pb/ipns.proto create mode 100644 ipns/proto/record.proto diff --git a/examples/go.mod b/examples/go.mod index 0e3b04d51..ef1bb7c4b 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -162,7 +162,7 @@ require ( gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect google.golang.org/grpc v1.53.0 // indirect - google.golang.org/protobuf v1.28.1 // indirect + google.golang.org/protobuf v1.30.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.1.7 // indirect nhooyr.io/websocket v1.8.7 // indirect diff --git a/examples/go.sum b/examples/go.sum index 0788f632d..b16a8b8be 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1062,8 +1062,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/go.mod b/go.mod index 942c00dd3..032fdf8a9 100644 --- a/go.mod +++ b/go.mod @@ -79,6 +79,7 @@ require ( golang.org/x/oauth2 v0.4.0 golang.org/x/sync v0.1.0 golang.org/x/sys v0.6.0 + google.golang.org/protobuf v1.30.0 ) require ( @@ -170,7 +171,6 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect google.golang.org/grpc v1.53.0 // indirect - google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.1.7 // indirect nhooyr.io/websocket v1.8.7 // indirect diff --git a/go.sum b/go.sum index 10e5df123..f5f1ecf48 100644 --- a/go.sum +++ b/go.sum @@ -1083,8 +1083,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/ipns/internal/pb/record.pb.go b/ipns/internal/pb/record.pb.go new file mode 100644 index 000000000..4e58b998c --- /dev/null +++ b/ipns/internal/pb/record.pb.go @@ -0,0 +1,281 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.30.0 +// protoc v3.21.12 +// source: record.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type IpnsRecord_ValidityType int32 + +const ( + IpnsRecord_EOL IpnsRecord_ValidityType = 0 +) + +// Enum value maps for IpnsRecord_ValidityType. +var ( + IpnsRecord_ValidityType_name = map[int32]string{ + 0: "EOL", + } + IpnsRecord_ValidityType_value = map[string]int32{ + "EOL": 0, + } +) + +func (x IpnsRecord_ValidityType) Enum() *IpnsRecord_ValidityType { + p := new(IpnsRecord_ValidityType) + *p = x + return p +} + +func (x IpnsRecord_ValidityType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (IpnsRecord_ValidityType) Descriptor() protoreflect.EnumDescriptor { + return file_record_proto_enumTypes[0].Descriptor() +} + +func (IpnsRecord_ValidityType) Type() protoreflect.EnumType { + return &file_record_proto_enumTypes[0] +} + +func (x IpnsRecord_ValidityType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use IpnsRecord_ValidityType.Descriptor instead. +func (IpnsRecord_ValidityType) EnumDescriptor() ([]byte, []int) { + return file_record_proto_rawDescGZIP(), []int{0, 0} +} + +type IpnsRecord struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value []byte `protobuf:"bytes,1,opt,name=value,proto3,oneof" json:"value,omitempty"` + SignatureV1 []byte `protobuf:"bytes,2,opt,name=signatureV1,proto3,oneof" json:"signatureV1,omitempty"` + ValidityType *IpnsRecord_ValidityType `protobuf:"varint,3,opt,name=validityType,proto3,enum=ipns.IpnsRecord_ValidityType,oneof" json:"validityType,omitempty"` + Validity []byte `protobuf:"bytes,4,opt,name=validity,proto3,oneof" json:"validity,omitempty"` + Sequence *uint64 `protobuf:"varint,5,opt,name=sequence,proto3,oneof" json:"sequence,omitempty"` + Ttl *uint64 `protobuf:"varint,6,opt,name=ttl,proto3,oneof" json:"ttl,omitempty"` + PubKey []byte `protobuf:"bytes,7,opt,name=pubKey,proto3,oneof" json:"pubKey,omitempty"` + SignatureV2 []byte `protobuf:"bytes,8,opt,name=signatureV2,proto3,oneof" json:"signatureV2,omitempty"` + Data []byte `protobuf:"bytes,9,opt,name=data,proto3,oneof" json:"data,omitempty"` +} + +func (x *IpnsRecord) Reset() { + *x = IpnsRecord{} + if protoimpl.UnsafeEnabled { + mi := &file_record_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IpnsRecord) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IpnsRecord) ProtoMessage() {} + +func (x *IpnsRecord) ProtoReflect() protoreflect.Message { + mi := &file_record_proto_msgTypes[0] + 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 IpnsRecord.ProtoReflect.Descriptor instead. +func (*IpnsRecord) Descriptor() ([]byte, []int) { + return file_record_proto_rawDescGZIP(), []int{0} +} + +func (x *IpnsRecord) GetValue() []byte { + if x != nil { + return x.Value + } + return nil +} + +func (x *IpnsRecord) GetSignatureV1() []byte { + if x != nil { + return x.SignatureV1 + } + return nil +} + +func (x *IpnsRecord) GetValidityType() IpnsRecord_ValidityType { + if x != nil && x.ValidityType != nil { + return *x.ValidityType + } + return IpnsRecord_EOL +} + +func (x *IpnsRecord) GetValidity() []byte { + if x != nil { + return x.Validity + } + return nil +} + +func (x *IpnsRecord) GetSequence() uint64 { + if x != nil && x.Sequence != nil { + return *x.Sequence + } + return 0 +} + +func (x *IpnsRecord) GetTtl() uint64 { + if x != nil && x.Ttl != nil { + return *x.Ttl + } + return 0 +} + +func (x *IpnsRecord) GetPubKey() []byte { + if x != nil { + return x.PubKey + } + return nil +} + +func (x *IpnsRecord) GetSignatureV2() []byte { + if x != nil { + return x.SignatureV2 + } + return nil +} + +func (x *IpnsRecord) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +var File_record_proto protoreflect.FileDescriptor + +var file_record_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, + 0x69, 0x70, 0x6e, 0x73, 0x22, 0xd6, 0x03, 0x0a, 0x0a, 0x49, 0x70, 0x6e, 0x73, 0x52, 0x65, 0x63, + 0x6f, 0x72, 0x64, 0x12, 0x19, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x48, 0x00, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x88, 0x01, 0x01, 0x12, 0x25, + 0x0a, 0x0b, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x56, 0x31, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0c, 0x48, 0x01, 0x52, 0x0b, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x56, 0x31, 0x88, 0x01, 0x01, 0x12, 0x46, 0x0a, 0x0c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, + 0x79, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1d, 0x2e, 0x69, 0x70, + 0x6e, 0x73, 0x2e, 0x49, 0x70, 0x6e, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x56, 0x61, + 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x54, 0x79, 0x70, 0x65, 0x48, 0x02, 0x52, 0x0c, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x54, 0x79, 0x70, 0x65, 0x88, 0x01, 0x01, 0x12, 0x1f, 0x0a, + 0x08, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x48, + 0x03, 0x52, 0x08, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x88, 0x01, 0x01, 0x12, 0x1f, + 0x0a, 0x08, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, + 0x48, 0x04, 0x52, 0x08, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x88, 0x01, 0x01, 0x12, + 0x15, 0x0a, 0x03, 0x74, 0x74, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x48, 0x05, 0x52, 0x03, + 0x74, 0x74, 0x6c, 0x88, 0x01, 0x01, 0x12, 0x1b, 0x0a, 0x06, 0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x06, 0x52, 0x06, 0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, + 0x88, 0x01, 0x01, 0x12, 0x25, 0x0a, 0x0b, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x56, 0x32, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x07, 0x52, 0x0b, 0x73, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x56, 0x32, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x64, 0x61, + 0x74, 0x61, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x08, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x88, 0x01, 0x01, 0x22, 0x17, 0x0a, 0x0c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x07, 0x0a, 0x03, 0x45, 0x4f, 0x4c, 0x10, 0x00, 0x42, 0x08, 0x0a, 0x06, + 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x56, 0x31, 0x42, 0x0f, 0x0a, 0x0d, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, + 0x69, 0x74, 0x79, 0x54, 0x79, 0x70, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x76, 0x61, 0x6c, 0x69, + 0x64, 0x69, 0x74, 0x79, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, + 0x65, 0x42, 0x06, 0x0a, 0x04, 0x5f, 0x74, 0x74, 0x6c, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x70, 0x75, + 0x62, 0x4b, 0x65, 0x79, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, + 0x72, 0x65, 0x56, 0x32, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x42, 0x0f, 0x5a, + 0x0d, 0x2e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_record_proto_rawDescOnce sync.Once + file_record_proto_rawDescData = file_record_proto_rawDesc +) + +func file_record_proto_rawDescGZIP() []byte { + file_record_proto_rawDescOnce.Do(func() { + file_record_proto_rawDescData = protoimpl.X.CompressGZIP(file_record_proto_rawDescData) + }) + return file_record_proto_rawDescData +} + +var file_record_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_record_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_record_proto_goTypes = []interface{}{ + (IpnsRecord_ValidityType)(0), // 0: ipns.IpnsRecord.ValidityType + (*IpnsRecord)(nil), // 1: ipns.IpnsRecord +} +var file_record_proto_depIdxs = []int32{ + 0, // 0: ipns.IpnsRecord.validityType:type_name -> ipns.IpnsRecord.ValidityType + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_record_proto_init() } +func file_record_proto_init() { + if File_record_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_record_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IpnsRecord); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_record_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_record_proto_rawDesc, + NumEnums: 1, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_record_proto_goTypes, + DependencyIndexes: file_record_proto_depIdxs, + EnumInfos: file_record_proto_enumTypes, + MessageInfos: file_record_proto_msgTypes, + }.Build() + File_record_proto = out.File + file_record_proto_rawDesc = nil + file_record_proto_goTypes = nil + file_record_proto_depIdxs = nil +} diff --git a/ipns/pb/Makefile b/ipns/pb/Makefile deleted file mode 100644 index eb14b5768..000000000 --- a/ipns/pb/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -PB = $(wildcard *.proto) -GO = $(PB:.proto=.pb.go) - -all: $(GO) - -%.pb.go: %.proto - protoc --proto_path=$(GOPATH)/src:. --gogofast_out=. $< - -clean: - rm -f *.pb.go - rm -f *.go diff --git a/ipns/pb/ipns.pb.go b/ipns/pb/ipns.pb.go deleted file mode 100644 index 1e2488852..000000000 --- a/ipns/pb/ipns.pb.go +++ /dev/null @@ -1,992 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: ipns.proto - -package ipns_pb - -import ( - fmt "fmt" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type IpnsEntry_ValidityType int32 - -const ( - // setting an EOL says "this record is valid until..." - IpnsEntry_EOL IpnsEntry_ValidityType = 0 -) - -var IpnsEntry_ValidityType_name = map[int32]string{ - 0: "EOL", -} - -var IpnsEntry_ValidityType_value = map[string]int32{ - "EOL": 0, -} - -func (x IpnsEntry_ValidityType) Enum() *IpnsEntry_ValidityType { - p := new(IpnsEntry_ValidityType) - *p = x - return p -} - -func (x IpnsEntry_ValidityType) String() string { - return proto.EnumName(IpnsEntry_ValidityType_name, int32(x)) -} - -func (x *IpnsEntry_ValidityType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(IpnsEntry_ValidityType_value, data, "IpnsEntry_ValidityType") - if err != nil { - return err - } - *x = IpnsEntry_ValidityType(value) - return nil -} - -func (IpnsEntry_ValidityType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_4d5b16fb32bfe8ea, []int{0, 0} -} - -type IpnsEntry struct { - Value []byte `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"` - SignatureV1 []byte `protobuf:"bytes,2,opt,name=signatureV1" json:"signatureV1,omitempty"` - ValidityType *IpnsEntry_ValidityType `protobuf:"varint,3,opt,name=validityType,enum=ipns.v1.pb.IpnsEntry_ValidityType" json:"validityType,omitempty"` - Validity []byte `protobuf:"bytes,4,opt,name=validity" json:"validity,omitempty"` - Sequence *uint64 `protobuf:"varint,5,opt,name=sequence" json:"sequence,omitempty"` - Ttl *uint64 `protobuf:"varint,6,opt,name=ttl" json:"ttl,omitempty"` - // in order for nodes to properly validate a record upon receipt, they need the public - // key associated with it. For old RSA keys, its easiest if we just send this as part of - // the record itself. For newer ed25519 keys, the public key can be embedded in the - // peerID, making this field unnecessary. - PubKey []byte `protobuf:"bytes,7,opt,name=pubKey" json:"pubKey,omitempty"` - SignatureV2 []byte `protobuf:"bytes,8,opt,name=signatureV2" json:"signatureV2,omitempty"` - Data []byte `protobuf:"bytes,9,opt,name=data" json:"data,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *IpnsEntry) Reset() { *m = IpnsEntry{} } -func (m *IpnsEntry) String() string { return proto.CompactTextString(m) } -func (*IpnsEntry) ProtoMessage() {} -func (*IpnsEntry) Descriptor() ([]byte, []int) { - return fileDescriptor_4d5b16fb32bfe8ea, []int{0} -} -func (m *IpnsEntry) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *IpnsEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_IpnsEntry.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *IpnsEntry) XXX_Merge(src proto.Message) { - xxx_messageInfo_IpnsEntry.Merge(m, src) -} -func (m *IpnsEntry) XXX_Size() int { - return m.Size() -} -func (m *IpnsEntry) XXX_DiscardUnknown() { - xxx_messageInfo_IpnsEntry.DiscardUnknown(m) -} - -var xxx_messageInfo_IpnsEntry proto.InternalMessageInfo - -func (m *IpnsEntry) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -func (m *IpnsEntry) GetSignatureV1() []byte { - if m != nil { - return m.SignatureV1 - } - return nil -} - -func (m *IpnsEntry) GetValidityType() IpnsEntry_ValidityType { - if m != nil && m.ValidityType != nil { - return *m.ValidityType - } - return IpnsEntry_EOL -} - -func (m *IpnsEntry) GetValidity() []byte { - if m != nil { - return m.Validity - } - return nil -} - -func (m *IpnsEntry) GetSequence() uint64 { - if m != nil && m.Sequence != nil { - return *m.Sequence - } - return 0 -} - -func (m *IpnsEntry) GetTtl() uint64 { - if m != nil && m.Ttl != nil { - return *m.Ttl - } - return 0 -} - -func (m *IpnsEntry) GetPubKey() []byte { - if m != nil { - return m.PubKey - } - return nil -} - -func (m *IpnsEntry) GetSignatureV2() []byte { - if m != nil { - return m.SignatureV2 - } - return nil -} - -func (m *IpnsEntry) GetData() []byte { - if m != nil { - return m.Data - } - return nil -} - -type IpnsSignatureV2Checker struct { - PubKey []byte `protobuf:"bytes,7,opt,name=pubKey" json:"pubKey,omitempty"` - SignatureV2 []byte `protobuf:"bytes,8,opt,name=signatureV2" json:"signatureV2,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *IpnsSignatureV2Checker) Reset() { *m = IpnsSignatureV2Checker{} } -func (m *IpnsSignatureV2Checker) String() string { return proto.CompactTextString(m) } -func (*IpnsSignatureV2Checker) ProtoMessage() {} -func (*IpnsSignatureV2Checker) Descriptor() ([]byte, []int) { - return fileDescriptor_4d5b16fb32bfe8ea, []int{1} -} -func (m *IpnsSignatureV2Checker) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *IpnsSignatureV2Checker) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_IpnsSignatureV2Checker.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *IpnsSignatureV2Checker) XXX_Merge(src proto.Message) { - xxx_messageInfo_IpnsSignatureV2Checker.Merge(m, src) -} -func (m *IpnsSignatureV2Checker) XXX_Size() int { - return m.Size() -} -func (m *IpnsSignatureV2Checker) XXX_DiscardUnknown() { - xxx_messageInfo_IpnsSignatureV2Checker.DiscardUnknown(m) -} - -var xxx_messageInfo_IpnsSignatureV2Checker proto.InternalMessageInfo - -func (m *IpnsSignatureV2Checker) GetPubKey() []byte { - if m != nil { - return m.PubKey - } - return nil -} - -func (m *IpnsSignatureV2Checker) GetSignatureV2() []byte { - if m != nil { - return m.SignatureV2 - } - return nil -} - -func init() { - proto.RegisterEnum("ipns.v1.pb.IpnsEntry_ValidityType", IpnsEntry_ValidityType_name, IpnsEntry_ValidityType_value) - proto.RegisterType((*IpnsEntry)(nil), "ipns.v1.pb.IpnsEntry") - proto.RegisterType((*IpnsSignatureV2Checker)(nil), "ipns.v1.pb.IpnsSignatureV2Checker") -} - -func init() { proto.RegisterFile("ipns.proto", fileDescriptor_4d5b16fb32bfe8ea) } - -var fileDescriptor_4d5b16fb32bfe8ea = []byte{ - // 272 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xca, 0x2c, 0xc8, 0x2b, - 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x82, 0xb0, 0xcb, 0x0c, 0xf5, 0x0a, 0x92, 0x94, 0xf6, - 0x30, 0x71, 0x71, 0x7a, 0x16, 0xe4, 0x15, 0xbb, 0xe6, 0x95, 0x14, 0x55, 0x0a, 0x89, 0x70, 0xb1, - 0x96, 0x25, 0xe6, 0x94, 0xa6, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x04, 0x41, 0x38, 0x42, 0x0a, - 0x5c, 0xdc, 0xc5, 0x99, 0xe9, 0x79, 0x89, 0x25, 0xa5, 0x45, 0xa9, 0x61, 0x86, 0x12, 0x4c, 0x60, - 0x39, 0x64, 0x21, 0x21, 0x37, 0x2e, 0x9e, 0xb2, 0xc4, 0x9c, 0xcc, 0x94, 0xcc, 0x92, 0xca, 0x90, - 0xca, 0x82, 0x54, 0x09, 0x66, 0x05, 0x46, 0x0d, 0x3e, 0x23, 0x25, 0x3d, 0x84, 0x45, 0x7a, 0x70, - 0x4b, 0xf4, 0xc2, 0x90, 0x54, 0x06, 0xa1, 0xe8, 0x13, 0x92, 0xe2, 0xe2, 0x80, 0xf1, 0x25, 0x58, - 0xc0, 0xd6, 0xc0, 0xf9, 0x20, 0xb9, 0xe2, 0xd4, 0xc2, 0xd2, 0xd4, 0xbc, 0xe4, 0x54, 0x09, 0x56, - 0x05, 0x46, 0x0d, 0x96, 0x20, 0x38, 0x5f, 0x48, 0x80, 0x8b, 0xb9, 0xa4, 0x24, 0x47, 0x82, 0x0d, - 0x2c, 0x0c, 0x62, 0x0a, 0x89, 0x71, 0xb1, 0x15, 0x94, 0x26, 0x79, 0xa7, 0x56, 0x4a, 0xb0, 0x83, - 0xcd, 0x81, 0xf2, 0x50, 0xfd, 0x62, 0x24, 0xc1, 0x81, 0xee, 0x17, 0x23, 0x21, 0x21, 0x2e, 0x96, - 0x94, 0xc4, 0x92, 0x44, 0x09, 0x4e, 0xb0, 0x14, 0x98, 0xad, 0x24, 0xce, 0xc5, 0x83, 0xec, 0x6a, - 0x21, 0x76, 0x2e, 0x66, 0x57, 0x7f, 0x1f, 0x01, 0x06, 0xa5, 0x20, 0x2e, 0x31, 0x90, 0xc7, 0x82, - 0x11, 0xfa, 0x9d, 0x33, 0x52, 0x93, 0xb3, 0x53, 0x8b, 0xc8, 0x77, 0x80, 0x93, 0xe8, 0x89, 0x47, - 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x18, 0xc5, 0x0e, 0x0a, 0xc3, 0xf8, - 0x82, 0x24, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbd, 0x45, 0xdd, 0x1a, 0xc2, 0x01, 0x00, 0x00, -} - -func (m *IpnsEntry) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *IpnsEntry) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *IpnsEntry) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Data != nil { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintIpns(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0x4a - } - if m.SignatureV2 != nil { - i -= len(m.SignatureV2) - copy(dAtA[i:], m.SignatureV2) - i = encodeVarintIpns(dAtA, i, uint64(len(m.SignatureV2))) - i-- - dAtA[i] = 0x42 - } - if m.PubKey != nil { - i -= len(m.PubKey) - copy(dAtA[i:], m.PubKey) - i = encodeVarintIpns(dAtA, i, uint64(len(m.PubKey))) - i-- - dAtA[i] = 0x3a - } - if m.Ttl != nil { - i = encodeVarintIpns(dAtA, i, uint64(*m.Ttl)) - i-- - dAtA[i] = 0x30 - } - if m.Sequence != nil { - i = encodeVarintIpns(dAtA, i, uint64(*m.Sequence)) - i-- - dAtA[i] = 0x28 - } - if m.Validity != nil { - i -= len(m.Validity) - copy(dAtA[i:], m.Validity) - i = encodeVarintIpns(dAtA, i, uint64(len(m.Validity))) - i-- - dAtA[i] = 0x22 - } - if m.ValidityType != nil { - i = encodeVarintIpns(dAtA, i, uint64(*m.ValidityType)) - i-- - dAtA[i] = 0x18 - } - if m.SignatureV1 != nil { - i -= len(m.SignatureV1) - copy(dAtA[i:], m.SignatureV1) - i = encodeVarintIpns(dAtA, i, uint64(len(m.SignatureV1))) - i-- - dAtA[i] = 0x12 - } - if m.Value != nil { - i -= len(m.Value) - copy(dAtA[i:], m.Value) - i = encodeVarintIpns(dAtA, i, uint64(len(m.Value))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *IpnsSignatureV2Checker) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *IpnsSignatureV2Checker) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *IpnsSignatureV2Checker) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.SignatureV2 != nil { - i -= len(m.SignatureV2) - copy(dAtA[i:], m.SignatureV2) - i = encodeVarintIpns(dAtA, i, uint64(len(m.SignatureV2))) - i-- - dAtA[i] = 0x42 - } - if m.PubKey != nil { - i -= len(m.PubKey) - copy(dAtA[i:], m.PubKey) - i = encodeVarintIpns(dAtA, i, uint64(len(m.PubKey))) - i-- - dAtA[i] = 0x3a - } - return len(dAtA) - i, nil -} - -func encodeVarintIpns(dAtA []byte, offset int, v uint64) int { - offset -= sovIpns(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *IpnsEntry) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Value != nil { - l = len(m.Value) - n += 1 + l + sovIpns(uint64(l)) - } - if m.SignatureV1 != nil { - l = len(m.SignatureV1) - n += 1 + l + sovIpns(uint64(l)) - } - if m.ValidityType != nil { - n += 1 + sovIpns(uint64(*m.ValidityType)) - } - if m.Validity != nil { - l = len(m.Validity) - n += 1 + l + sovIpns(uint64(l)) - } - if m.Sequence != nil { - n += 1 + sovIpns(uint64(*m.Sequence)) - } - if m.Ttl != nil { - n += 1 + sovIpns(uint64(*m.Ttl)) - } - if m.PubKey != nil { - l = len(m.PubKey) - n += 1 + l + sovIpns(uint64(l)) - } - if m.SignatureV2 != nil { - l = len(m.SignatureV2) - n += 1 + l + sovIpns(uint64(l)) - } - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovIpns(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *IpnsSignatureV2Checker) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.PubKey != nil { - l = len(m.PubKey) - n += 1 + l + sovIpns(uint64(l)) - } - if m.SignatureV2 != nil { - l = len(m.SignatureV2) - n += 1 + l + sovIpns(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovIpns(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozIpns(x uint64) (n int) { - return sovIpns(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *IpnsEntry) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: IpnsEntry: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: IpnsEntry: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthIpns - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthIpns - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SignatureV1", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthIpns - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthIpns - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SignatureV1 = append(m.SignatureV1[:0], dAtA[iNdEx:postIndex]...) - if m.SignatureV1 == nil { - m.SignatureV1 = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidityType", wireType) - } - var v IpnsEntry_ValidityType - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= IpnsEntry_ValidityType(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.ValidityType = &v - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Validity", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthIpns - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthIpns - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Validity = append(m.Validity[:0], dAtA[iNdEx:postIndex]...) - if m.Validity == nil { - m.Validity = []byte{} - } - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) - } - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Sequence = &v - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Ttl", wireType) - } - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Ttl = &v - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthIpns - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthIpns - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PubKey = append(m.PubKey[:0], dAtA[iNdEx:postIndex]...) - if m.PubKey == nil { - m.PubKey = []byte{} - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SignatureV2", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthIpns - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthIpns - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SignatureV2 = append(m.SignatureV2[:0], dAtA[iNdEx:postIndex]...) - if m.SignatureV2 == nil { - m.SignatureV2 = []byte{} - } - iNdEx = postIndex - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthIpns - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthIpns - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipIpns(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthIpns - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthIpns - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *IpnsSignatureV2Checker) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: IpnsSignatureV2Checker: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: IpnsSignatureV2Checker: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthIpns - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthIpns - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PubKey = append(m.PubKey[:0], dAtA[iNdEx:postIndex]...) - if m.PubKey == nil { - m.PubKey = []byte{} - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SignatureV2", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowIpns - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthIpns - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthIpns - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SignatureV2 = append(m.SignatureV2[:0], dAtA[iNdEx:postIndex]...) - if m.SignatureV2 == nil { - m.SignatureV2 = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipIpns(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthIpns - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthIpns - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipIpns(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowIpns - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowIpns - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowIpns - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthIpns - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupIpns - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthIpns - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthIpns = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowIpns = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupIpns = fmt.Errorf("proto: unexpected end of group") -) diff --git a/ipns/pb/ipns.proto b/ipns/pb/ipns.proto deleted file mode 100644 index bd89a34ec..000000000 --- a/ipns/pb/ipns.proto +++ /dev/null @@ -1,36 +0,0 @@ -syntax = "proto2"; - -package ipns.v1.pb; - -option go_package = "ipns_pb"; - -message IpnsEntry { - enum ValidityType { - // setting an EOL says "this record is valid until..." - EOL = 0; - } - optional bytes value = 1; - optional bytes signatureV1 = 2; - - optional ValidityType validityType = 3; - optional bytes validity = 4; - - optional uint64 sequence = 5; - - optional uint64 ttl = 6; - - // in order for nodes to properly validate a record upon receipt, they need the public - // key associated with it. For old RSA keys, its easiest if we just send this as part of - // the record itself. For newer ed25519 keys, the public key can be embedded in the - // peerID, making this field unnecessary. - optional bytes pubKey = 7; - - optional bytes signatureV2 = 8; - - optional bytes data = 9; -} - -message IpnsSignatureV2Checker { - optional bytes pubKey = 7; - optional bytes signatureV2 = 8; -} diff --git a/ipns/proto/record.proto b/ipns/proto/record.proto new file mode 100644 index 000000000..9f7a18ce7 --- /dev/null +++ b/ipns/proto/record.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package ipns; + +option go_package = "./internal/pb"; + +message IpnsRecord { + enum ValidityType { + EOL = 0; + } + + optional bytes value = 1; + optional bytes signatureV1 = 2; + optional ValidityType validityType = 3; + optional bytes validity = 4; + optional uint64 sequence = 5; + optional uint64 ttl = 6; + optional bytes pubKey = 7; + optional bytes signatureV2 = 8; + optional bytes data = 9; +} diff --git a/ipns/record.go b/ipns/record.go index 3a0858b9f..51bb8c712 100644 --- a/ipns/record.go +++ b/ipns/record.go @@ -1,3 +1,4 @@ +//go:generate protoc -I=proto --go_out=. ./proto/record.proto package ipns import ( @@ -7,8 +8,7 @@ import ( "sort" "time" - "github.com/gogo/protobuf/proto" - ipns_pb "github.com/ipfs/boxo/ipns/pb" + ipns_pb "github.com/ipfs/boxo/ipns/internal/pb" "github.com/ipfs/boxo/path" "github.com/ipfs/boxo/util" logging "github.com/ipfs/go-log/v2" @@ -19,6 +19,7 @@ import ( ic "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "go.uber.org/multierr" + "google.golang.org/protobuf/proto" ) var log = logging.Logger("ipns") @@ -33,7 +34,7 @@ const ValidityEOL ValidityType = 0 // // [IPNS Record]: https://specs.ipfs.tech/ipns/ipns-record/ type Record struct { - pb ipns_pb.IpnsEntry + pb *ipns_pb.IpnsRecord node datamodel.Node } @@ -47,14 +48,14 @@ func UnmarshalRecord(data []byte) (*Record, error) { return nil, ErrRecordSize } - var pb ipns_pb.IpnsEntry + var pb ipns_pb.IpnsRecord err := proto.Unmarshal(data, &pb) if err != nil { return nil, multierr.Combine(ErrInvalidRecord, err) } record := &Record{ - pb: pb, + pb: &pb, } // Ensure the record has DAG-CBOR data because we need it. @@ -76,7 +77,7 @@ func UnmarshalRecord(data []byte) (*Record, error) { // // [Protobuf serialization format]: https://specs.ipfs.tech/ipns/ipns-record/#record-serialization-format func MarshalRecord(rec *Record) ([]byte, error) { - return proto.Marshal(&rec.pb) + return proto.Marshal(rec.pb) } // Value returns the [path.Path] that is embedded in this IPNS Record. If the @@ -246,14 +247,14 @@ func NewRecord(sk ic.PrivKey, value path.Path, seq uint64, eol time.Time, ttl ti return nil, err } - pb := ipns_pb.IpnsEntry{ + pb := ipns_pb.IpnsRecord{ Data: cborData, SignatureV2: sig2, } if options.v1Compatibility { pb.Value = []byte(value) - typ := ipns_pb.IpnsEntry_EOL + typ := ipns_pb.IpnsRecord_EOL pb.ValidityType = &typ pb.Sequence = &seq pb.Validity = []byte(util.FormatRFC3339(eol)) @@ -290,7 +291,7 @@ func NewRecord(sk ic.PrivKey, value path.Path, seq uint64, eol time.Time, ttl ti } return &Record{ - pb: pb, + pb: &pb, node: node, }, nil } @@ -353,7 +354,7 @@ func nodeToCBOR(node datamodel.Node) ([]byte, error) { return buf.Bytes(), nil } -func recordDataForSignatureV1(e *ipns_pb.IpnsEntry) []byte { +func recordDataForSignatureV1(e *ipns_pb.IpnsRecord) []byte { return bytes.Join([][]byte{ e.Value, e.Validity, diff --git a/ipns/record_test.go b/ipns/record_test.go index f237295a9..4c7f0e934 100644 --- a/ipns/record_test.go +++ b/ipns/record_test.go @@ -5,8 +5,7 @@ import ( "testing" "time" - "github.com/gogo/protobuf/proto" - ipns_pb "github.com/ipfs/boxo/ipns/pb" + ipns_pb "github.com/ipfs/boxo/ipns/internal/pb" "github.com/ipfs/boxo/path" "github.com/ipfs/boxo/util" "github.com/ipld/go-ipld-prime/codec/dagcbor" @@ -15,6 +14,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" ) const ( @@ -70,7 +70,7 @@ func fieldsMatch(t *testing.T, rec *Record, value path.Path, seq uint64, eol tim func fieldsMatchV1(t *testing.T, rec *Record, value path.Path, seq uint64, eol time.Time, ttl time.Duration) { require.Equal(t, value.String(), string(rec.pb.GetValue())) require.Equal(t, seq, rec.pb.GetSequence()) - require.Equal(t, rec.pb.GetValidityType(), ipns_pb.IpnsEntry_EOL) + require.Equal(t, rec.pb.GetValidityType(), ipns_pb.IpnsRecord_EOL) require.Equal(t, time.Duration(rec.pb.GetTtl()), ttl) recEOL, err := util.ParseRFC3339(string(rec.pb.GetValidity())) @@ -264,7 +264,7 @@ func TestUnmarshal(t *testing.T) { }) t.Run("Errors with V1-only records", func(t *testing.T) { - pb := ipns_pb.IpnsEntry{} + pb := ipns_pb.IpnsRecord{} data, err := proto.Marshal(&pb) require.NoError(t, err) _, err = UnmarshalRecord(data) @@ -272,7 +272,7 @@ func TestUnmarshal(t *testing.T) { }) t.Run("Errors on bad data", func(t *testing.T) { - pb := ipns_pb.IpnsEntry{ + pb := ipns_pb.IpnsRecord{ Data: []byte("definitely not cbor"), } data, err := proto.Marshal(&pb) diff --git a/ipns/validation.go b/ipns/validation.go index e54ae6d9f..d6ed71e8c 100644 --- a/ipns/validation.go +++ b/ipns/validation.go @@ -6,13 +6,14 @@ import ( "fmt" "time" - pb "github.com/ipfs/boxo/ipns/pb" + ipns_pb "github.com/ipfs/boxo/ipns/internal/pb" "github.com/ipld/go-ipld-prime/codec/dagcbor" basicnode "github.com/ipld/go-ipld-prime/node/basic" record "github.com/libp2p/go-libp2p-record" ic "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peerstore" + "google.golang.org/protobuf/proto" ) // ValidateWithName validates the given IPNS [Record] against the given [Name]. @@ -31,7 +32,7 @@ func ValidateWithName(rec *Record, name Name) error { // [Record Verification]: https://specs.ipfs.tech/ipns/ipns-record/#record-verification func Validate(rec *Record, pk ic.PubKey) error { // (1) Ensure size is not over maximum record size. - if rec.pb.Size() > MaxRecordSize { + if proto.Size(rec.pb) > MaxRecordSize { return ErrRecordSize } @@ -58,7 +59,7 @@ func Validate(rec *Record, pk ic.PubKey) error { // (5) Ensure that CBOR data matches Protobuf, only if non-CBOR Value or SignatureV1 are present. if len(rec.pb.GetSignatureV1()) != 0 || len(rec.pb.GetValue()) != 0 { - if err := validateCborDataMatchesPbData(&rec.pb); err != nil { + if err := validateCborDataMatchesPbData(rec.pb); err != nil { return err } } @@ -77,7 +78,7 @@ func Validate(rec *Record, pk ic.PubKey) error { } // TODO: Most of this function could probably be replaced with codegen -func validateCborDataMatchesPbData(entry *pb.IpnsEntry) error { +func validateCborDataMatchesPbData(entry *ipns_pb.IpnsRecord) error { if len(entry.GetData()) == 0 { return fmt.Errorf("record data is missing") }