Fix unit tests
[govpp.git] / vendor / github.com / google / gopacket / layers / eapol.go
1 // Copyright 2012 Google, Inc. 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
7 package layers
8
9 import (
10         "encoding/binary"
11         "github.com/google/gopacket"
12 )
13
14 // EAPOL defines an EAP over LAN (802.1x) layer.
15 type EAPOL struct {
16         BaseLayer
17         Version uint8
18         Type    EAPOLType
19         Length  uint16
20 }
21
22 // LayerType returns LayerTypeEAPOL.
23 func (e *EAPOL) LayerType() gopacket.LayerType { return LayerTypeEAPOL }
24
25 // DecodeFromBytes decodes the given bytes into this layer.
26 func (e *EAPOL) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
27         e.Version = data[0]
28         e.Type = EAPOLType(data[1])
29         e.Length = binary.BigEndian.Uint16(data[2:4])
30         e.BaseLayer = BaseLayer{data[:4], data[4:]}
31         return nil
32 }
33
34 // SerializeTo writes the serialized form of this layer into the
35 // SerializationBuffer, implementing gopacket.SerializableLayer
36 func (e *EAPOL) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
37         bytes, _ := b.PrependBytes(4)
38         bytes[0] = e.Version
39         bytes[1] = byte(e.Type)
40         binary.BigEndian.PutUint16(bytes[2:], e.Length)
41         return nil
42 }
43
44 // CanDecode returns the set of layer types that this DecodingLayer can decode.
45 func (e *EAPOL) CanDecode() gopacket.LayerClass {
46         return LayerTypeEAPOL
47 }
48
49 // NextLayerType returns the layer type contained by this DecodingLayer.
50 func (e *EAPOL) NextLayerType() gopacket.LayerType {
51         return e.Type.LayerType()
52 }
53
54 func decodeEAPOL(data []byte, p gopacket.PacketBuilder) error {
55         e := &EAPOL{}
56         return decodingLayerDecoder(e, data, p)
57 }