tls_appdata.go 827 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2018 The GoPacket Authors. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the LICENSE file in the root of the source
  5. // tree.
  6. package layers
  7. import (
  8. "errors"
  9. "github.com/google/gopacket"
  10. )
  11. // TLSAppDataRecord contains all the information that each AppData Record types should have
  12. type TLSAppDataRecord struct {
  13. TLSRecordHeader
  14. Payload []byte
  15. }
  16. // DecodeFromBytes decodes the slice into the TLS struct.
  17. func (t *TLSAppDataRecord) decodeFromBytes(h TLSRecordHeader, data []byte, df gopacket.DecodeFeedback) error {
  18. // TLS Record Header
  19. t.ContentType = h.ContentType
  20. t.Version = h.Version
  21. t.Length = h.Length
  22. if len(data) != int(t.Length) {
  23. return errors.New("TLS Application Data length mismatch")
  24. }
  25. t.Payload = data
  26. return nil
  27. }