record: convert child_index from uint16 to uint32

This commit is contained in:
Conner Fromknecht 2021-03-24 19:47:01 -07:00
parent 46c9140ac0
commit 8fe4de88c1
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 8 additions and 8 deletions

@ -16,12 +16,12 @@ const AMPOnionType tlv.Type = 10
type AMP struct { type AMP struct {
rootShare [32]byte rootShare [32]byte
setID [32]byte setID [32]byte
childIndex uint16 childIndex uint32
} }
// NewAMP generate a new AMP record with the given root_share, set_id, and // NewAMP generate a new AMP record with the given root_share, set_id, and
// child_index. // child_index.
func NewAMP(rootShare, setID [32]byte, childIndex uint16) *AMP { func NewAMP(rootShare, setID [32]byte, childIndex uint32) *AMP {
return &AMP{ return &AMP{
rootShare: rootShare, rootShare: rootShare,
setID: setID, setID: setID,
@ -40,7 +40,7 @@ func (a *AMP) SetID() [32]byte {
} }
// ChildIndex returns the child index contained in the AMP record. // ChildIndex returns the child index contained in the AMP record.
func (a *AMP) ChildIndex() uint16 { func (a *AMP) ChildIndex() uint32 {
return a.childIndex return a.childIndex
} }
@ -55,7 +55,7 @@ func AMPEncoder(w io.Writer, val interface{}, buf *[8]byte) error {
return err return err
} }
return tlv.ETUint16T(w, v.childIndex, buf) return tlv.ETUint32T(w, v.childIndex, buf)
} }
return tlv.NewTypeForEncodingErr(val, "AMP") return tlv.NewTypeForEncodingErr(val, "AMP")
} }
@ -69,7 +69,7 @@ const (
// maxAMPLength is the maximum legnth of a serialized AMP TLV record, // maxAMPLength is the maximum legnth of a serialized AMP TLV record,
// which occurs when the truncated endoing of a child_index takes 2 // which occurs when the truncated endoing of a child_index takes 2
// bytes. // bytes.
maxAMPLength = 66 maxAMPLength = 68
) )
// AMPDecoder reads the AMP record from the provided io.Reader. // AMPDecoder reads the AMP record from the provided io.Reader.
@ -83,7 +83,7 @@ func AMPDecoder(r io.Reader, val interface{}, buf *[8]byte, l uint64) error {
return err return err
} }
return tlv.DTUint16(r, &v.childIndex, buf, l-64) return tlv.DTUint32(r, &v.childIndex, buf, l-minAMPLength)
} }
return tlv.NewTypeForDecodingErr(val, "AMP", l, maxAMPLength) return tlv.NewTypeForDecodingErr(val, "AMP", l, maxAMPLength)
} }
@ -97,7 +97,7 @@ func (a *AMP) Record() tlv.Record {
// PayloadSize returns the size this record takes up in encoded form. // PayloadSize returns the size this record takes up in encoded form.
func (a *AMP) PayloadSize() uint64 { func (a *AMP) PayloadSize() uint64 {
return 32 + 32 + tlv.SizeTUint16(a.childIndex) return 32 + 32 + tlv.SizeTUint32(a.childIndex)
} }
// String returns a human-readble description of the amp payload fields. // String returns a human-readble description of the amp payload fields.

@ -21,7 +21,7 @@ var (
testAddr = [32]byte{0x01, 0x02} testAddr = [32]byte{0x01, 0x02}
testShare = [32]byte{0x03, 0x04} testShare = [32]byte{0x03, 0x04}
testSetID = [32]byte{0x05, 0x06} testSetID = [32]byte{0x05, 0x06}
testChildIndex = uint16(17) testChildIndex = uint32(17)
) )
var recordEncDecTests = []recordEncDecTest{ var recordEncDecTests = []recordEncDecTest{