@amritk/nish-aarch64-linux 0.35.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/INSTALL.md +6 -1
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +9 -2
  4. package/package.json +1 -1
  5. package/runtime/nish.d.ts +4612 -430
  6. package/runtime/vite.d.ts +30 -0
  7. package/runtime/vite.mjs +150 -0
  8. package/scripts/build.sh +108 -13
  9. package/std/base64.ts +34 -5
  10. package/std/bytes.ts +256 -40
  11. package/std/cli-args.ts +296 -70
  12. package/std/cli-flags.ts +184 -19
  13. package/std/cli.ts +475 -54
  14. package/std/collections.ts +121 -23
  15. package/std/compress/checksum.ts +44 -14
  16. package/std/compress/deflate.ts +224 -111
  17. package/std/compress/gzip.ts +217 -53
  18. package/std/compress/zlib.ts +63 -7
  19. package/std/crypto/aes.ts +80 -9
  20. package/std/crypto/base64url.ts +22 -0
  21. package/std/crypto/bcrypt-batch.ts +88 -21
  22. package/std/crypto/bcrypt.ts +60 -0
  23. package/std/crypto/chacha20poly1305.ts +53 -0
  24. package/std/crypto/ct.ts +32 -13
  25. package/std/crypto/ed25519.ts +47 -0
  26. package/std/crypto/hkdf.ts +198 -13
  27. package/std/crypto/hmac.ts +235 -31
  28. package/std/crypto/jwt.ts +192 -63
  29. package/std/crypto/p256.ts +159 -16
  30. package/std/crypto/p384.ts +28 -3
  31. package/std/crypto/pki-roots.ts +32 -2
  32. package/std/crypto/pki.ts +81 -15
  33. package/std/crypto/rsa.ts +33 -3
  34. package/std/crypto/sha1.ts +3 -0
  35. package/std/crypto/sha256.ts +24 -1
  36. package/std/crypto/sha512.ts +99 -14
  37. package/std/crypto/x25519.ts +152 -14
  38. package/std/crypto/x509-random.ts +10 -0
  39. package/std/crypto/x509.ts +67 -7
  40. package/std/json-equal.ts +19 -0
  41. package/std/json-format.ts +112 -13
  42. package/std/json-number.ts +64 -14
  43. package/std/json-pointer.ts +23 -1
  44. package/std/json-tokenizer.ts +100 -29
  45. package/std/json-typed.ts +713 -66
  46. package/std/json-value.ts +400 -124
  47. package/std/json.ts +138 -10
  48. package/std/map.ts +25 -7
  49. package/std/math.ts +36 -4
  50. package/std/net/buffer-pool.ts +42 -11
  51. package/std/net/dns-config.ts +109 -23
  52. package/std/net/dns-message.ts +62 -7
  53. package/std/net/dns-resolver.ts +247 -53
  54. package/std/net/dns.ts +203 -35
  55. package/std/net/fetch.ts +151 -61
  56. package/std/net/handler.ts +278 -80
  57. package/std/net/hpack.ts +262 -52
  58. package/std/net/http-compress.ts +125 -15
  59. package/std/net/http-fields.ts +85 -9
  60. package/std/net/http1-client-codec.ts +100 -19
  61. package/std/net/http1-codec.ts +235 -27
  62. package/std/net/http1-server.ts +343 -85
  63. package/std/net/http2-frame.ts +272 -35
  64. package/std/net/http2-tls.ts +135 -34
  65. package/std/net/http2.ts +247 -106
  66. package/std/net/http3-frame.ts +154 -17
  67. package/std/net/http3-server.ts +246 -96
  68. package/std/net/http3.ts +307 -115
  69. package/std/net/outbound.ts +37 -3
  70. package/std/net/postgres-carrier.ts +144 -8
  71. package/std/net/postgres.ts +723 -103
  72. package/std/net/prefork.ts +164 -31
  73. package/std/net/qpack.ts +105 -18
  74. package/std/net/quic-conn-ack.ts +59 -12
  75. package/std/net/quic-conn-cid.ts +124 -27
  76. package/std/net/quic-conn-params.ts +70 -10
  77. package/std/net/quic-datagram.ts +43 -3
  78. package/std/net/quic-frame.ts +286 -12
  79. package/std/net/quic-listener.ts +101 -32
  80. package/std/net/quic-packet.ts +302 -21
  81. package/std/net/quic-recovery.ts +228 -44
  82. package/std/net/quic-stream.ts +353 -91
  83. package/std/net/quic.ts +489 -171
  84. package/std/net/router.ts +87 -40
  85. package/std/net/tls/client.ts +166 -51
  86. package/std/net/tls/codec.ts +413 -56
  87. package/std/net/tls/record-client.ts +110 -55
  88. package/std/net/tls/record-server.ts +159 -59
  89. package/std/net/tls/record.ts +109 -12
  90. package/std/net/tls/schedule.ts +235 -26
  91. package/std/net/tls/ticket.ts +159 -40
  92. package/std/net/tls/verify.ts +49 -3
  93. package/std/net/tls-tcp.ts +250 -45
  94. package/std/net/tls.ts +221 -59
  95. package/std/net/upstream.ts +81 -45
  96. package/std/net/url.ts +97 -13
  97. package/std/net/websocket.ts +122 -12
  98. package/std/net/webtransport.ts +220 -89
  99. package/std/pair.ts +10 -2
  100. package/std/random.ts +34 -9
  101. package/std/regex.ts +352 -198
  102. package/std/region.ts +70 -15
  103. package/std/secret.ts +52 -11
  104. package/std/sort.ts +17 -2
  105. package/std/sqlite.ts +256 -35
  106. package/std/sync/ring.ts +205 -35
  107. package/std/sync/shm.ts +194 -16
  108. package/std/term-io.ts +137 -64
  109. package/std/term-pixels.ts +144 -19
  110. package/std/term-probe.ts +66 -25
  111. package/std/term-rate.ts +128 -57
  112. package/std/term.ts +332 -121
  113. package/std/testing.ts +130 -32
  114. package/std/text.ts +73 -7
  115. package/std/threads.ts +229 -41
  116. package/std/yaml-json.ts +94 -82
  117. package/std/yaml-lines.ts +47 -15
  118. package/std/yaml-write.ts +24 -16
  119. package/std/yaml.ts +764 -384
@@ -5,25 +5,35 @@
5
5
  * Initial secrets, AEAD packet protection, header protection and the Retry
6
6
  * integrity tag.
7
7
  *
8
- * import { quicInitialSecrets, quicKeys, quicParseHeader, quicOpenPacket, QuicKeysSlot,
9
- * QUIC_AEAD_AES_128_GCM, QUIC_PACKET_OK } from "nish/net/quic-packet";
10
- * import { Secret, secret, wipe } from "nish:secret";
8
+ * import { QuicHeader, QuicInitialSecrets, QuicKeys, QuicKeysSlot, QuicPacket, quicInitialSecrets,
9
+ * quicKeys, quicLongHeader, quicOpenPacket, quicParseHeader, quicSealPacket,
10
+ * QUIC_AEAD_AES_128_GCM, QUIC_PACKET_INITIAL, QUIC_PACKET_OK } from "nish/net/quic-packet"
11
+ * import { Secret, secret, wipe } from "nish:secret"
11
12
  *
12
- * const secrets = quicInitialSecrets(clientDcid); // RFC 9001 §5.2
13
- * if (secrets === null) { … a DCID over 20 bytes … }
14
- * const client: u8[] = new Array<u8>(secrets.client.length); // public, so a copy
15
- * client.set(secrets.client);
16
- * const held: Secret<u8[]> = secret(client);
17
- * const slot = new QuicKeysSlot(); // ours, so ours to wipe
18
- * const keys = quicKeys(slot, QUIC_AEAD_AES_128_GCM, held);
19
- * wipe(held);
20
- * if (keys === null) { … }
21
- * const header = quicParseHeader(datagram, 0, 8); // 8: our short-header DCID length
22
- * const packet = quicOpenPacket(keys, datagram, header, largestReceived);
23
- * if (packet.error === QUIC_PACKET_OK) { … packet.payload holds the frames … }
24
- * slot.wipe(); // once the level is done
13
+ * const dcid: u8[] = [0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08]
14
+ * const secrets: QuicInitialSecrets | null = quicInitialSecrets(dcid) // RFC 9001 §5.2
15
+ * if (secrets !== null) {
16
+ * const client: u8[] = new Array<u8>(32) // public, so a copy
17
+ * client.set(secrets.client)
18
+ * const held: Secret<u8[]> = secret(client)
19
+ * const slot: QuicKeysSlot = new QuicKeysSlot() // ours, so ours to wipe
20
+ * const keys: QuicKeys | null = quicKeys(slot, QUIC_AEAD_AES_128_GCM, held)
21
+ * wipe(held)
22
+ * const header: u8[] | null = quicLongHeader(QUIC_PACKET_INITIAL, dcid, [], [], 0, 4, 20)
23
+ * if (keys !== null && header !== null) {
24
+ * const datagram: u8[] | null = quicSealPacket(keys, header, 0, new Array<u8>(20))
25
+ * if (datagram !== null) {
26
+ * const parsed: QuicHeader = quicParseHeader(datagram, 0, 8) // 8: our short DCID length
27
+ * const packet: QuicPacket = quicOpenPacket(keys, datagram, parsed, -1)
28
+ * if (packet.error === QUIC_PACKET_OK) {
29
+ * // packet.payload holds the 20 bytes of frames sealed above
30
+ * }
31
+ * }
32
+ * }
33
+ * slot.wipe() // once the level is done
34
+ * }
25
35
  *
26
- * The module is sans-IO: bytes in, bytes out, no socket and no clock. It
36
+ * **Sans-IO.** The module takes bytes in and gives bytes out, with no socket and no clock. It
27
37
  * frames and protects packets and stops there, so it knows nothing of frames,
28
38
  * of a connection's state or of which keys a level is on; that is
29
39
  * `nish/net/quic` (WP34 Q2). Only version 1 (`0x00000001`) is spoken. A long
@@ -84,12 +94,12 @@
84
94
  * who holds the header-protection key, and RFC 9001 §5.4.1 protects it against
85
95
  * observers, not timing), and whether a payload authenticated.
86
96
  *
87
- * Written from RFC 9000 and RFC 9001, in this module's own structure: nothing
97
+ * **Provenance.** Written from RFC 9000 and RFC 9001, in this module's own structure: nothing
88
98
  * here is ported from another implementation. The packet-number decoding
89
99
  * follows the arithmetic of RFC 9000 §A.3 and the length choice the rule of
90
100
  * §A.2, neither line by line.
91
101
  *
92
- * Private names carry the `quicPacket` prefix because a `std/` module's
102
+ * **Private names.** They carry the `quicPacket` prefix because a `std/` module's
93
103
  * private functions share the importing program's flat symbol namespace
94
104
  * (`docs/wp26-stdlib.md` §3e).
95
105
  */
@@ -246,6 +256,10 @@ export class QuicHeader {
246
256
  tokenStart: i32 = 0
247
257
  tokenLength: i32 = 0
248
258
 
259
+ /**
260
+ * Makes an empty header, every array empty and every window at 0, for
261
+ * `quicParseHeader` or `quicParseHeaderInto` to fill.
262
+ */
249
263
  constructor() {
250
264
  this.dcid = []
251
265
  this.scid = []
@@ -274,6 +288,17 @@ export class QuicKeys {
274
288
  /** `hp` expanded, for the AES suites; `null` for ChaCha20-Poly1305. */
275
289
  hpAes: AesKey | null = null
276
290
 
291
+ /**
292
+ * Wraps keys already derived; the arrays are kept, not copied, so they stay the owner's to wipe.
293
+ * `packetAes` and `hpAes` start `null`; the `quicKeys*` functions fill them for the AES suites. A
294
+ * `QuicKeys` built by hand for an AES suite stays unusable: opening refuses it with `QUIC_ERR_KEYS`, and
295
+ * sealing answers `null`.
296
+ *
297
+ * @param aead The suite, one of the `QUIC_AEAD_*` constants.
298
+ * @param key The packet-protection key: 16 bytes for AES-128-GCM, 32 for the others.
299
+ * @param iv The 12-byte packet IV.
300
+ * @param hp The header-protection key, the same length as `key`.
301
+ */
277
302
  constructor(aead: i32, key: u8[], iv: u8[], hp: u8[]) {
278
303
  this.aead = aead
279
304
  this.key = key
@@ -289,6 +314,12 @@ export class QuicInitialSecrets {
289
314
  /** `server_initial_secret`: what protects the server's. */
290
315
  server: u8[]
291
316
 
317
+ /**
318
+ * Pairs two secrets already derived, keeping the arrays rather than copying them.
319
+ *
320
+ * @param client The 32-byte `client_initial_secret`.
321
+ * @param server The 32-byte `server_initial_secret`.
322
+ */
292
323
  constructor(client: u8[], server: u8[]) {
293
324
  this.client = client
294
325
  this.server = server
@@ -316,6 +347,10 @@ export class QuicPacket {
316
347
  /** A short header's Key Phase bit (RFC 9001 §6); `false` for a long header. */
317
348
  keyPhase: boolean = false
318
349
 
350
+ /**
351
+ * Makes an empty packet, its header and payload empty, for `quicOpenPacket`
352
+ * to fill.
353
+ */
319
354
  constructor() {
320
355
  this.header = []
321
356
  this.payload = []
@@ -362,6 +397,9 @@ const quicPacketAppend = (out: u8[], bytes: u8[]): void => {
362
397
  /**
363
398
  * The bytes a variable-length integer needs (RFC 9000 §16): 1, 2, 4 or 8, or
364
399
  * 0 for a value that has no encoding, below zero or past 2^62 - 1.
400
+ *
401
+ * @param value The integer to encode.
402
+ * @returns The encoded length in bytes, or 0 when `value` has no encoding.
365
403
  */
366
404
  export const quicVarintSize = (value: i64): i32 => {
367
405
  if (value < 0 || value > QUIC_MAX_VARINT) {
@@ -385,6 +423,12 @@ export const quicVarintSize = (value: i64): i32 => {
385
423
  * allows that, and a Length field written before its packet is complete uses
386
424
  * it). Answers `at + size`, or -1, writing nothing, when `size` is not 1, 2,
387
425
  * 4 or 8, is too short for `value`, or does not fit in `buf` from `at`.
426
+ *
427
+ * @param buf The buffer to write into; it is not grown.
428
+ * @param at The byte offset of the integer's first byte.
429
+ * @param value The integer, 0 to 2^62 - 1.
430
+ * @param size The encoded length in bytes: 1, 2, 4 or 8, at least `quicVarintSize(value)`.
431
+ * @returns The byte offset one past the integer, or -1 when nothing was written.
388
432
  */
389
433
  export const quicVarintPut = (buf: u8[], at: i32, value: i64, size: i32): i32 => {
390
434
  const needed: i32 = quicVarintSize(value)
@@ -418,6 +462,9 @@ export const quicVarintPut = (buf: u8[], at: i32, value: i64, size: i32): i32 =>
418
462
  /**
419
463
  * Appends `count` zero bytes to `out`, which a writer then fills in place
420
464
  * with the `put` form of what it appends: one encoder serves both.
465
+ *
466
+ * @param out The array to lengthen.
467
+ * @param count How many zero bytes to append; 0 or less appends none.
421
468
  */
422
469
  export const quicPacketGrow = (out: u8[], count: i32): void => {
423
470
  for (let k: i32 = 0; k < count; k += 1) {
@@ -429,6 +476,11 @@ export const quicPacketGrow = (out: u8[], count: i32): void => {
429
476
  * Appends `value` to `out` as a variable-length integer of exactly `size`
430
477
  * bytes, as `quicVarintPut` writes it. Answers `false`, appending nothing,
431
478
  * when `size` is not 1, 2, 4 or 8 or is too short for `value`.
479
+ *
480
+ * @param out The array to append to.
481
+ * @param value The integer, 0 to 2^62 - 1.
482
+ * @param size The encoded length in bytes: 1, 2, 4 or 8, at least `quicVarintSize(value)`.
483
+ * @returns True when the integer was appended.
432
484
  */
433
485
  export const quicVarintPushSized = (out: u8[], value: i64, size: i32): boolean => {
434
486
  const needed: i32 = quicVarintSize(value)
@@ -444,6 +496,10 @@ export const quicVarintPushSized = (out: u8[], value: i64, size: i32): boolean =
444
496
  * Appends `value` to `out` as a variable-length integer in the fewest bytes
445
497
  * (RFC 9000 §16). Answers `false`, appending nothing, for a value below zero
446
498
  * or past 2^62 - 1.
499
+ *
500
+ * @param out The array to append to.
501
+ * @param value The integer, 0 to 2^62 - 1.
502
+ * @returns True when the integer was appended.
447
503
  */
448
504
  export const quicVarintPush = (out: u8[], value: i64): boolean =>
449
505
  quicVarintPushSized(out, value, quicVarintSize(value))
@@ -452,6 +508,10 @@ export const quicVarintPush = (out: u8[], value: i64): boolean =>
452
508
  * The length of the variable-length integer whose first byte is at
453
509
  * `bytes[at]`, read from its two-bit prefix: 1, 2, 4 or 8. Answers 0 when
454
510
  * `at` is outside `bytes`.
511
+ *
512
+ * @param bytes The bytes holding the integer.
513
+ * @param at The byte offset of the integer's first byte.
514
+ * @returns The integer's length in bytes, which may run past the end of `bytes`; or 0.
455
515
  */
456
516
  export const quicVarintLength = (bytes: u8[], at: i32): i32 => {
457
517
  if (at < 0 || at >= toI32(bytes.length)) {
@@ -465,6 +525,11 @@ export const quicVarintLength = (bytes: u8[], at: i32): i32 => {
465
525
  * from `bytes[at .. end)`. Answers -1, which no varint holds, when it does not
466
526
  * fit in that window or the window is not inside `bytes`. Advance past it by
467
527
  * `quicVarintLength(bytes, at)`.
528
+ *
529
+ * @param bytes The bytes holding the integer.
530
+ * @param at The byte offset of the integer's first byte.
531
+ * @param end The byte offset the integer must end at or before, at most `bytes.length`.
532
+ * @returns The integer, 0 to 2^62 - 1, or -1 when it cannot be read.
468
533
  */
469
534
  export const quicVarintRead = (bytes: u8[], at: i32, end: i32): i64 => {
470
535
  const size: i32 = quicVarintLength(bytes, at)
@@ -484,6 +549,10 @@ export const quicVarintRead = (bytes: u8[], at: i32, end: i32): i64 => {
484
549
  * or -1 if none: enough that twice the unacknowledged range fits, 1 to 4.
485
550
  * Answers 0 when no length will do — `fullPn` not above `largestAcked`, not a
486
551
  * packet number, or more than 2^31 packets unacknowledged.
552
+ *
553
+ * @param fullPn The packet number about to be sent, 0 to 2^62 - 1.
554
+ * @param largestAcked The largest packet number the peer has acknowledged in this space, or -1 for none.
555
+ * @returns The packet-number length in bytes, 1 to 4, or 0 when none will do.
487
556
  */
488
557
  export const quicPacketNumberLength = (fullPn: i64, largestAcked: i64): i32 => {
489
558
  if (fullPn < 0 || fullPn > QUIC_MAX_VARINT || largestAcked < -1 || fullPn <= largestAcked) {
@@ -508,6 +577,11 @@ export const quicPacketNumberLength = (fullPn: i64, largestAcked: i64): i32 => {
508
577
  * that space, or -1 for none (RFC 9000 §17.1, §A.3): the one closest to
509
578
  * `largestPn + 1` whose low bytes are `truncatedPn`. Answers -1 when
510
579
  * `pnLength` is not 1 to 4 or `truncatedPn` does not fit in it.
580
+ *
581
+ * @param largestPn The largest packet number processed in this space, or -1 for none.
582
+ * @param truncatedPn The packet number's low bytes as the header carried them, below 2^(8 × `pnLength`).
583
+ * @param pnLength The packet number's length on the wire, 1 to 4 bytes.
584
+ * @returns The full packet number, 0 to 2^62 - 1, or -1 for an argument out of range.
511
585
  */
512
586
  export const quicPacketNumberDecode = (largestPn: i64, truncatedPn: i64, pnLength: i32): i64 => {
513
587
  if (pnLength < 1 || pnLength > 4 || largestPn < -1 || largestPn > QUIC_MAX_VARINT) {
@@ -543,7 +617,16 @@ const quicPacketCidFits = (cid: u8[]): boolean => toI32(cid.length) <= QUIC_MAX_
543
617
  const quicPacketCidWindowFits = (cid: u8[], length: i32): boolean =>
544
618
  length >= 0 && length <= QUIC_MAX_CID_LENGTH && length <= toI32(cid.length)
545
619
 
546
- /** Writes `bytes[from .. from + length)` into `buf` at `at`; the caller has checked both windows. */
620
+ /**
621
+ * Writes `bytes[from .. from + length)` into `buf` at `at`; the caller has checked both windows.
622
+ * A byte outside either window is skipped rather than written, so a wrong window cannot panic.
623
+ *
624
+ * @param buf The buffer to write into; it is not grown.
625
+ * @param at The byte offset in `buf` of the first byte written.
626
+ * @param bytes The bytes to copy from.
627
+ * @param from The byte offset in `bytes` of the first byte copied.
628
+ * @param length How many bytes to copy.
629
+ */
547
630
  export const quicPacketCopy = (buf: u8[], at: i32, bytes: u8[], from: i32, length: i32): void => {
548
631
  for (let k: i32 = 0; k < length; k += 1) {
549
632
  if (at + k >= 0 && at + k < toI32(buf.length) && from + k >= 0 && from + k < toI32(bytes.length)) {
@@ -601,6 +684,16 @@ const quicPacketPutNumber = (buf: u8[], at: i32, packetNumber: i64, pnLength: i3
601
684
  /**
602
685
  * The size of the long header `quicPutLongHeader` writes for these
603
686
  * arguments, or 0 when it would refuse them (see `quicLongHeader`).
687
+ *
688
+ * @param type `QUIC_PACKET_INITIAL`, `QUIC_PACKET_ZERO_RTT` or `QUIC_PACKET_HANDSHAKE`.
689
+ * @param dcidLength The Destination Connection ID's length in bytes, 0 to 20.
690
+ * @param scidLength The Source Connection ID's length in bytes, 0 to 20.
691
+ * @param tokenLength The token's length in bytes; 0 for anything but an Initial.
692
+ * @param packetNumber The full packet number, 0 to 2^62 - 1; only range-checked, as the size does not
693
+ * depend on it.
694
+ * @param pnLength The packet number's length on the wire, 1 to 4 bytes.
695
+ * @param payloadLength The plaintext payload's length in bytes, without the AEAD tag.
696
+ * @returns The header's length in bytes, packet number included, or 0 for an argument out of range.
604
697
  */
605
698
  export const quicLongHeaderSize = (
606
699
  type: i32,
@@ -638,6 +731,20 @@ export const quicLongHeaderSize = (
638
731
  * bytes of `dcid` and `scid`, and answers the offset past it: where the
639
732
  * payload goes. Answers -1, writing nothing, where `quicLongHeader` answers
640
733
  * `null`, and for a header that does not fit in `buf` from `at`.
734
+ *
735
+ * @param buf The buffer to write into; it is not grown.
736
+ * @param at The byte offset in `buf` where the packet starts.
737
+ * @param type `QUIC_PACKET_INITIAL`, `QUIC_PACKET_ZERO_RTT` or `QUIC_PACKET_HANDSHAKE`.
738
+ * @param dcid The bytes holding the Destination Connection ID at their start.
739
+ * @param dcidLength How many bytes of `dcid` are the ID, 0 to 20.
740
+ * @param scid The bytes holding the Source Connection ID at their start.
741
+ * @param scidLength How many bytes of `scid` are the ID, 0 to 20.
742
+ * @param token The whole of an Initial's token; empty for the other types.
743
+ * @param packetNumber The full packet number, 0 to 2^62 - 1; its low `pnLength` bytes are written.
744
+ * @param pnLength The packet number's length on the wire, 1 to 4 bytes.
745
+ * @param payloadLength The plaintext payload's length in bytes, without the AEAD tag.
746
+ * @returns The byte offset one past the packet number, where the payload goes, or -1 when nothing was
747
+ * written.
641
748
  */
642
749
  export const quicPutLongHeader = (
643
750
  buf: u8[],
@@ -703,6 +810,15 @@ export const quicPutLongHeader = (
703
810
  * on a non-Initial packet, a `pnLength` outside 1 to 4, a packet number that
704
811
  * is not one, a negative `payloadLength`, or a Length past 16383, the most two
705
812
  * bytes hold and far more than a datagram carries.
813
+ *
814
+ * @param type `QUIC_PACKET_INITIAL`, `QUIC_PACKET_ZERO_RTT` or `QUIC_PACKET_HANDSHAKE`.
815
+ * @param dcid The Destination Connection ID, 0 to 20 bytes.
816
+ * @param scid The Source Connection ID, 0 to 20 bytes.
817
+ * @param token An Initial's token, or empty.
818
+ * @param packetNumber The full packet number, 0 to 2^62 - 1; its low `pnLength` bytes are written.
819
+ * @param pnLength The packet number's length on the wire, 1 to 4 bytes.
820
+ * @param payloadLength The plaintext payload's length in bytes, without the AEAD tag.
821
+ * @returns A new array holding the header, or `null` for an argument out of range.
706
822
  */
707
823
  export const quicLongHeader = (
708
824
  type: i32,
@@ -753,6 +869,18 @@ export const quicLongHeader = (
753
869
  * answers, with the Destination Connection ID the first `dcidLength` bytes of
754
870
  * `dcid`, and answers the offset past it. Answers -1, writing nothing, where
755
871
  * `quicShortHeader` answers `null`, and for a header that does not fit.
872
+ *
873
+ * @param buf The buffer to write into; it is not grown.
874
+ * @param at The byte offset in `buf` where the packet starts.
875
+ * @param dcid The bytes holding the Destination Connection ID at their start.
876
+ * @param dcidLength How many bytes of `dcid` are the ID, 0 to 20.
877
+ * @param spin The latency spin bit (RFC 9000 §17.4).
878
+ * @param keyPhase The Key Phase bit, which says which generation of 1-RTT keys protects the packet
879
+ * (RFC 9001 §6).
880
+ * @param packetNumber The full packet number, 0 to 2^62 - 1; its low `pnLength` bytes are written.
881
+ * @param pnLength The packet number's length on the wire, 1 to 4 bytes.
882
+ * @returns The byte offset one past the packet number, where the payload goes, or -1 when nothing was
883
+ * written.
756
884
  */
757
885
  export const quicPutShortHeader = (
758
886
  buf: u8[],
@@ -789,6 +917,14 @@ export const quicPutShortHeader = (
789
917
  * and the packet number in `pnLength` bytes. Answers `null` for a connection
790
918
  * ID over 20 bytes, a `pnLength` outside 1 to 4 or a packet number that is
791
919
  * not one.
920
+ *
921
+ * @param dcid The Destination Connection ID, 0 to 20 bytes.
922
+ * @param spin The latency spin bit (RFC 9000 §17.4).
923
+ * @param keyPhase The Key Phase bit, which says which generation of 1-RTT keys protects the packet
924
+ * (RFC 9001 §6).
925
+ * @param packetNumber The full packet number, 0 to 2^62 - 1; its low `pnLength` bytes are written.
926
+ * @param pnLength The packet number's length on the wire, 1 to 4 bytes.
927
+ * @returns A new array holding the header, or `null` for an argument out of range.
792
928
  */
793
929
  export const quicShortHeader = (
794
930
  dcid: u8[],
@@ -836,6 +972,13 @@ const quicPacketCidLength = (bytes: u8[], at: i32, end: i32): i32 => {
836
972
  * as they were. The datagram is `datagram[at .. limit)`, so one buffer can
837
973
  * hold several (a GRO receive); a `limit` past the array reads as its length.
838
974
  * See `quicParseHeader` for what is read and refused.
975
+ *
976
+ * @param header The header to overwrite; its windows index into `datagram`.
977
+ * @param datagram The received bytes, only read.
978
+ * @param at The byte offset where the packet starts.
979
+ * @param limit The byte offset one past the datagram's end.
980
+ * @param shortDcidLength The length in bytes of the connection IDs this endpoint hands out, 0 to 20.
981
+ * @returns `QUIC_PACKET_OK`, or the `QUIC_ERR_*` that stopped the parse.
839
982
  */
840
983
  export const quicParseHeaderInto = (
841
984
  header: QuicHeader,
@@ -957,6 +1100,11 @@ export const quicParseHeaderInto = (
957
1100
  * answer's arrays; `quicParseHeaderInto` reads the same without a copy.
958
1101
  *
959
1102
  * The answer's `error` says what stopped it; nothing a peer sends panics.
1103
+ *
1104
+ * @param datagram The received bytes, only read; the datagram runs to the array's end.
1105
+ * @param at The byte offset where the packet starts.
1106
+ * @param shortDcidLength The length in bytes of the connection IDs this endpoint hands out, 0 to 20.
1107
+ * @returns A new `QuicHeader`; read its `error` before any other field.
960
1108
  */
961
1109
  export const quicParseHeader = (datagram: u8[], at: i32, shortDcidLength: i32): QuicHeader => {
962
1110
  const header: QuicHeader = new QuicHeader()
@@ -975,6 +1123,9 @@ export const quicParseHeader = (datagram: u8[], at: i32, shortDcidLength: i32):
975
1123
  * ID, `dcid`: `initial_secret` is HKDF-Extract under version 1's salt, and the
976
1124
  * client's and the server's are expanded from it with the labels `client in`
977
1125
  * and `server in`. Answers `null` for a `dcid` over 20 bytes.
1126
+ *
1127
+ * @param dcid The Destination Connection ID of the client's first Initial, 0 to 20 bytes.
1128
+ * @returns The two 32-byte secrets as plain arrays, which are not secret, or `null`.
978
1129
  */
979
1130
  export const quicInitialSecrets = (dcid: u8[]): QuicInitialSecrets | null => {
980
1131
  if (!quicPacketCidFits(dcid)) {
@@ -1063,6 +1214,12 @@ const quicPacketKeysUsable = (keys: QuicKeys): boolean => {
1063
1214
  * this module does not know or a secret that is not that hash's length. The
1064
1215
  * Initial secrets are public (RFC 9001 §5.2), so a caller deriving Initial
1065
1216
  * keys wraps a copy of one in `secret`, or uses `quicKeysInto`.
1217
+ *
1218
+ * @param slot The caller's slot to derive into; its earlier keys are overwritten.
1219
+ * @param aead The negotiated suite, one of the `QUIC_AEAD_*` constants.
1220
+ * @param trafficSecret The level's traffic secret, 32 bytes (48 for AES-256-GCM); borrowed: it is
1221
+ * not wiped here, and the caller wipes it once no more keys come from it.
1222
+ * @returns `slot.keys`, valid until the slot is derived into again or wiped, or `null`.
1066
1223
  */
1067
1224
  export const quicKeys = (slot: QuicKeysSlot, aead: i32, trafficSecret: Secret<u8[]>): QuicKeys | null => {
1068
1225
  if (!quicPacketHeldFits(aead, trafficSecret)) {
@@ -1084,6 +1241,10 @@ export const quicKeys = (slot: QuicKeysSlot, aead: i32, trafficSecret: Secret<u8
1084
1241
  * answered as a `Secret` the caller wipes. The header-protection key does
1085
1242
  * not change with it (§6), so the new keys are `quicKeysUpdate` of the old
1086
1243
  * keys and this. Answers `null` where `quicKeys` would.
1244
+ *
1245
+ * @param aead The negotiated suite, one of the `QUIC_AEAD_*` constants.
1246
+ * @param trafficSecret The current generation's traffic secret; borrowed, and left for the caller to wipe.
1247
+ * @returns The next generation's secret, a new `Secret` the caller owns and wipes, or `null`.
1087
1248
  */
1088
1249
  export const quicKeyUpdateSecret = (aead: i32, trafficSecret: Secret<u8[]>): Secret<u8[]> | null => {
1089
1250
  if (!quicPacketHeldFits(aead, trafficSecret)) {
@@ -1103,6 +1264,11 @@ export const quicKeyUpdateSecret = (aead: i32, trafficSecret: Secret<u8[]>): Sec
1103
1264
  * schedule, in the slot, so wiping one generation leaves the other usable.
1104
1265
  * Answers the slot's keys, or `null`, deriving nothing, for keys `quicKeys`
1105
1266
  * did not make, keys that live in `slot`, or a secret of the wrong length.
1267
+ *
1268
+ * @param slot The caller's slot for the next generation; a different slot from the one `keys` live in.
1269
+ * @param keys The current generation's keys, whose header-protection key is copied; left unchanged.
1270
+ * @param nextSecret The next generation's traffic secret; borrowed, and left for the caller to wipe.
1271
+ * @returns `slot.keys`, valid until the slot is derived into again or wiped, or `null`.
1106
1272
  */
1107
1273
  export const quicKeysUpdate = (
1108
1274
  slot: QuicKeysSlot,
@@ -1136,6 +1302,9 @@ export const quicKeysUpdate = (
1136
1302
  * kernels' powers of H included) and H itself. It zeroes the arrays `keys`
1137
1303
  * points at now; a slot's arrays of the other lengths are
1138
1304
  * `QuicKeysSlot.wipe`'s, which zeroes them all.
1305
+ *
1306
+ * @param keys The keys to zero. Nothing marks them wiped and nothing refuses them afterwards, so derive
1307
+ * into them again before sealing or opening with them.
1139
1308
  */
1140
1309
  export const quicKeysWipe = (keys: QuicKeys): void => {
1141
1310
  secureZero(keys.key)
@@ -1175,6 +1344,10 @@ export class QuicKeysSlot {
1175
1344
  hp128: AesKey
1176
1345
  hp256: AesKey
1177
1346
 
1347
+ /**
1348
+ * Makes the slot's arrays and key schedules once, with no keys derived yet
1349
+ * (`keys.aead` is 0).
1350
+ */
1178
1351
  constructor() {
1179
1352
  this.key16 = new Array<u8>(16)
1180
1353
  this.key32 = new Array<u8>(32)
@@ -1223,7 +1396,7 @@ const quicPacketPoint = (slot: QuicKeysSlot, aead: i32): void => {
1223
1396
  /**
1224
1397
  * `quicPacketDerive` in place: the packet key and IV from `secret` into
1225
1398
  * `keys`' own arrays, and for the AES suites the key's schedule expanded
1226
- * into its own `AesKey`. HKDF runs in `kdf`, which wipes what it held, and
1399
+ * into its own `AesKey`. HKDF runs in `kdf`, which wipes its secret-bearing fields, and
1227
1400
  * the expansion's temporaries go with the arena block.
1228
1401
  */
1229
1402
  const quicPacketDeriveInto = (kdf: HkdfScratch, keys: QuicKeys, secret: u8[]): void => {
@@ -1245,6 +1418,14 @@ const quicPacketDeriveInto = (kdf: HkdfScratch, keys: QuicKeys, secret: u8[]): v
1245
1418
  * `kdf`, with the AES schedules expanded in place. Answers the slot's keys,
1246
1419
  * or `null`, deriving nothing, where `quicKeys` answers `null`. The keys
1247
1420
  * are the slot's: the next derivation into it overwrites them.
1421
+ *
1422
+ * @param kdf The caller's HKDF scratch, reused across derivations; its secret-bearing fields are wiped
1423
+ * before each returns (its `info` label is not).
1424
+ * @param slot The caller's slot to derive into; its earlier keys are overwritten.
1425
+ * @param aead The negotiated suite, one of the `QUIC_AEAD_*` constants.
1426
+ * @param secret The traffic secret as a plain array, 32 bytes (48 for AES-256-GCM); only read, and not
1427
+ * wiped, so a caller passing a non-Initial secret wipes it.
1428
+ * @returns `slot.keys`, valid until the slot is derived into again or wiped, or `null`.
1248
1429
  */
1249
1430
  export const quicKeysInto = (
1250
1431
  kdf: HkdfScratch,
@@ -1286,6 +1467,16 @@ export const quicKeysInto = (
1286
1467
  * the next generation's packet key and IV from `nextSecret`, and `keys`'
1287
1468
  * header-protection key shared, as every generation shares it (RFC 9001
1288
1469
  * §6). Answers the slot's keys, or `null` where `quicKeysUpdate` does.
1470
+ * Unlike `quicKeysUpdate` the header-protection key and its schedule are the
1471
+ * same arrays as `keys`', not a copy, so wiping either generation zeroes the
1472
+ * header-protection key both use.
1473
+ *
1474
+ * @param kdf The caller's HKDF scratch, reused across derivations; its secret-bearing fields are wiped
1475
+ * before each returns (its `info` label is not).
1476
+ * @param slot The caller's slot for the next generation; a different slot from the one `keys` live in.
1477
+ * @param keys The current generation's keys, whose header-protection arrays are shared; left unchanged.
1478
+ * @param nextSecret The next generation's traffic secret as a plain array; only read, and not wiped.
1479
+ * @returns `slot.keys`, valid until the slot is derived into again or wiped, or `null`.
1289
1480
  */
1290
1481
  export const quicKeysUpdateInto = (
1291
1482
  kdf: HkdfScratch,
@@ -1308,6 +1499,13 @@ export const quicKeysUpdateInto = (
1308
1499
  * `quicKeyUpdateSecret` into `out`, which must be exactly the secret's
1309
1500
  * length and not `secret` itself. Answers whether it derived, which it does
1310
1501
  * where `quicKeyUpdateSecret` answers a secret.
1502
+ *
1503
+ * @param kdf The caller's HKDF scratch, reused across derivations; its secret-bearing fields are wiped
1504
+ * before each returns (its `info` label is not).
1505
+ * @param aead The negotiated suite, one of the `QUIC_AEAD_*` constants.
1506
+ * @param secret The current traffic secret as a plain array; only read, and not wiped.
1507
+ * @param out The array the next secret is written over, 32 bytes (48 for AES-256-GCM).
1508
+ * @returns True when `out` holds the next secret; false, `out` untouched, for a wrong length or `aead`.
1311
1509
  */
1312
1510
  export const quicKeyUpdateSecretInto = (kdf: HkdfScratch, aead: i32, secret: u8[], out: u8[]): boolean => {
1313
1511
  const length: i32 = quicPacketSecretLength(aead)
@@ -1326,6 +1524,11 @@ export const quicKeyUpdateSecretInto = (kdf: HkdfScratch, aead: i32, secret: u8[
1326
1524
  * the plain output of each derivation wiped, and the AES schedules expanded
1327
1525
  * in place inside an arena block. Answers the slot's keys, or `null`,
1328
1526
  * deriving nothing, where `quicKeys` answers `null`.
1527
+ *
1528
+ * @param slot The caller's slot to derive into; its earlier keys are overwritten.
1529
+ * @param aead The negotiated suite, one of the `QUIC_AEAD_*` constants.
1530
+ * @param secret The traffic secret, 32 bytes (48 for AES-256-GCM); borrowed, and left for the caller to wipe.
1531
+ * @returns `slot.keys`, valid until the slot is derived into again or wiped, or `null`.
1329
1532
  */
1330
1533
  export const quicKeysHeldInto = (slot: QuicKeysSlot, aead: i32, secret: Secret<u8[]>): QuicKeys | null => {
1331
1534
  if (!quicPacketHeldFits(aead, secret)) {
@@ -1357,6 +1560,10 @@ export const quicKeysHeldInto = (slot: QuicKeysSlot, aead: i32, secret: Secret<u
1357
1560
  * bytes in place, under SHA-384 for a 48-byte secret and SHA-256 for a
1358
1561
  * 32-byte one. `dst` may be `src`, which ratchets it. Answers whether it
1359
1562
  * derived: not unless both hold 32 bytes or both 48.
1563
+ *
1564
+ * @param dst The secret overwritten with the next generation's; the caller's, and the caller wipes it.
1565
+ * @param src The current generation's secret; borrowed, and not wiped here unless it is `dst`.
1566
+ * @returns True when `dst` holds the next secret; false, both untouched, for mismatched or wrong lengths.
1360
1567
  */
1361
1568
  export const quicKeyUpdateSecretHeldInto = (dst: Secret<u8[]>, src: Secret<u8[]>): boolean => {
1362
1569
  const length: i32 = expose(src, quicPacketBytesLength)
@@ -1377,6 +1584,15 @@ export const quicKeyUpdateSecretHeldInto = (dst: Secret<u8[]>, src: Secret<u8[]>
1377
1584
  * length)`, read in place, into `client` and `server`, 32 bytes each.
1378
1585
  * Answers whether it derived: not for an ID over 20 bytes, a window outside
1379
1586
  * `buf`, or an output of another length.
1587
+ *
1588
+ * @param kdf The caller's HKDF scratch, reused across derivations; its secret-bearing fields are wiped
1589
+ * before each returns (its `info` label is not).
1590
+ * @param buf The bytes holding the client's first Destination Connection ID, such as the datagram.
1591
+ * @param at The byte offset in `buf` where the ID starts.
1592
+ * @param length The ID's length in bytes, 0 to 20.
1593
+ * @param client The 32-byte array `client_initial_secret` is written over.
1594
+ * @param server The 32-byte array `server_initial_secret` is written over.
1595
+ * @returns True when both secrets were written; false, both untouched, otherwise.
1380
1596
  */
1381
1597
  export const quicInitialSecretsInto = (
1382
1598
  kdf: HkdfScratch,
@@ -1472,6 +1688,14 @@ const quicPacketOpen = (keys: QuicKeys, nonce: u8[], aad: u8[], sealed: u8[]): u
1472
1688
  * `buf` not to be sent, for anything `quicSealPacket` refuses and for a tag
1473
1689
  * that does not fit in `buf`. The AEAD's temporaries are released before it
1474
1690
  * answers, so sealing allocates nothing that outlives the call.
1691
+ *
1692
+ * @param keys The level's keys, as `quicKeys` or one of its `Into` forms made them.
1693
+ * @param buf The buffer holding the packet; it is not grown, so it needs 16 bytes of room past the payload.
1694
+ * @param start The byte offset in `buf` where the packet starts.
1695
+ * @param headerLength The header's length in bytes, packet number included.
1696
+ * @param payloadLength The plaintext payload's length in bytes; with the packet number, at least 4.
1697
+ * @param packetNumber The full packet number the header carries, 0 to 2^62 - 1.
1698
+ * @returns The byte offset one past the AEAD tag, or -1 when the packet is not to be sent.
1475
1699
  */
1476
1700
  export const quicSealInPlace = (
1477
1701
  keys: QuicKeys,
@@ -1568,6 +1792,12 @@ export const quicSealInPlace = (
1568
1792
  * must be at least 4 bytes; a shorter payload has to be padded first (RFC 9001
1569
1793
  * §5.4.2). Answers `null` for any of those, for a header too short for its
1570
1794
  * packet-number length, and for keys `quicKeys` did not make.
1795
+ *
1796
+ * @param keys The level's keys, as `quicKeys` or one of its `Into` forms made them.
1797
+ * @param header The unprotected header, only read.
1798
+ * @param packetNumber The full packet number the header carries, 0 to 2^62 - 1.
1799
+ * @param payload The plaintext frames, only read.
1800
+ * @returns A new array holding the protected packet, 16 bytes longer than header and payload, or `null`.
1571
1801
  */
1572
1802
  export const quicSealPacket = (
1573
1803
  keys: QuicKeys,
@@ -1594,6 +1824,13 @@ export const quicSealPacket = (
1594
1824
  * associated data: empty when `error` is not `QUIC_PACKET_OK`. Only numbers
1595
1825
  * are stored into `packet`, so a connection reuses one for every packet and
1596
1826
  * the answer is its own to let go. See `quicRemoveHeaderProtection`.
1827
+ *
1828
+ * @param keys The level's keys, as `quicKeys` or one of its `Into` forms made them.
1829
+ * @param datagram The received bytes `header` was parsed from, only read.
1830
+ * @param header The packet's parsed header.
1831
+ * @param largestPn The largest packet number processed in the packet's space, or -1 for none.
1832
+ * @param packet The result to overwrite; its `header` and `payload` arrays are not touched.
1833
+ * @returns A new array holding the header in the clear, or an empty one when `packet.error` is set.
1597
1834
  */
1598
1835
  export const quicUnprotectHeader = (
1599
1836
  keys: QuicKeys,
@@ -1686,6 +1923,12 @@ export const quicUnprotectHeader = (
1686
1923
  * `error` is the header's own for a header that did not parse,
1687
1924
  * `QUIC_ERR_NOT_PROTECTED` for a Retry, `QUIC_ERR_KEYS` for keys `quicKeys`
1688
1925
  * did not make, and `QUIC_ERR_SAMPLE` for a packet too short to sample.
1926
+ *
1927
+ * @param keys The level's keys; the whole set must be usable, though only the header-protection key is used.
1928
+ * @param datagram The received bytes `header` was parsed from, only read.
1929
+ * @param header The packet's parsed header.
1930
+ * @param largestPn The largest packet number processed in the packet's space, or -1 for none.
1931
+ * @returns A new `QuicPacket` with no payload yet; read its `error` before any other field.
1689
1932
  */
1690
1933
  export const quicRemoveHeaderProtection = (
1691
1934
  keys: QuicKeys,
@@ -1704,6 +1947,13 @@ export const quicRemoveHeaderProtection = (
1704
1947
  * changing `datagram`. Sets `packet.error` as `quicDecryptPacket` does and
1705
1948
  * answers the plaintext frames, or `null` when they did not authenticate
1706
1949
  * (or `packet` was already in error). Only numbers are stored into `packet`.
1950
+ *
1951
+ * @param keys The level's keys, as `quicKeys` or one of its `Into` forms made them.
1952
+ * @param datagram The received bytes `header` was parsed from, only read.
1953
+ * @param header The packet's parsed header.
1954
+ * @param clear What `quicUnprotectHeader` answered for this packet: the AEAD's associated data.
1955
+ * @param packet The result `quicUnprotectHeader` filled for this packet; only its `error` is changed.
1956
+ * @returns A new array holding the frames, also for `QUIC_ERR_RESERVED_BITS`, or `null`.
1707
1957
  */
1708
1958
  export const quicDecryptPayload = (
1709
1959
  keys: QuicKeys,
@@ -1748,6 +1998,13 @@ export const quicDecryptPayload = (
1748
1998
  * does but the header's reserved bits are not zero (RFC 9000 §17.2, §17.3.1),
1749
1999
  * which the caller is to close the connection over. Answers whether the
1750
2000
  * payload authenticated. A packet already in error is left as it is.
2001
+ *
2002
+ * @param keys The level's keys, as `quicKeys` or one of its `Into` forms made them.
2003
+ * @param datagram The received bytes `header` was parsed from, only read.
2004
+ * @param header The packet's parsed header.
2005
+ * @param packet What `quicRemoveHeaderProtection` answered for this packet.
2006
+ * @returns True when the payload authenticated, `QUIC_ERR_RESERVED_BITS` included, so read
2007
+ * `packet.error` too.
1751
2008
  */
1752
2009
  export const quicDecryptPacket = (
1753
2010
  keys: QuicKeys,
@@ -1769,6 +2026,12 @@ export const quicDecryptPacket = (
1769
2026
  * payload decrypted. The answer's `error` is `QUIC_PACKET_OK` with `payload`
1770
2027
  * holding the frames, or the `QUIC_ERR_*` of the step that failed — see
1771
2028
  * `quicRemoveHeaderProtection` and `quicDecryptPacket`.
2029
+ *
2030
+ * @param keys The level's keys, as `quicKeys` or one of its `Into` forms made them.
2031
+ * @param datagram The received bytes `header` was parsed from, only read.
2032
+ * @param header The packet's parsed header.
2033
+ * @param largestPn The largest packet number processed in the packet's space, or -1 for none.
2034
+ * @returns A new `QuicPacket`; read its `error` before any other field.
1772
2035
  */
1773
2036
  export const quicOpenPacket = (
1774
2037
  keys: QuicKeys,
@@ -1787,6 +2050,10 @@ export const quicOpenPacket = (
1787
2050
  * `odcid`'s length and bytes, then the Retry packet up to its tag — as the
1788
2051
  * associated data. `odcid` is the Destination Connection ID of the client's
1789
2052
  * Initial the Retry answers. Answers `null` for an `odcid` over 20 bytes.
2053
+ *
2054
+ * @param odcid The Destination Connection ID of the client's first Initial, 0 to 20 bytes.
2055
+ * @param retryWithoutTag The Retry packet from its first byte to just before the tag, only read.
2056
+ * @returns The 16-byte tag as a new array, or `null`.
1790
2057
  */
1791
2058
  export const quicRetryIntegrityTag = (odcid: u8[], retryWithoutTag: u8[]): u8[] | null => {
1792
2059
  const key: AesKey | null = aesKey(quicPacketRetryKey())
@@ -1808,6 +2075,13 @@ export const quicRetryIntegrityTag = (odcid: u8[], retryWithoutTag: u8[]): u8[]
1808
2075
  * DCID the client's Initial was sent to. Answers `null` for a connection ID
1809
2076
  * over 20 bytes, an empty token (a client discards that Retry, §17.2.5.2) or
1810
2077
  * `unused` outside 0 to 15.
2078
+ *
2079
+ * @param dcid The client's Source Connection ID, which the Retry is sent to; 0 to 20 bytes.
2080
+ * @param scid The server's new Source Connection ID, 0 to 20 bytes.
2081
+ * @param token The address-validation token the client is to echo; at least one byte.
2082
+ * @param odcid The Destination Connection ID of the client's first Initial, 0 to 20 bytes.
2083
+ * @param unused The first byte's four low bits, 0 to 15.
2084
+ * @returns A new array holding the whole Retry, tag included, or `null`.
1811
2085
  */
1812
2086
  export const quicRetryPacket = (
1813
2087
  dcid: u8[],
@@ -1843,6 +2117,13 @@ export const quicRetryPacket = (
1843
2117
  * `odcid`, the DCID of the Initial this client sent (RFC 9001 §5.8). The tag
1844
2118
  * is recomputed over the datagram's bytes and compared in constant time.
1845
2119
  * Answers `false` for a header that is not a Retry that parsed.
2120
+ *
2121
+ * @param odcid The Destination Connection ID of the Initial this client sent.
2122
+ * @param datagram The received bytes `header` was parsed from, only read.
2123
+ * @param header The Retry's header from `quicParseHeader`, which copies out `retryTag`;
2124
+ * `quicParseHeaderInto` leaves that array as it was.
2125
+ * @returns True when the integrity tag is valid for `odcid`: the packet was not altered and answers the
2126
+ * Initial that carried that DCID. It authenticates nothing more (RFC 9001 §5.8).
1846
2127
  */
1847
2128
  export const quicRetryVerify = (odcid: u8[], datagram: u8[], header: QuicHeader): boolean => {
1848
2129
  if (header.error !== QUIC_PACKET_OK || header.type !== QUIC_PACKET_RETRY) {