mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-01-15 02:30:05 +08:00
use proto3 & rename fields to match spec changes
This commit is contained in:
parent
41d8bd9d4b
commit
9cc8ee1b44
@ -12,7 +12,7 @@ import (
|
||||
// Envelopes are signed in the context of a particular "domain", which is a string
|
||||
// specified when creating and verifying the envelope. You must know the domain
|
||||
// string used to produce the envelope in order to verify the signature and
|
||||
// access the contents.
|
||||
// access the payload.
|
||||
type SignedEnvelope struct {
|
||||
|
||||
// The public key that can be used to verify the signature and derive the peer id of the signer.
|
||||
@ -20,13 +20,13 @@ type SignedEnvelope struct {
|
||||
|
||||
// A binary identifier that indicates what kind of data is contained in the payload.
|
||||
// TODO(yusef): enforce multicodec prefix
|
||||
TypeHint []byte
|
||||
PayloadType []byte
|
||||
|
||||
// The envelope payload. This is private to discourage accessing the payload without verifying the signature.
|
||||
// To access, use the Open method.
|
||||
contents []byte
|
||||
payload []byte
|
||||
|
||||
// The signature of the domain string, type hint, and contents.
|
||||
// The signature of the domain string, type hint, and payload.
|
||||
signature []byte
|
||||
}
|
||||
|
||||
@ -37,22 +37,22 @@ var errEmptyDomain = errors.New("envelope domain must not be empty")
|
||||
// The required 'domain' string contextualizes the envelope for a particular purpose,
|
||||
// and must be supplied when verifying the signature.
|
||||
//
|
||||
// The 'typeHint' field indicates what kind of data is contained and may be empty.
|
||||
func MakeEnvelope(privateKey PrivKey, domain string, typeHint []byte, contents []byte) (*SignedEnvelope, error) {
|
||||
// The 'payloadType' field indicates what kind of data is contained and may be empty.
|
||||
func MakeEnvelope(privateKey PrivKey, domain string, payloadType []byte, contents []byte) (*SignedEnvelope, error) {
|
||||
if len(domain) == 0 {
|
||||
return nil, errEmptyDomain
|
||||
}
|
||||
toSign := makeSigBuffer(domain, typeHint, contents)
|
||||
toSign := makeSigBuffer(domain, payloadType, contents)
|
||||
sig, err := privateKey.Sign(toSign)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &SignedEnvelope{
|
||||
PublicKey: privateKey.GetPublic(),
|
||||
TypeHint: typeHint,
|
||||
contents: contents,
|
||||
signature: sig,
|
||||
PublicKey: privateKey.GetPublic(),
|
||||
PayloadType: payloadType,
|
||||
payload: contents,
|
||||
signature: sig,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -68,17 +68,17 @@ func UnmarshalEnvelope(serializedEnvelope []byte) (*SignedEnvelope, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &SignedEnvelope{
|
||||
PublicKey: key,
|
||||
TypeHint: e.TypeHint,
|
||||
contents: e.Contents,
|
||||
signature: e.Signature,
|
||||
PublicKey: key,
|
||||
PayloadType: e.PayloadType,
|
||||
payload: e.Payload,
|
||||
signature: e.Signature,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Validate returns true if the envelope signature is valid for the given 'domain',
|
||||
// or false if it is invalid. May return an error if signature validation fails.
|
||||
func (e *SignedEnvelope) Validate(domain string) (bool, error) {
|
||||
toVerify := makeSigBuffer(domain, e.TypeHint, e.contents)
|
||||
toVerify := makeSigBuffer(domain, e.PayloadType, e.payload)
|
||||
return e.PublicKey.Verify(toVerify, e.signature)
|
||||
}
|
||||
|
||||
@ -90,16 +90,16 @@ func (e *SignedEnvelope) Marshal() ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
msg := pb.SignedEnvelope{
|
||||
PublicKey: key,
|
||||
TypeHint: e.TypeHint,
|
||||
Contents: e.contents,
|
||||
Signature: e.signature,
|
||||
PublicKey: key,
|
||||
PayloadType: e.PayloadType,
|
||||
Payload: e.payload,
|
||||
Signature: e.signature,
|
||||
}
|
||||
return proto.Marshal(&msg)
|
||||
}
|
||||
|
||||
// Open validates the signature (within the given 'domain') and returns
|
||||
// the contents of the envelope. Will fail with an error if the signature
|
||||
// the payload of the envelope. Will fail with an error if the signature
|
||||
// is invalid.
|
||||
func (e *SignedEnvelope) Open(domain string) ([]byte, error) {
|
||||
valid, err := e.Validate(domain)
|
||||
@ -109,13 +109,13 @@ func (e *SignedEnvelope) Open(domain string) ([]byte, error) {
|
||||
if !valid {
|
||||
return nil, errors.New("invalid signature or incorrect domain")
|
||||
}
|
||||
return e.contents, nil
|
||||
return e.payload, nil
|
||||
}
|
||||
|
||||
func (e *SignedEnvelope) Equals(other *SignedEnvelope) bool {
|
||||
return e.PublicKey.Equals(other.PublicKey) &&
|
||||
bytes.Compare(e.TypeHint, other.TypeHint) == 0 &&
|
||||
bytes.Compare(e.contents, other.contents) == 0 &&
|
||||
bytes.Compare(e.PayloadType, other.PayloadType) == 0 &&
|
||||
bytes.Compare(e.payload, other.payload) == 0 &&
|
||||
bytes.Compare(e.signature, other.signature) == 0
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@ func TestEnvelopeHappyPath(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
contents := []byte("happy hacking")
|
||||
payload := []byte("happy hacking")
|
||||
domain := "libp2p-testing"
|
||||
typeHint := []byte("/libp2p/testdata")
|
||||
envelope, err := MakeEnvelope(priv, domain, typeHint, contents)
|
||||
payloadType := []byte("/libp2p/testdata")
|
||||
envelope, err := MakeEnvelope(priv, domain, payloadType, payload)
|
||||
if err != nil {
|
||||
t.Errorf("error constructing envelope: %v", err)
|
||||
}
|
||||
@ -27,8 +27,8 @@ func TestEnvelopeHappyPath(t *testing.T) {
|
||||
t.Error("envelope has unexpected public key")
|
||||
}
|
||||
|
||||
if bytes.Compare(typeHint, envelope.TypeHint) != 0 {
|
||||
t.Error("TypeHint does not match typeHint used to construct envelope")
|
||||
if bytes.Compare(payloadType, envelope.PayloadType) != 0 {
|
||||
t.Error("PayloadType does not match payloadType used to construct envelope")
|
||||
}
|
||||
|
||||
valid, err := envelope.Validate(domain)
|
||||
@ -43,8 +43,8 @@ func TestEnvelopeHappyPath(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("error opening envelope: %v", err)
|
||||
}
|
||||
if bytes.Compare(c, contents) != 0 {
|
||||
t.Error("contents of envelope do not match input")
|
||||
if bytes.Compare(c, payload) != 0 {
|
||||
t.Error("payload of envelope do not match input")
|
||||
}
|
||||
|
||||
serialized, err := envelope.Marshal()
|
||||
@ -66,10 +66,10 @@ func TestEnvelopeValidateFailsForDifferentDomain(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
contents := []byte("happy hacking")
|
||||
payload := []byte("happy hacking")
|
||||
domain := "libp2p-testing"
|
||||
typeHint := []byte("/libp2p/testdata")
|
||||
envelope, err := MakeEnvelope(priv, domain, typeHint, contents)
|
||||
payloadType := []byte("/libp2p/testdata")
|
||||
envelope, err := MakeEnvelope(priv, domain, payloadType, payload)
|
||||
if err != nil {
|
||||
t.Errorf("error constructing envelope: %v", err)
|
||||
}
|
||||
@ -88,14 +88,14 @@ func TestEnvelopeValidateFailsIfTypeHintIsAltered(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
contents := []byte("happy hacking")
|
||||
payload := []byte("happy hacking")
|
||||
domain := "libp2p-testing"
|
||||
typeHint := []byte("/libp2p/testdata")
|
||||
envelope, err := MakeEnvelope(priv, domain, typeHint, contents)
|
||||
payloadType := []byte("/libp2p/testdata")
|
||||
envelope, err := MakeEnvelope(priv, domain, payloadType, payload)
|
||||
if err != nil {
|
||||
t.Errorf("error constructing envelope: %v", err)
|
||||
}
|
||||
envelope.TypeHint = []byte("foo")
|
||||
envelope.PayloadType = []byte("foo")
|
||||
valid, err := envelope.Validate("other-domain")
|
||||
if err != nil {
|
||||
t.Errorf("error validating envelope: %v", err)
|
||||
@ -110,15 +110,15 @@ func TestEnvelopeValidateFailsIfContentsAreAltered(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
contents := []byte("happy hacking")
|
||||
payload := []byte("happy hacking")
|
||||
domain := "libp2p-testing"
|
||||
typeHint := []byte("/libp2p/testdata")
|
||||
envelope, err := MakeEnvelope(priv, domain, typeHint, contents)
|
||||
payloadType := []byte("/libp2p/testdata")
|
||||
envelope, err := MakeEnvelope(priv, domain, payloadType, payload)
|
||||
if err != nil {
|
||||
t.Errorf("error constructing envelope: %v", err)
|
||||
}
|
||||
|
||||
// since the contents field is private, we'll serialize and alter the
|
||||
// since the payload field is private, we'll serialize and alter the
|
||||
// serialized protobuf
|
||||
serialized, err := envelope.Marshal()
|
||||
if err != nil {
|
||||
@ -130,7 +130,7 @@ func TestEnvelopeValidateFailsIfContentsAreAltered(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("error deserializing envelope: %v", err)
|
||||
}
|
||||
msg.Contents = []byte("totally legit, trust me")
|
||||
msg.Payload = []byte("totally legit, trust me")
|
||||
serialized, err = proto.Marshal(&msg)
|
||||
|
||||
// unmarshal our altered envelope
|
||||
|
@ -172,103 +172,29 @@ func (m *PrivateKey) GetData() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
type SignedEnvelope struct {
|
||||
PublicKey *PublicKey `protobuf:"bytes,1,req,name=PublicKey" json:"PublicKey,omitempty"`
|
||||
TypeHint []byte `protobuf:"bytes,2,req,name=TypeHint" json:"TypeHint"`
|
||||
Contents []byte `protobuf:"bytes,3,req,name=Contents" json:"Contents"`
|
||||
Signature []byte `protobuf:"bytes,4,req,name=Signature" json:"Signature"`
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) Reset() { *m = SignedEnvelope{} }
|
||||
func (m *SignedEnvelope) String() string { return proto.CompactTextString(m) }
|
||||
func (*SignedEnvelope) ProtoMessage() {}
|
||||
func (*SignedEnvelope) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_527278fb02d03321, []int{2}
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_SignedEnvelope.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalTo(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_SignedEnvelope.Merge(m, src)
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_SignedEnvelope.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_SignedEnvelope proto.InternalMessageInfo
|
||||
|
||||
func (m *SignedEnvelope) GetPublicKey() *PublicKey {
|
||||
if m != nil {
|
||||
return m.PublicKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) GetTypeHint() []byte {
|
||||
if m != nil {
|
||||
return m.TypeHint
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) GetContents() []byte {
|
||||
if m != nil {
|
||||
return m.Contents
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) GetSignature() []byte {
|
||||
if m != nil {
|
||||
return m.Signature
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterEnum("crypto.pb.KeyType", KeyType_name, KeyType_value)
|
||||
proto.RegisterType((*PublicKey)(nil), "crypto.pb.PublicKey")
|
||||
proto.RegisterType((*PrivateKey)(nil), "crypto.pb.PrivateKey")
|
||||
proto.RegisterType((*SignedEnvelope)(nil), "crypto.pb.SignedEnvelope")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("crypto.proto", fileDescriptor_527278fb02d03321) }
|
||||
|
||||
var fileDescriptor_527278fb02d03321 = []byte{
|
||||
// 285 bytes of a gzipped FileDescriptorProto
|
||||
// 203 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0x2e, 0xaa, 0x2c,
|
||||
0x28, 0xc9, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x84, 0xf1, 0x92, 0x94, 0x82, 0xb9,
|
||||
0x38, 0x03, 0x4a, 0x93, 0x72, 0x32, 0x93, 0xbd, 0x53, 0x2b, 0x85, 0x74, 0xb8, 0x58, 0x42, 0x2a,
|
||||
0x0b, 0x52, 0x25, 0x18, 0x15, 0x98, 0x34, 0xf8, 0x8c, 0x84, 0xf4, 0xe0, 0xca, 0xf4, 0xbc, 0x53,
|
||||
0x2b, 0x41, 0x32, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x81, 0x55, 0x09, 0x49, 0x70, 0xb1,
|
||||
0xb8, 0x24, 0x96, 0x24, 0x4a, 0x30, 0x29, 0x30, 0x69, 0xf0, 0xc0, 0x64, 0x40, 0x22, 0x4a, 0x21,
|
||||
0x5c, 0x5c, 0x01, 0x45, 0x99, 0x65, 0x89, 0x25, 0xa9, 0xd4, 0x34, 0x75, 0x0d, 0x23, 0x17, 0x5f,
|
||||
0x70, 0x66, 0x7a, 0x5e, 0x6a, 0x8a, 0x6b, 0x5e, 0x59, 0x6a, 0x4e, 0x7e, 0x41, 0xaa, 0x90, 0x11,
|
||||
0x92, 0xeb, 0xc1, 0xe6, 0x73, 0x1b, 0x89, 0x20, 0x99, 0x0f, 0x97, 0x0b, 0x42, 0xf2, 0xa4, 0x02,
|
||||
0x17, 0x07, 0xc8, 0x22, 0x8f, 0xcc, 0xbc, 0x12, 0x14, 0x4b, 0xe0, 0xa2, 0x20, 0x15, 0xce, 0xf9,
|
||||
0x79, 0x25, 0xa9, 0x79, 0x25, 0xc5, 0x12, 0xcc, 0xc8, 0x2a, 0x60, 0xa2, 0x42, 0x4a, 0x5c, 0x9c,
|
||||
0x20, 0x97, 0x24, 0x96, 0x94, 0x16, 0xa5, 0x4a, 0xb0, 0x20, 0x29, 0x41, 0x08, 0x6b, 0x59, 0x72,
|
||||
0xb1, 0x43, 0xfd, 0x27, 0xc4, 0xce, 0xc5, 0x1c, 0x14, 0xec, 0x28, 0xc0, 0x20, 0xc4, 0xcd, 0xc5,
|
||||
0xee, 0x9a, 0x62, 0x64, 0x6a, 0x6a, 0x68, 0x29, 0xc0, 0x28, 0xc4, 0xcb, 0xc5, 0x19, 0x9c, 0x9a,
|
||||
0x5c, 0x60, 0x64, 0x6a, 0x96, 0x6d, 0x28, 0xc0, 0x24, 0xc4, 0xc9, 0xc5, 0xea, 0xea, 0xec, 0x12,
|
||||
0xec, 0x28, 0xc0, 0xec, 0x24, 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e,
|
||||
0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x80,
|
||||
0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 0xc0, 0x25, 0x32, 0xc8, 0x01, 0x00, 0x00,
|
||||
0x5c, 0x5c, 0x01, 0x45, 0x99, 0x65, 0x89, 0x25, 0xa9, 0x54, 0x34, 0x55, 0xcb, 0x92, 0x8b, 0x1d,
|
||||
0xaa, 0x41, 0x88, 0x9d, 0x8b, 0x39, 0x28, 0xd8, 0x51, 0x80, 0x41, 0x88, 0x9b, 0x8b, 0xdd, 0x35,
|
||||
0xc5, 0xc8, 0xd4, 0xd4, 0xd0, 0x52, 0x80, 0x51, 0x88, 0x97, 0x8b, 0x33, 0x38, 0x35, 0xb9, 0xc0,
|
||||
0xc8, 0xd4, 0x2c, 0xdb, 0x50, 0x80, 0x49, 0x88, 0x93, 0x8b, 0xd5, 0xd5, 0xd9, 0x25, 0xd8, 0x51,
|
||||
0x80, 0xd9, 0x49, 0xe2, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63,
|
||||
0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0x00, 0x01, 0x00,
|
||||
0x00, 0xff, 0xff, 0x13, 0xbe, 0xd4, 0xff, 0x19, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *PublicKey) Marshal() (dAtA []byte, err error) {
|
||||
@ -325,54 +251,6 @@ func (m *PrivateKey) MarshalTo(dAtA []byte) (int, error) {
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) MarshalTo(dAtA []byte) (int, error) {
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.PublicKey == nil {
|
||||
return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("PublicKey")
|
||||
} else {
|
||||
dAtA[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintCrypto(dAtA, i, uint64(m.PublicKey.Size()))
|
||||
n1, err := m.PublicKey.MarshalTo(dAtA[i:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i += n1
|
||||
}
|
||||
if m.TypeHint != nil {
|
||||
dAtA[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintCrypto(dAtA, i, uint64(len(m.TypeHint)))
|
||||
i += copy(dAtA[i:], m.TypeHint)
|
||||
}
|
||||
if m.Contents != nil {
|
||||
dAtA[i] = 0x1a
|
||||
i++
|
||||
i = encodeVarintCrypto(dAtA, i, uint64(len(m.Contents)))
|
||||
i += copy(dAtA[i:], m.Contents)
|
||||
}
|
||||
if m.Signature != nil {
|
||||
dAtA[i] = 0x22
|
||||
i++
|
||||
i = encodeVarintCrypto(dAtA, i, uint64(len(m.Signature)))
|
||||
i += copy(dAtA[i:], m.Signature)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func encodeVarintCrypto(dAtA []byte, offset int, v uint64) int {
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
@ -410,31 +288,6 @@ func (m *PrivateKey) Size() (n int) {
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if m.PublicKey != nil {
|
||||
l = m.PublicKey.Size()
|
||||
n += 1 + l + sovCrypto(uint64(l))
|
||||
}
|
||||
if m.TypeHint != nil {
|
||||
l = len(m.TypeHint)
|
||||
n += 1 + l + sovCrypto(uint64(l))
|
||||
}
|
||||
if m.Contents != nil {
|
||||
l = len(m.Contents)
|
||||
n += 1 + l + sovCrypto(uint64(l))
|
||||
}
|
||||
if m.Signature != nil {
|
||||
l = len(m.Signature)
|
||||
n += 1 + l + sovCrypto(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovCrypto(x uint64) (n int) {
|
||||
for {
|
||||
n++
|
||||
@ -678,214 +531,6 @@ func (m *PrivateKey) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *SignedEnvelope) Unmarshal(dAtA []byte) error {
|
||||
var hasFields [1]uint64
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCrypto
|
||||
}
|
||||
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: SignedEnvelope: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: SignedEnvelope: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCrypto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if m.PublicKey == nil {
|
||||
m.PublicKey = &PublicKey{}
|
||||
}
|
||||
if err := m.PublicKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
hasFields[0] |= uint64(0x00000001)
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field TypeHint", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCrypto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.TypeHint = append(m.TypeHint[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.TypeHint == nil {
|
||||
m.TypeHint = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
hasFields[0] |= uint64(0x00000002)
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Contents", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCrypto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Contents = append(m.Contents[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Contents == nil {
|
||||
m.Contents = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
hasFields[0] |= uint64(0x00000004)
|
||||
case 4:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowCrypto
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Signature == nil {
|
||||
m.Signature = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
hasFields[0] |= uint64(0x00000008)
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipCrypto(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthCrypto
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
if hasFields[0]&uint64(0x00000001) == 0 {
|
||||
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("PublicKey")
|
||||
}
|
||||
if hasFields[0]&uint64(0x00000002) == 0 {
|
||||
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("TypeHint")
|
||||
}
|
||||
if hasFields[0]&uint64(0x00000004) == 0 {
|
||||
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Contents")
|
||||
}
|
||||
if hasFields[0]&uint64(0x00000008) == 0 {
|
||||
return github_com_gogo_protobuf_proto.NewRequiredNotSetError("Signature")
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipCrypto(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
|
@ -18,10 +18,3 @@ message PrivateKey {
|
||||
required KeyType Type = 1;
|
||||
required bytes Data = 2;
|
||||
}
|
||||
|
||||
message SignedEnvelope {
|
||||
required PublicKey PublicKey = 1;
|
||||
required bytes TypeHint = 2;
|
||||
required bytes Contents = 3;
|
||||
required bytes Signature = 4;
|
||||
}
|
508
crypto/pb/envelope.pb.go
Normal file
508
crypto/pb/envelope.pb.go
Normal file
@ -0,0 +1,508 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: envelope.proto
|
||||
|
||||
package crypto_pb
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
)
|
||||
|
||||
// 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.GoGoProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type SignedEnvelope struct {
|
||||
PublicKey *PublicKey `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"`
|
||||
PayloadType []byte `protobuf:"bytes,2,opt,name=payload_type,json=payloadType,proto3" json:"payload_type,omitempty"`
|
||||
Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
|
||||
Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"`
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) Reset() { *m = SignedEnvelope{} }
|
||||
func (m *SignedEnvelope) String() string { return proto.CompactTextString(m) }
|
||||
func (*SignedEnvelope) ProtoMessage() {}
|
||||
func (*SignedEnvelope) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_ee266e8c558e9dc5, []int{0}
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_SignedEnvelope.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalTo(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_SignedEnvelope.Merge(m, src)
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *SignedEnvelope) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_SignedEnvelope.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_SignedEnvelope proto.InternalMessageInfo
|
||||
|
||||
func (m *SignedEnvelope) GetPublicKey() *PublicKey {
|
||||
if m != nil {
|
||||
return m.PublicKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) GetPayloadType() []byte {
|
||||
if m != nil {
|
||||
return m.PayloadType
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) GetPayload() []byte {
|
||||
if m != nil {
|
||||
return m.Payload
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) GetSignature() []byte {
|
||||
if m != nil {
|
||||
return m.Signature
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*SignedEnvelope)(nil), "crypto.pb.SignedEnvelope")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("envelope.proto", fileDescriptor_ee266e8c558e9dc5) }
|
||||
|
||||
var fileDescriptor_ee266e8c558e9dc5 = []byte{
|
||||
// 200 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0xcd, 0x2b, 0x4b,
|
||||
0xcd, 0xc9, 0x2f, 0x48, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4c, 0x2e, 0xaa, 0x2c,
|
||||
0x28, 0xc9, 0xd7, 0x2b, 0x48, 0x92, 0xe2, 0x81, 0x31, 0x41, 0x12, 0x4a, 0x0b, 0x18, 0xb9, 0xf8,
|
||||
0x82, 0x33, 0xd3, 0xf3, 0x52, 0x53, 0x5c, 0xa1, 0x3a, 0x84, 0x8c, 0xb9, 0xb8, 0x0a, 0x4a, 0x93,
|
||||
0x72, 0x32, 0x93, 0xe3, 0xb3, 0x53, 0x2b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x44, 0xf4,
|
||||
0xe0, 0x06, 0xe8, 0x05, 0x80, 0x25, 0xbd, 0x53, 0x2b, 0x83, 0x38, 0x0b, 0x60, 0x4c, 0x21, 0x45,
|
||||
0x2e, 0x9e, 0x82, 0xc4, 0xca, 0x9c, 0xfc, 0xc4, 0x94, 0xf8, 0x92, 0xca, 0x82, 0x54, 0x09, 0x26,
|
||||
0x05, 0x46, 0x0d, 0x9e, 0x20, 0x6e, 0xa8, 0x58, 0x48, 0x65, 0x41, 0xaa, 0x90, 0x04, 0x17, 0x3b,
|
||||
0x94, 0x2b, 0xc1, 0x0c, 0x96, 0x85, 0x71, 0x85, 0x64, 0xb8, 0x38, 0x8b, 0x33, 0xd3, 0xf3, 0x12,
|
||||
0x4b, 0x4a, 0x8b, 0x52, 0x25, 0x58, 0xc0, 0x72, 0x08, 0x01, 0x27, 0x89, 0x13, 0x8f, 0xe4, 0x18,
|
||||
0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5,
|
||||
0x18, 0x6e, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xfb, 0xc1, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff,
|
||||
0x40, 0xc9, 0x83, 0xba, 0xee, 0x00, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *SignedEnvelope) MarshalTo(dAtA []byte) (int, error) {
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.PublicKey != nil {
|
||||
dAtA[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintEnvelope(dAtA, i, uint64(m.PublicKey.Size()))
|
||||
n1, err := m.PublicKey.MarshalTo(dAtA[i:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i += n1
|
||||
}
|
||||
if len(m.PayloadType) > 0 {
|
||||
dAtA[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.PayloadType)))
|
||||
i += copy(dAtA[i:], m.PayloadType)
|
||||
}
|
||||
if len(m.Payload) > 0 {
|
||||
dAtA[i] = 0x1a
|
||||
i++
|
||||
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.Payload)))
|
||||
i += copy(dAtA[i:], m.Payload)
|
||||
}
|
||||
if len(m.Signature) > 0 {
|
||||
dAtA[i] = 0x22
|
||||
i++
|
||||
i = encodeVarintEnvelope(dAtA, i, uint64(len(m.Signature)))
|
||||
i += copy(dAtA[i:], m.Signature)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func encodeVarintEnvelope(dAtA []byte, offset int, v uint64) int {
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return offset + 1
|
||||
}
|
||||
func (m *SignedEnvelope) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if m.PublicKey != nil {
|
||||
l = m.PublicKey.Size()
|
||||
n += 1 + l + sovEnvelope(uint64(l))
|
||||
}
|
||||
l = len(m.PayloadType)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovEnvelope(uint64(l))
|
||||
}
|
||||
l = len(m.Payload)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovEnvelope(uint64(l))
|
||||
}
|
||||
l = len(m.Signature)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovEnvelope(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovEnvelope(x uint64) (n int) {
|
||||
for {
|
||||
n++
|
||||
x >>= 7
|
||||
if x == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
func sozEnvelope(x uint64) (n int) {
|
||||
return sovEnvelope(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *SignedEnvelope) 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 ErrIntOverflowEnvelope
|
||||
}
|
||||
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: SignedEnvelope: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: SignedEnvelope: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowEnvelope
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if m.PublicKey == nil {
|
||||
m.PublicKey = &PublicKey{}
|
||||
}
|
||||
if err := m.PublicKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PayloadType", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowEnvelope
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.PayloadType = append(m.PayloadType[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.PayloadType == nil {
|
||||
m.PayloadType = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowEnvelope
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Payload = append(m.Payload[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Payload == nil {
|
||||
m.Payload = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 4:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowEnvelope
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Signature == nil {
|
||||
m.Signature = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipEnvelope(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthEnvelope
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipEnvelope(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowEnvelope
|
||||
}
|
||||
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, ErrIntOverflowEnvelope
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
return iNdEx, nil
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowEnvelope
|
||||
}
|
||||
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, ErrInvalidLengthEnvelope
|
||||
}
|
||||
iNdEx += length
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthEnvelope
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 3:
|
||||
for {
|
||||
var innerWire uint64
|
||||
var start int = iNdEx
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowEnvelope
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
innerWire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
innerWireType := int(innerWire & 0x7)
|
||||
if innerWireType == 4 {
|
||||
break
|
||||
}
|
||||
next, err := skipEnvelope(dAtA[start:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
iNdEx = start + next
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthEnvelope
|
||||
}
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 4:
|
||||
return iNdEx, nil
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
return iNdEx, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthEnvelope = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowEnvelope = fmt.Errorf("proto: integer overflow")
|
||||
)
|
12
crypto/pb/envelope.proto
Normal file
12
crypto/pb/envelope.proto
Normal file
@ -0,0 +1,12 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package crypto.pb;
|
||||
|
||||
import "crypto.proto";
|
||||
|
||||
message SignedEnvelope {
|
||||
PublicKey public_key = 1;
|
||||
bytes payload_type = 2;
|
||||
bytes payload = 3;
|
||||
bytes signature = 4;
|
||||
}
|
Loading…
Reference in New Issue
Block a user