package proxy import ( "encoding/binary" "time" ) 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 { footer := make([]byte, 8) unixTime := uint64(time.Now().Unix()) binary.LittleEndian.PutUint64(footer, unixTime) b = append(b, footer...) mac := g.Generate(b) return append(b, mac...) } func StripMac(b []byte, v MacVerifier) ([]byte, error) { data := b[:len(b)-v.CodeLength()] sum := b[len(b)-v.CodeLength():] if err := v.Verify(data, sum); err != nil { return nil, err } // TODO: Verify timestamp return data[:len(data)-8], nil }