SerializeTo writes the serialized form of this layer into the SerializationBuffer, implementing gopacket.SerializableLayer. See the docs for gopacket.SerializableLayer for more info.
(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions)
| 242 | // SerializationBuffer, implementing gopacket.SerializableLayer. |
| 243 | // See the docs for gopacket.SerializableLayer for more info. |
| 244 | func (ek *EAPOLKey) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 245 | buf, err := b.PrependBytes(eapolKeyFrameLen + len(ek.EncryptedKeyData)) |
| 246 | if err != nil { |
| 247 | return err |
| 248 | } |
| 249 | |
| 250 | buf[0] = byte(ek.KeyDescriptorType) |
| 251 | |
| 252 | var info uint16 |
| 253 | info |= uint16(ek.KeyDescriptorVersion) |
| 254 | info |= uint16(ek.KeyType) << 3 |
| 255 | info |= uint16(ek.KeyIndex) << 4 |
| 256 | if ek.Install { |
| 257 | info |= 0x0040 |
| 258 | } |
| 259 | if ek.KeyACK { |
| 260 | info |= 0x0080 |
| 261 | } |
| 262 | if ek.KeyMIC { |
| 263 | info |= 0x0100 |
| 264 | } |
| 265 | if ek.Secure { |
| 266 | info |= 0x0200 |
| 267 | } |
| 268 | if ek.MICError { |
| 269 | info |= 0x0400 |
| 270 | } |
| 271 | if ek.Request { |
| 272 | info |= 0x0800 |
| 273 | } |
| 274 | if ek.HasEncryptedKeyData { |
| 275 | info |= 0x1000 |
| 276 | } |
| 277 | if ek.SMKMessage { |
| 278 | info |= 0x2000 |
| 279 | } |
| 280 | binary.BigEndian.PutUint16(buf[1:3], info) |
| 281 | |
| 282 | binary.BigEndian.PutUint16(buf[3:5], ek.KeyLength) |
| 283 | binary.BigEndian.PutUint64(buf[5:13], ek.ReplayCounter) |
| 284 | |
| 285 | copy(buf[13:45], ek.Nonce) |
| 286 | copy(buf[45:61], ek.IV) |
| 287 | binary.BigEndian.PutUint64(buf[61:69], ek.RSC) |
| 288 | binary.BigEndian.PutUint64(buf[69:77], ek.ID) |
| 289 | copy(buf[77:93], ek.MIC) |
| 290 | |
| 291 | binary.BigEndian.PutUint16(buf[93:95], ek.KeyDataLength) |
| 292 | if len(ek.EncryptedKeyData) > 0 { |
| 293 | copy(buf[95:95+len(ek.EncryptedKeyData)], ek.EncryptedKeyData) |
| 294 | } |
| 295 | |
| 296 | return nil |
| 297 | } |
| 298 | |
| 299 | func decodeEAPOLKey(data []byte, p gopacket.PacketBuilder) error { |
| 300 | ek := &EAPOLKey{} |
nothing calls this directly
no test coverage detected