Skip to content
Snippets Groups Projects
tlv_padding.go 885 B
Newer Older
  • Learn to ignore specific revisions
  • Oliver Herms's avatar
    Oliver Herms committed
    import (
    
    Oliver Herms's avatar
    Oliver Herms committed
    // PaddingType is the type value of a padding TLV
    
    const PaddingType = 8
    
    
    Oliver Herms's avatar
    Oliver Herms committed
    // PaddingTLV represents a padding TLV
    
    type PaddingTLV struct {
    	TLVType     uint8
    	TLVLength   uint8
    	PaddingData []byte
    }
    
    
    Oliver Herms's avatar
    Oliver Herms committed
    // NewPaddingTLV creates a new padding TLV
    
    func NewPaddingTLV(length uint8) *PaddingTLV {
    	return &PaddingTLV{
    
    Oliver Herms's avatar
    Oliver Herms committed
    		TLVType:     PaddingType,
    		TLVLength:   length,
    
    		PaddingData: make([]byte, length),
    	}
    }
    
    
    Oliver Herms's avatar
    Oliver Herms committed
    // Type gets the type of the TLV
    
    func (p *PaddingTLV) Type() uint8 {
    	return p.TLVType
    }
    
    
    Oliver Herms's avatar
    Oliver Herms committed
    // Length gets the length of the TLV
    
    func (p *PaddingTLV) Length() uint8 {
    	return p.TLVLength
    }
    
    
    Oliver Herms's avatar
    Oliver Herms committed
    // Value gets the TLV itself
    
    func (p *PaddingTLV) Value() interface{} {
    
    Oliver Herms's avatar
    Oliver Herms committed
    	return p
    
    Oliver Herms's avatar
    Oliver Herms committed
    // Serialize serializes a padding TLV
    
    func (p *PaddingTLV) Serialize(buf *bytes.Buffer) {
    	buf.WriteByte(p.TLVType)
    	buf.WriteByte(p.TLVLength)
    	buf.Write(p.PaddingData)
    
    Oliver Herms's avatar
    Oliver Herms committed
    }