DecodeFromBytes decodes the given bytes into this layer.
(data []byte, df gopacket.DecodeFeedback)
| 183 | |
| 184 | // DecodeFromBytes decodes the given bytes into this layer. |
| 185 | func (ek *EAPOLKey) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { |
| 186 | if len(data) < eapolKeyFrameLen { |
| 187 | df.SetTruncated() |
| 188 | return fmt.Errorf("EAPOLKey length %v too short, %v required", |
| 189 | len(data), eapolKeyFrameLen) |
| 190 | } |
| 191 | |
| 192 | ek.KeyDescriptorType = EAPOLKeyDescriptorType(data[0]) |
| 193 | |
| 194 | info := binary.BigEndian.Uint16(data[1:3]) |
| 195 | ek.KeyDescriptorVersion = EAPOLKeyDescriptorVersion(info & 0x0007) |
| 196 | ek.KeyType = EAPOLKeyType((info & 0x0008) >> 3) |
| 197 | ek.KeyIndex = uint8((info & 0x0030) >> 4) |
| 198 | ek.Install = (info & 0x0040) != 0 |
| 199 | ek.KeyACK = (info & 0x0080) != 0 |
| 200 | ek.KeyMIC = (info & 0x0100) != 0 |
| 201 | ek.Secure = (info & 0x0200) != 0 |
| 202 | ek.MICError = (info & 0x0400) != 0 |
| 203 | ek.Request = (info & 0x0800) != 0 |
| 204 | ek.HasEncryptedKeyData = (info & 0x1000) != 0 |
| 205 | ek.SMKMessage = (info & 0x2000) != 0 |
| 206 | |
| 207 | ek.KeyLength = binary.BigEndian.Uint16(data[3:5]) |
| 208 | ek.ReplayCounter = binary.BigEndian.Uint64(data[5:13]) |
| 209 | |
| 210 | ek.Nonce = data[13:45] |
| 211 | ek.IV = data[45:61] |
| 212 | ek.RSC = binary.BigEndian.Uint64(data[61:69]) |
| 213 | ek.ID = binary.BigEndian.Uint64(data[69:77]) |
| 214 | ek.MIC = data[77:93] |
| 215 | |
| 216 | ek.KeyDataLength = binary.BigEndian.Uint16(data[93:95]) |
| 217 | |
| 218 | totalLength := eapolKeyFrameLen + int(ek.KeyDataLength) |
| 219 | if len(data) < totalLength { |
| 220 | df.SetTruncated() |
| 221 | return fmt.Errorf("EAPOLKey data length %d too short, %d required", |
| 222 | len(data)-eapolKeyFrameLen, ek.KeyDataLength) |
| 223 | } |
| 224 | |
| 225 | if ek.HasEncryptedKeyData { |
| 226 | ek.EncryptedKeyData = data[eapolKeyFrameLen:totalLength] |
| 227 | ek.BaseLayer = BaseLayer{ |
| 228 | Contents: data[:totalLength], |
| 229 | Payload: data[totalLength:], |
| 230 | } |
| 231 | } else { |
| 232 | ek.BaseLayer = BaseLayer{ |
| 233 | Contents: data[:eapolKeyFrameLen], |
| 234 | Payload: data[eapolKeyFrameLen:], |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | return nil |
| 239 | } |
| 240 | |
| 241 | // SerializeTo writes the serialized form of this layer into the |
| 242 | // SerializationBuffer, implementing gopacket.SerializableLayer. |
nothing calls this directly
no test coverage detected