package proxy import "mpbl3p/shared" type Packet interface { Marshal() []byte Contents() []byte } type SimplePacket []byte // get the raw data of the IP packet func (p SimplePacket) Marshal() []byte { return p } func (p SimplePacket) Contents() []byte { return p } func AppendMac(b []byte, g MacGenerator) []byte { mac := g.Generate(b) return append(b, mac...) } func StripMac(b []byte, v MacVerifier) ([]byte, error) { if len(b) < v.CodeLength() { return nil, shared.ErrNotEnoughBytes } data := b[:len(b)-v.CodeLength()] sum := b[len(b)-v.CodeLength():] if err := v.Verify(data, sum); err != nil { return nil, err } return data, nil }