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