tls_cipherspec.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // TLSchangeCipherSpec defines the message value inside ChangeCipherSpec Record
  12. type TLSchangeCipherSpec uint8
  13. const (
  14. TLSChangecipherspecMessage TLSchangeCipherSpec = 1
  15. TLSChangecipherspecUnknown TLSchangeCipherSpec = 255
  16. )
  17. // TLS Change Cipher Spec
  18. // 0 1 2 3 4 5 6 7 8
  19. // +--+--+--+--+--+--+--+--+
  20. // | Message |
  21. // +--+--+--+--+--+--+--+--+
  22. // TLSChangeCipherSpecRecord defines the type of data inside ChangeCipherSpec Record
  23. type TLSChangeCipherSpecRecord struct {
  24. TLSRecordHeader
  25. Message TLSchangeCipherSpec
  26. }
  27. // DecodeFromBytes decodes the slice into the TLS struct.
  28. func (t *TLSChangeCipherSpecRecord) decodeFromBytes(h TLSRecordHeader, data []byte, df gopacket.DecodeFeedback) error {
  29. // TLS Record Header
  30. t.ContentType = h.ContentType
  31. t.Version = h.Version
  32. t.Length = h.Length
  33. if len(data) != 1 {
  34. df.SetTruncated()
  35. return errors.New("TLS Change Cipher Spec record incorrect length")
  36. }
  37. t.Message = TLSchangeCipherSpec(data[0])
  38. if t.Message != TLSChangecipherspecMessage {
  39. t.Message = TLSChangecipherspecUnknown
  40. }
  41. return nil
  42. }
  43. // String shows the message value nicely formatted
  44. func (ccs TLSchangeCipherSpec) String() string {
  45. switch ccs {
  46. default:
  47. return "Unknown"
  48. case TLSChangecipherspecMessage:
  49. return "Change Cipher Spec Message"
  50. }
  51. }