ExtractCryptoFramesFromPacket decrypts an Initial packet and extracts CRYPTO frames This is the main entry point for CRYPTO reassembly
(packet []byte)
| 285 | // ExtractCryptoFramesFromPacket decrypts an Initial packet and extracts CRYPTO frames |
| 286 | // This is the main entry point for CRYPTO reassembly |
| 287 | func ExtractCryptoFramesFromPacket(packet []byte) ([]CryptoFrame, error) { |
| 288 | if len(packet) < 5 { |
| 289 | return nil, errors.New("packet too short") |
| 290 | } |
| 291 | |
| 292 | // Verify this is an Initial packet |
| 293 | pktType := ClassifyPacket(packet) |
| 294 | if pktType != PacketInitial { |
| 295 | return nil, &PacketTypeError{Expected: PacketInitial, Got: pktType} |
| 296 | } |
| 297 | |
| 298 | // Parse version |
| 299 | version := binary.BigEndian.Uint32(packet[1:5]) |
| 300 | if version != quicVersion1 { |
| 301 | return nil, fmt.Errorf("unsupported QUIC version: 0x%08x", version) |
| 302 | } |
| 303 | |
| 304 | offset := 5 |
| 305 | |
| 306 | // DCID Length |
| 307 | if offset >= len(packet) { |
| 308 | return nil, errors.New("packet too short for DCID length") |
| 309 | } |
| 310 | dcidLen := int(packet[offset]) |
| 311 | offset++ |
| 312 | |
| 313 | // DCID |
| 314 | if offset+dcidLen > len(packet) { |
| 315 | return nil, errors.New("packet too short for DCID") |
| 316 | } |
| 317 | dcid := packet[offset : offset+dcidLen] |
| 318 | offset += dcidLen |
| 319 | |
| 320 | // SCID Length |
| 321 | if offset >= len(packet) { |
| 322 | return nil, errors.New("packet too short for SCID length") |
| 323 | } |
| 324 | scidLen := int(packet[offset]) |
| 325 | offset++ |
| 326 | offset += scidLen |
| 327 | |
| 328 | // Token Length |
| 329 | tokenLen, n, err := readVarInt(packet[offset:]) |
| 330 | if err != nil { |
| 331 | return nil, fmt.Errorf("failed to read token length: %w", err) |
| 332 | } |
| 333 | offset += n |
| 334 | offset += int(tokenLen) |
| 335 | |
| 336 | // Payload Length |
| 337 | payloadLen, n, err := readVarInt(packet[offset:]) |
| 338 | if err != nil { |
| 339 | return nil, fmt.Errorf("failed to read payload length: %w", err) |
| 340 | } |
| 341 | offset += n |
| 342 | |
| 343 | if offset+int(payloadLen) > len(packet) { |
| 344 | return nil, errors.New("packet too short for payload") |
no test coverage detected