function espPacket
espPacket(): Coder<EspPacket>

Creates a coder for an IPsec ESP header (RFC 4303) — an 8-byte header (spi, sequenceNumber) followed by a payload that absorbs the rest of the buffer on decode.

The payload is never parsed or decrypted: RFC 4303's padding, pad-length, next-header and ICV trailer fields all live inside the encrypted region, so locating them requires the security association's cipher and key, which this package does not have.

Examples

Decode a known-wire ESP header

import { assertEquals } from "@std/assert";
import { espPacket, ESP_HEADER_SIZE } from "@binstruct/esp";

// deno-fmt-ignore
const wire = new Uint8Array([
  0x00, 0x00, 0x03, 0x00, // spi = 768
  0x00, 0x00, 0x00, 0x01, // sequenceNumber = 1
  0xaa, 0xbb, 0xcc, 0xdd, // opaque payloadData
]);

const [decoded, read] = espPacket().decode(wire);

assertEquals(read, wire.length);
assertEquals(decoded.spi, 768);
assertEquals(decoded.sequenceNumber, 1);
assertEquals(decoded.payloadData, wire.subarray(ESP_HEADER_SIZE));

Return Type

Coder<EspPacket>

A coder for EspPacket.

Usage

import { espPacket } from ".";