nish 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 (118) hide show
  1. package/docs/AI.md +9 -2
  2. package/docs/INSTALL.md +6 -1
  3. package/package.json +15 -5
  4. package/runtime/nish.d.ts +4612 -430
  5. package/runtime/vite.d.ts +30 -0
  6. package/runtime/vite.mjs +150 -0
  7. package/scripts/build.sh +108 -13
  8. package/std/base64.ts +34 -5
  9. package/std/bytes.ts +256 -40
  10. package/std/cli-args.ts +296 -70
  11. package/std/cli-flags.ts +184 -19
  12. package/std/cli.ts +475 -54
  13. package/std/collections.ts +121 -23
  14. package/std/compress/checksum.ts +44 -14
  15. package/std/compress/deflate.ts +224 -111
  16. package/std/compress/gzip.ts +217 -53
  17. package/std/compress/zlib.ts +63 -7
  18. package/std/crypto/aes.ts +80 -9
  19. package/std/crypto/base64url.ts +22 -0
  20. package/std/crypto/bcrypt-batch.ts +88 -21
  21. package/std/crypto/bcrypt.ts +60 -0
  22. package/std/crypto/chacha20poly1305.ts +53 -0
  23. package/std/crypto/ct.ts +32 -13
  24. package/std/crypto/ed25519.ts +47 -0
  25. package/std/crypto/hkdf.ts +198 -13
  26. package/std/crypto/hmac.ts +235 -31
  27. package/std/crypto/jwt.ts +192 -63
  28. package/std/crypto/p256.ts +159 -16
  29. package/std/crypto/p384.ts +28 -3
  30. package/std/crypto/pki-roots.ts +32 -2
  31. package/std/crypto/pki.ts +81 -15
  32. package/std/crypto/rsa.ts +33 -3
  33. package/std/crypto/sha1.ts +3 -0
  34. package/std/crypto/sha256.ts +24 -1
  35. package/std/crypto/sha512.ts +99 -14
  36. package/std/crypto/x25519.ts +152 -14
  37. package/std/crypto/x509-random.ts +10 -0
  38. package/std/crypto/x509.ts +67 -7
  39. package/std/json-equal.ts +19 -0
  40. package/std/json-format.ts +112 -13
  41. package/std/json-number.ts +64 -14
  42. package/std/json-pointer.ts +23 -1
  43. package/std/json-tokenizer.ts +100 -29
  44. package/std/json-typed.ts +713 -66
  45. package/std/json-value.ts +400 -124
  46. package/std/json.ts +138 -10
  47. package/std/map.ts +25 -7
  48. package/std/math.ts +36 -4
  49. package/std/net/buffer-pool.ts +42 -11
  50. package/std/net/dns-config.ts +109 -23
  51. package/std/net/dns-message.ts +62 -7
  52. package/std/net/dns-resolver.ts +247 -53
  53. package/std/net/dns.ts +203 -35
  54. package/std/net/fetch.ts +151 -61
  55. package/std/net/handler.ts +278 -80
  56. package/std/net/hpack.ts +262 -52
  57. package/std/net/http-compress.ts +125 -15
  58. package/std/net/http-fields.ts +85 -9
  59. package/std/net/http1-client-codec.ts +100 -19
  60. package/std/net/http1-codec.ts +235 -27
  61. package/std/net/http1-server.ts +343 -85
  62. package/std/net/http2-frame.ts +272 -35
  63. package/std/net/http2-tls.ts +135 -34
  64. package/std/net/http2.ts +247 -106
  65. package/std/net/http3-frame.ts +154 -17
  66. package/std/net/http3-server.ts +246 -96
  67. package/std/net/http3.ts +307 -115
  68. package/std/net/outbound.ts +37 -3
  69. package/std/net/postgres-carrier.ts +144 -8
  70. package/std/net/postgres.ts +723 -103
  71. package/std/net/prefork.ts +164 -31
  72. package/std/net/qpack.ts +105 -18
  73. package/std/net/quic-conn-ack.ts +59 -12
  74. package/std/net/quic-conn-cid.ts +124 -27
  75. package/std/net/quic-conn-params.ts +70 -10
  76. package/std/net/quic-datagram.ts +43 -3
  77. package/std/net/quic-frame.ts +286 -12
  78. package/std/net/quic-listener.ts +101 -32
  79. package/std/net/quic-packet.ts +302 -21
  80. package/std/net/quic-recovery.ts +228 -44
  81. package/std/net/quic-stream.ts +353 -91
  82. package/std/net/quic.ts +489 -171
  83. package/std/net/router.ts +87 -40
  84. package/std/net/tls/client.ts +166 -51
  85. package/std/net/tls/codec.ts +413 -56
  86. package/std/net/tls/record-client.ts +110 -55
  87. package/std/net/tls/record-server.ts +159 -59
  88. package/std/net/tls/record.ts +109 -12
  89. package/std/net/tls/schedule.ts +235 -26
  90. package/std/net/tls/ticket.ts +159 -40
  91. package/std/net/tls/verify.ts +49 -3
  92. package/std/net/tls-tcp.ts +250 -45
  93. package/std/net/tls.ts +221 -59
  94. package/std/net/upstream.ts +81 -45
  95. package/std/net/url.ts +97 -13
  96. package/std/net/websocket.ts +122 -12
  97. package/std/net/webtransport.ts +220 -89
  98. package/std/pair.ts +10 -2
  99. package/std/random.ts +34 -9
  100. package/std/regex.ts +352 -198
  101. package/std/region.ts +70 -15
  102. package/std/secret.ts +52 -11
  103. package/std/sort.ts +17 -2
  104. package/std/sqlite.ts +256 -35
  105. package/std/sync/ring.ts +205 -35
  106. package/std/sync/shm.ts +194 -16
  107. package/std/term-io.ts +137 -64
  108. package/std/term-pixels.ts +144 -19
  109. package/std/term-probe.ts +66 -25
  110. package/std/term-rate.ts +128 -57
  111. package/std/term.ts +332 -121
  112. package/std/testing.ts +130 -32
  113. package/std/text.ts +73 -7
  114. package/std/threads.ts +229 -41
  115. package/std/yaml-json.ts +94 -82
  116. package/std/yaml-lines.ts +47 -15
  117. package/std/yaml-write.ts +24 -16
  118. package/std/yaml.ts +764 -384
package/std/net/tls.ts CHANGED
@@ -335,6 +335,9 @@ const tlsEcdsaDerInto = (der: u8[], rs: u8[]): void => {
335
335
  * An ECDSA signature `r || s` (32 bytes each, as `nish/crypto/p256` answers
336
336
  * it) as the DER `ECDSA-Sig-Value` a CertificateVerify carries (RFC 8446
337
337
  * §4.2.3), or `null` when `rs` is not 64 bytes.
338
+ *
339
+ * @param rs The signature's `r` then `s`, 32 big-endian bytes each.
340
+ * @returns A fresh array of 8 to 72 bytes holding the DER encoding, or `null`.
338
341
  */
339
342
  export const tlsEcdsaDerSignature = (rs: u8[]): u8[] | null => {
340
343
  if (toI32(rs.length) !== 64) {
@@ -351,6 +354,10 @@ export const tlsEcdsaDerSignature = (rs: u8[]): u8[] | null => {
351
354
  * encoded. `null` for a malformed key. The answer is what `TlsServer.sign`
352
355
  * takes. The key is borrowed, as every `Secret` parameter is: the caller made
353
356
  * it, and wipes it.
357
+ *
358
+ * @param priv The server's P-256 private key, borrowed.
359
+ * @param content The CertificateVerify input, as `TlsServer.signatureInput` answers it.
360
+ * @returns A fresh array holding the DER signature, or `null` for a malformed key.
354
361
  */
355
362
  export const tlsSignEcdsaP256 = (priv: Secret<u8[]>, content: u8[]): u8[] | null => {
356
363
  const rs: u8[] | null = p256SignSha256(priv, content)
@@ -372,12 +379,17 @@ export const tlsSignEcdsaP256 = (priv: Secret<u8[]>, content: u8[]): u8[] | null
372
379
  */
373
380
  export class TlsP256Signer {
374
381
  /** The P-256 signer's scratch. */
375
- scratch: P256SignScratch
382
+ private scratch: P256SignScratch
376
383
  /** `r || s` as `p256SignSha256Into` writes it. */
377
- rs: u8[]
384
+ private rs: u8[]
378
385
  /** The DER signatures, index `length - TLS_P256_DER_MIN`. */
379
- ders: u8[][]
386
+ private ders: u8[][]
380
387
 
388
+ /**
389
+ * Makes the signer's scratch and one signature array per DER length, so a
390
+ * signature keeps nothing: the P-256 step releases what it allocates per
391
+ * call, and the DER is written into one of these arrays.
392
+ */
381
393
  constructor() {
382
394
  this.scratch = new P256SignScratch()
383
395
  this.rs = new Array<u8>(P256_SIGNATURE_SIZE)
@@ -392,6 +404,10 @@ export class TlsP256Signer {
392
404
  * signer's that has its length; `null` for a malformed key. It keeps
393
405
  * nothing: the P-256 signature releases what it allocated, and the DER is
394
406
  * written in place. The key is borrowed.
407
+ *
408
+ * @param priv The server's P-256 private key, borrowed.
409
+ * @param content The CertificateVerify input, as `TlsServer.signatureInput` answers it.
410
+ * @returns One of this signer's own arrays, which a later `sign` of the same length overwrites, or `null`.
395
411
  */
396
412
  sign(priv: Secret<u8[]>, content: u8[]): u8[] | null {
397
413
  if (
@@ -409,7 +425,12 @@ export class TlsP256Signer {
409
425
  }
410
426
  }
411
427
 
412
- /** Whether an x25519 shared secret is all zeros, reading every byte (run inside `expose`). */
428
+ /**
429
+ * Whether an x25519 shared secret is all zeros, reading every byte (run inside `expose`).
430
+ *
431
+ * @param shared The exposed shared secret, `X25519_SIZE` bytes.
432
+ * @returns True when every byte is zero (a low-order peer share, RFC 7748 §6.1), which the handshake refuses.
433
+ */
413
434
  export const tlsIsZeroSecret = (shared: u8[]): boolean => timingSafeEqual(shared, new Array<u8>(X25519_SIZE))
414
435
 
415
436
  /**
@@ -437,13 +458,26 @@ const tlsHandshakeFromEcdhe256 = (ecdhe: u8[], salt: u8[]): u8[] => hmacSha256(s
437
458
  /** The SHA-384 handshake secret: HKDF-Extract of the ECDHE secret under `salt`, as the SHA-256 one is. */
438
459
  const tlsHandshakeFromEcdhe384 = (ecdhe: u8[], salt: u8[]): u8[] => hmacSha384(salt, ecdhe)
439
460
 
440
- /** Wipes the bytes a `Secret` holds, for `exposeWith` to run on one secret of a holder outside its `wipe()`; answers `answer`. */
461
+ /**
462
+ * Wipes the bytes a `Secret` holds, for `exposeWith` to run on one secret of a holder outside its `wipe()`.
463
+ *
464
+ * @param held The exposed bytes, zeroed in place.
465
+ * @param answer The value to hand back, so a caller can wipe and answer in one expression.
466
+ * @returns `answer`, unchanged.
467
+ */
441
468
  export const tlsZeroHeld = (held: u8[], answer: i32): i32 => {
442
469
  wipe(held)
443
470
  return answer
444
471
  }
445
472
 
446
- /** Overwrites the bytes a `Secret` holds with `from`'s, for `exposeWith` to run on the destination; answers 0. */
473
+ /**
474
+ * Overwrites the bytes a `Secret` holds with `from`'s, for `exposeWith` to run on the destination.
475
+ * Only as many bytes as the shorter of the two holds are copied; the rest of `held` is left as it was.
476
+ *
477
+ * @param held The destination's exposed bytes, written in place.
478
+ * @param from The bytes to copy in, read from index 0.
479
+ * @returns 0.
480
+ */
447
481
  export const tlsHeldCopyIn = (held: u8[], from: u8[]): i32 => {
448
482
  for (let k: i32 = 0; k < toI32(held.length) && k < toI32(from.length); k++) {
449
483
  held[k] = from[k]
@@ -455,6 +489,9 @@ export const tlsHeldCopyIn = (held: u8[], from: u8[]): i32 => {
455
489
  * A plain copy of a held secret, for a derivation that runs on its bytes
456
490
  * inside a `using arena()` block: the copy dies with the block, and its
457
491
  * caller `secureZero`s it before the block ends.
492
+ *
493
+ * @param held The exposed bytes to copy.
494
+ * @returns A fresh plain array of the same length, which the caller must wipe.
458
495
  */
459
496
  export const tlsHeldClone = (held: u8[]): u8[] => {
460
497
  const copy: u8[] = new Array<u8>(held.length)
@@ -468,6 +505,10 @@ export const tlsHeldClone = (held: u8[]): u8[] => {
468
505
  * Copies the bytes one `Secret` holds over another's, for `exposeWith` to
469
506
  * run on the source with the destination as its argument: no plain copy is
470
507
  * made on the way. Answers 0.
508
+ *
509
+ * @param from The source's exposed bytes.
510
+ * @param to The destination secret, borrowed; as many bytes as the shorter of the two holds are overwritten.
511
+ * @returns 0.
471
512
  */
472
513
  export const tlsHeldCopyOver = (from: u8[], to: Secret<u8[]>): i32 => exposeWith(to, from, tlsHeldCopyIn)
473
514
 
@@ -517,12 +558,19 @@ class TlsExchangeWords {
517
558
  * The salt the handshake secret is extracted under, `hashLength` bytes of
518
559
  * it: the `TLS_DERIVED_SALT_*` constant on a full handshake, the salt
519
560
  * derived from the PSK early secret on a resumed one.
561
+ *
562
+ * @internal Read by the free functions of this module; `TlsServer.exchangeKeys` writes it.
520
563
  */
521
564
  salt0: u64 = 0
565
+ /** @internal Read by the free functions of this module; `TlsServer.exchangeKeys` writes it. */
522
566
  salt1: u64 = 0
567
+ /** @internal Read by the free functions of this module; `TlsServer.exchangeKeys` writes it. */
523
568
  salt2: u64 = 0
569
+ /** @internal Read by the free functions of this module; `TlsServer.exchangeKeys` writes it. */
524
570
  salt3: u64 = 0
571
+ /** @internal Read by the free functions of this module; `TlsServer.exchangeKeys` writes it. */
525
572
  salt4: u64 = 0
573
+ /** @internal Read by the free functions of this module; `TlsServer.exchangeKeys` writes it. */
526
574
  salt5: u64 = 0
527
575
  /** 32 or 48: which handshake secret to extract. */
528
576
  hashLength: i32 = 0
@@ -643,14 +691,21 @@ const TLS_ECDSA_SIGNATURE_MAX: i32 = 72
643
691
  * that says the secret is derived (`1 << index`).
644
692
  */
645
693
  export const TLS_SECRET_HANDSHAKE: i32 = 0
694
+ /** `client_handshake_traffic_secret` (RFC 8446 §7.1): the client's Handshake-level keys. */
646
695
  export const TLS_SECRET_CLIENT_HANDSHAKE: i32 = 1
696
+ /** `server_handshake_traffic_secret` (RFC 8446 §7.1): the server's Handshake-level keys. */
647
697
  export const TLS_SECRET_SERVER_HANDSHAKE: i32 = 2
698
+ /** `client_application_traffic_secret_0` (RFC 8446 §7.1): the client's first application keys. */
648
699
  export const TLS_SECRET_CLIENT_APPLICATION: i32 = 3
700
+ /** `server_application_traffic_secret_0` (RFC 8446 §7.1): the server's first application keys. */
649
701
  export const TLS_SECRET_SERVER_APPLICATION: i32 = 4
702
+ /** `exporter_master_secret` (RFC 8446 §7.5), for a caller's own exporters. */
650
703
  export const TLS_SECRET_EXPORTER: i32 = 5
704
+ /** The client Finished's expected `verify_data` (RFC 8446 §4.4.4), plain, since the wire carries it. */
651
705
  export const TLS_SECRET_CLIENT_FINISHED: i32 = 6
652
706
  /** The CertificateVerify input sits beside them: 98 bytes and the transcript hash. */
653
707
  export const TLS_SECRET_TO_BE_SIGNED: i32 = 7
708
+ /** `resumption_master_secret` (RFC 8446 §7.1), what a NewSessionTicket's PSK is derived from. */
654
709
  export const TLS_SECRET_RESUMPTION: i32 = 8
655
710
  /** The PSK a ticket opened to, held from the binder's check to the early secret's extract. */
656
711
  export const TLS_SECRET_PSK: i32 = 9
@@ -696,6 +751,11 @@ export class TlsSecretPool {
696
751
  /** The CertificateVerify input, 98 bytes longer than the rest. */
697
752
  toBeSigned: u8[]
698
753
 
754
+ /**
755
+ * Allocates every array of the pool once, all zero, so a connection never allocates one for a secret.
756
+ *
757
+ * @param hashLength The suite's hash length in bytes: 32 for SHA-256, 48 for SHA-384.
758
+ */
699
759
  constructor(hashLength: i32) {
700
760
  this.handshake = secret(new Array<u8>(hashLength))
701
761
  this.clientHandshake = secret(new Array<u8>(hashLength))
@@ -711,7 +771,11 @@ export class TlsSecretPool {
711
771
  this.toBeSigned = new Array<u8>(hashLength + TLS_CERTIFICATE_VERIFY_PREFIX)
712
772
  }
713
773
 
714
- /** Wipes the one secret `index` names (`TLS_SECRET_*`), leaving the rest; any other index wipes nothing. */
774
+ /**
775
+ * Wipes the one secret `index` names (`TLS_SECRET_*`), leaving the rest; any other index wipes nothing.
776
+ *
777
+ * @internal Read by `net/tls/client.ts` and `TlsServer`.
778
+ */
715
779
  zero(index: i32): void {
716
780
  if (index === TLS_SECRET_HANDSHAKE) {
717
781
  exposeWith(this.handshake, TLS_FROM, tlsZeroHeld)
@@ -740,7 +804,11 @@ export class TlsSecretPool {
740
804
  }
741
805
  }
742
806
 
743
- /** Wipes every secret in the pool. */
807
+ /**
808
+ * Wipes every secret in the pool.
809
+ *
810
+ * @internal Read by `net/tls/client.ts` and `TlsServer`.
811
+ */
744
812
  wipe(): void {
745
813
  wipe(this.handshake)
746
814
  wipe(this.clientHandshake)
@@ -880,7 +948,7 @@ const tlsServerTicketCapacity = (state: TlsTicketState): i32 => {
880
948
  */
881
949
  export class TlsServer {
882
950
  config: TlsServerConfig
883
- serverRandom: u8[]
951
+ private serverRandom: u8[]
884
952
  /** The connection's x25519 private key, copied in by `restart` and wiped by the record layer once the ServerHello is written. */
885
953
  readonly ephemeral: Secret<u8[]>
886
954
  /** The client's `host_name`, or empty. */
@@ -888,33 +956,41 @@ export class TlsServer {
888
956
  /** The ALPN protocol chosen, one of the configuration's, or empty. */
889
957
  alpn: string = ""
890
958
  /** The last host name a client of this server sent, kept across `restart` so that the next one naming it reuses the string. */
891
- lastServerName: string = ""
959
+ private lastServerName: string = ""
892
960
  /** The client's `quic_transport_parameters`, opaque; empty unless the carrier is QUIC. */
893
961
  clientTransportParameters: u8[]
894
962
  /** The array `clientTransportParameters` points at once read, kept across `restart` and refilled in the room it has. */
895
- clientParameters: u8[]
896
- transcript: TlsTranscript
963
+ private clientParameters: u8[]
964
+ private transcript: TlsTranscript
897
965
  /** The bytes received at the current level and not yet a whole message: `input[0 .. inputLength)`. */
898
966
  input: u8[]
899
- /** What the server has written at the Initial level and not handed on: `outputInitial[0 .. outputInitialLength)`. */
967
+ /**
968
+ * What the server has written at the Initial level and not handed on: `outputInitial[0 .. outputInitialLength)`.
969
+ *
970
+ * @internal Read by `net/tls/record-server.ts` and `net/quic.ts`.
971
+ */
900
972
  outputInitial: u8[]
901
- /** What the server has written at the Handshake level and not handed on: `outputHandshake[0 .. outputHandshakeLength)`. */
973
+ /**
974
+ * What the server has written at the Handshake level and not handed on: `outputHandshake[0 .. outputHandshakeLength)`.
975
+ *
976
+ * @internal Read by `net/tls/record-server.ts` and `net/quic.ts`.
977
+ */
902
978
  outputHandshake: u8[]
903
979
  /** An empty array: what `clientTransportParameters` holds until a client's are read. */
904
- none: u8[]
980
+ private none: u8[]
905
981
  /** The secrets under each hash (`TlsSecretPool`); `secrets()` answers the negotiated hash's. */
906
982
  secrets256: TlsSecretPool
907
983
  secrets384: TlsSecretPool
908
984
  /** The ClientHello last read, as windows into `input`. */
909
- hello: TlsClientHelloView
985
+ private hello: TlsClientHelloView
910
986
  /** Where every HKDF and HMAC of the schedule runs. */
911
- kdf: HkdfScratch
987
+ private kdf: HkdfScratch
912
988
  /** The exchange's words (`tlsExchange`). */
913
989
  exchange: TlsExchangeWords
914
990
  /** The server's x25519 public key, unpacked from the exchange's words for the ServerHello. */
915
- serverPublic: u8[]
991
+ private serverPublic: u8[]
916
992
  /** A transcript hash on its way into the schedule: HashLen bytes of it. */
917
- hashes: u8[]
993
+ private hashes: u8[]
918
994
  /**
919
995
  * The salt the handshake secret is extracted under, HashLen bytes of it:
920
996
  * the `TLS_DERIVED_SALT_*` constant on a full handshake, derived from the
@@ -923,19 +999,23 @@ export class TlsServer {
923
999
  */
924
1000
  salt: u8[]
925
1001
  /** The transcript hash through the ClientHello's binders prefix, which a binder covers (§4.2.11.2). */
926
- binderHash: u8[]
1002
+ private binderHash: u8[]
927
1003
  /** What the ticket `resume` is reading opened to; its PSK is zeroed once read. */
928
1004
  opened: TlsTicketState
929
1005
  /** What `issue` seals; its PSK is zeroed once sealed. */
930
1006
  issuing: TlsTicketState
931
1007
  /** The sealed ticket, sized once for the largest. */
932
- ticketScratch: u8[]
933
- /** What the server has written at the Application level and not handed on: one NewSessionTicket. */
1008
+ private ticketScratch: u8[]
1009
+ /**
1010
+ * What the server has written at the Application level and not handed on: one NewSessionTicket.
1011
+ *
1012
+ * @internal Read by `net/tls/record-server.ts`.
1013
+ */
934
1014
  outputApplication: u8[]
935
1015
  /** The ticket nonce: one ticket a connection, so one byte, the same each time, keeps each PSK distinct (§4.6.1). */
936
- ticketNonce: u8[]
1016
+ private ticketNonce: u8[]
937
1017
  /** The ticket's `ticket_age_add`, drawn fresh for each ticket (§4.6.1). */
938
- ageAddBytes: u8[]
1018
+ private ageAddBytes: u8[]
939
1019
  /**
940
1020
  * Which of the negotiated pool's secrets the handshake has derived: bit
941
1021
  * `1 << TLS_SECRET_*` for each. A secret wiped by `wipeSecret` keeps its
@@ -947,24 +1027,35 @@ export class TlsServer {
947
1027
  alert: i32 = 0
948
1028
  /** The negotiated cipher suite, or 0 before the first ClientHello is read. */
949
1029
  suite: i32 = 0
1030
+ /** @internal Read by `net/tls/record-server.ts`. */
950
1031
  hashLength: i32 = 0
1032
+ /** @internal Read by `net/tls/record-server.ts`. */
951
1033
  inputLength: i32 = 0
1034
+ /** @internal Read by `net/tls/record-server.ts` and `net/quic.ts`. */
952
1035
  outputInitialLength: i32 = 0
1036
+ /** @internal Read by `net/tls/record-server.ts` and `net/quic.ts`. */
953
1037
  outputHandshakeLength: i32 = 0
1038
+ /** @internal Read by `net/tls/record-server.ts`. */
954
1039
  outputApplicationLength: i32 = 0
955
1040
  /** Whether a HelloRetryRequest was sent, so a second miss is fatal. */
956
1041
  retried: boolean = false
957
1042
  /** Whether `config` passed `tlsConfigFits`, decided once by the constructor. */
958
- configFits: boolean = false
1043
+ private configFits: boolean = false
959
1044
  /** Whether the carrier turned resumption on with `enableTickets`; kept across `restart`. */
960
1045
  tickets: boolean = false
961
1046
  /**
962
1047
  * Whether this connection may be issued a ticket: tickets are on, the
963
1048
  * client listed `psk_dhe_ke`, the only mode this server resumes in, and its
964
1049
  * server name, if any, fits a ticket.
1050
+ *
1051
+ * @internal Read by `net/tls/record-server.ts`.
965
1052
  */
966
1053
  ticketWanted: boolean = false
967
- /** Whether `issue` has run for this connection. */
1054
+ /**
1055
+ * Whether `issue` has run for this connection.
1056
+ *
1057
+ * @internal Read by `net/tls/record-server.ts`.
1058
+ */
968
1059
  issued: boolean = false
969
1060
  /** Whether this connection resumed a ticket (row 1 of the record's table). */
970
1061
  resumed: boolean = false
@@ -974,6 +1065,12 @@ export class TlsServer {
974
1065
  * random and the 32-byte x25519 private key drawn for it. A random or key of
975
1066
  * another length, or a configuration `tlsConfigFits` refuses, leaves the
976
1067
  * server failed with `internal_error` before it reads anything.
1068
+ *
1069
+ * @param config What the server offers and answers with; held, not copied, and checked by `tlsConfigFits`.
1070
+ * @param serverRandom The 32 random bytes of the ServerHello's `random`; the array itself is kept, so the
1071
+ * caller hands over a fresh one.
1072
+ * @param ephemeralPrivate The 32-byte x25519 private key; copied into the server's `Secret` and then zeroed
1073
+ * in the caller's array, as `restart` does.
977
1074
  */
978
1075
  constructor(config: TlsServerConfig, serverRandom: u8[], ephemeralPrivate: u8[]) {
979
1076
  this.config = config
@@ -1014,6 +1111,9 @@ export class TlsServer {
1014
1111
  * only copy left is the one the server wipes. A random or key of another
1015
1112
  * length, or a configuration `tlsConfigFits` refused, leaves the server
1016
1113
  * failed with `internal_error`.
1114
+ *
1115
+ * @param serverRandom The next connection's 32 random bytes; the array itself is kept.
1116
+ * @param ephemeralPrivate The next connection's 32-byte x25519 private key; zeroed once copied in.
1017
1117
  */
1018
1118
  restart(serverRandom: u8[], ephemeralPrivate: u8[]): void {
1019
1119
  const keyLength: i32 = toI32(ephemeralPrivate.length)
@@ -1051,7 +1151,7 @@ export class TlsServer {
1051
1151
  * master secret `sign` derived ahead and what a ticket being read left: its
1052
1152
  * PSK, early secret and binder key, and the salt.
1053
1153
  */
1054
- fail(alert: i32): i32 {
1154
+ private fail(alert: i32): i32 {
1055
1155
  this.wipeResumption()
1056
1156
  const pool: TlsSecretPool = this.secrets()
1057
1157
  pool.zero(TLS_SECRET_PSK)
@@ -1073,12 +1173,23 @@ export class TlsServer {
1073
1173
  this.secrets().zero(TLS_SECRET_RESUMPTION)
1074
1174
  }
1075
1175
 
1076
- /** The pool of the negotiated hash: SHA-384's for a SHA-384 suite, SHA-256's otherwise. */
1176
+ /**
1177
+ * The pool of the negotiated hash: SHA-384's for a SHA-384 suite, SHA-256's otherwise.
1178
+ *
1179
+ * @returns One of the server's two pools, which the server keeps and reuses for the next connection.
1180
+ */
1077
1181
  secrets(): TlsSecretPool {
1078
1182
  return this.hashLength === SHA384_SIZE ? this.secrets384 : this.secrets256
1079
1183
  }
1080
1184
 
1081
- /** Whether the handshake has derived secret `index` (`TLS_SECRET_*`) for this connection. */
1185
+ /**
1186
+ * Whether the handshake has derived secret `index` (`TLS_SECRET_*`) for this connection.
1187
+ *
1188
+ * @param index A `TLS_SECRET_*` index; any index outside 0 to 30 is never known.
1189
+ * @returns True once the secret is derived; it stays true after `wipeSecret`, until `restart`,
1190
+ * except that `sign` clears `TLS_SECRET_TO_BE_SIGNED` and the client's Finished clears
1191
+ * `TLS_SECRET_HANDSHAKE`.
1192
+ */
1082
1193
  known(index: i32): boolean {
1083
1194
  return index >= 0 && index < 31 && (this.held & (1 << index)) !== 0
1084
1195
  }
@@ -1088,6 +1199,9 @@ export class TlsServer {
1088
1199
  * traffic secret, `clientHandshake` or `clientApplication` of `secrets()` —
1089
1200
  * is known yet. The Initial level has none: it is cleartext in TLS, and
1090
1201
  * QUIC derives its own from the connection id.
1202
+ *
1203
+ * @param level A `TLS_LEVEL_*` level.
1204
+ * @returns True when the client's secret for `level` is derived; always false for Initial.
1091
1205
  */
1092
1206
  readKnown(level: i32): boolean {
1093
1207
  if (level === TLS_LEVEL_HANDSHAKE) {
@@ -1096,7 +1210,13 @@ export class TlsServer {
1096
1210
  return level === TLS_LEVEL_APPLICATION && this.known(TLS_SECRET_CLIENT_APPLICATION)
1097
1211
  }
1098
1212
 
1099
- /** Whether the secret the server *writes* `level` under — `serverHandshake` or `serverApplication` — is known yet. */
1213
+ /**
1214
+ * Whether the secret the server *writes* `level` under — `serverHandshake` or `serverApplication` — is
1215
+ * known yet.
1216
+ *
1217
+ * @param level A `TLS_LEVEL_*` level.
1218
+ * @returns True when the server's secret for `level` is derived; always false for Initial.
1219
+ */
1100
1220
  writeKnown(level: i32): boolean {
1101
1221
  if (level === TLS_LEVEL_HANDSHAKE) {
1102
1222
  return this.known(TLS_SECRET_SERVER_HANDSHAKE)
@@ -1104,12 +1224,18 @@ export class TlsServer {
1104
1224
  return level === TLS_LEVEL_APPLICATION && this.known(TLS_SECRET_SERVER_APPLICATION)
1105
1225
  }
1106
1226
 
1107
- /** Zeroes secret `index` of `secrets()` once a carrier has taken what it needs from it; it stays known. */
1227
+ /**
1228
+ * Zeroes secret `index` of `secrets()` once a carrier has taken what it needs from it; it stays known.
1229
+ *
1230
+ * @param index A `TLS_SECRET_*` index; any other index wipes nothing.
1231
+ */
1108
1232
  wipeSecret(index: i32): void {
1109
1233
  this.secrets().zero(index)
1110
1234
  }
1111
1235
 
1112
- /** Zeroes the ephemeral key, which the record layer does once the ServerHello is written: not while a hello that offers a ticket waits for `resume`, whose exchange still needs it. */
1236
+ /**
1237
+ * Zeroes the ephemeral key, which the record layer does once the ServerHello is written: not while a hello that offers a ticket waits for `resume`, whose exchange still needs it.
1238
+ */
1113
1239
  wipeEphemeral(): void {
1114
1240
  exposeWith(this.ephemeral, TLS_FROM, tlsZeroHeld)
1115
1241
  }
@@ -1122,7 +1248,7 @@ export class TlsServer {
1122
1248
  }
1123
1249
 
1124
1250
  /** The level the client's next bytes must arrive at, or -1 when the state expects none. */
1125
- expectedLevel(): i32 {
1251
+ private expectedLevel(): i32 {
1126
1252
  switch (this.state) {
1127
1253
  case TLS_STATE_WAIT_CLIENT_HELLO:
1128
1254
  return TLS_LEVEL_INITIAL
@@ -1139,7 +1265,7 @@ export class TlsServer {
1139
1265
  * clients cut their messages, and never past the largest message `receive`
1140
1266
  * takes.
1141
1267
  */
1142
- reserveInput(need: i32): void {
1268
+ private reserveInput(need: i32): void {
1143
1269
  const capacity: i32 = toI32(this.input.length)
1144
1270
  if (need <= capacity) {
1145
1271
  return
@@ -1162,7 +1288,7 @@ export class TlsServer {
1162
1288
  * writes with an ECDSA signature, so only a longer signature grows the
1163
1289
  * Handshake level's, once per slot.
1164
1290
  */
1165
- reserveOutput(level: i32, need: i32): void {
1291
+ private reserveOutput(level: i32, need: i32): void {
1166
1292
  const initial: boolean = level === TLS_LEVEL_INITIAL
1167
1293
  const buffer: u8[] = initial ? this.outputInitial : this.outputHandshake
1168
1294
  const held: i32 = initial ? this.outputInitialLength : this.outputHandshakeLength
@@ -1194,6 +1320,13 @@ export class TlsServer {
1194
1320
  * fault and not the peer's. Once the handshake is done, any further bytes
1195
1321
  * are `unexpected_message` too: the post-handshake messages a client may
1196
1322
  * send (KeyUpdate) belong to the record layer, which handles them itself.
1323
+ *
1324
+ * @param level The `TLS_LEVEL_*` level the bytes arrived at.
1325
+ * @param data The array holding the bytes; only read, and copied into the server's own buffer.
1326
+ * @param off Where in `data` the bytes start.
1327
+ * @param len How many bytes, from `off`, to take; 0 takes nothing and answers 0, once the window is
1328
+ * checked and unless the server has already failed.
1329
+ * @returns 0, or the `TLS_ALERT_*` the server failed with (the same one again on every later call).
1197
1330
  */
1198
1331
  receive(level: i32, data: u8[], off: i32, len: i32): i32 {
1199
1332
  if (this.state === TLS_STATE_FAILED) {
@@ -1253,7 +1386,7 @@ export class TlsServer {
1253
1386
  * admits bytes only in the two states that expect them, so the state is
1254
1387
  * one of those two here.
1255
1388
  */
1256
- handleMessage(length: i32): i32 {
1389
+ private handleMessage(length: i32): i32 {
1257
1390
  const type: i32 = toI32(this.input[0])
1258
1391
  if (this.state === TLS_STATE_WAIT_CLIENT_HELLO) {
1259
1392
  return type === TLS_HANDSHAKE_CLIENT_HELLO
@@ -1268,7 +1401,7 @@ export class TlsServer {
1268
1401
  * (§4.1.1: the server picks; following the client's order is the choice
1269
1402
  * RFC 8448's server makes).
1270
1403
  */
1271
- chooseSuite(hello: TlsClientHelloView): i32 {
1404
+ private chooseSuite(hello: TlsClientHelloView): i32 {
1272
1405
  const data: u8[] = hello.data
1273
1406
  const end: i32 = hello.suitesAt + hello.suitesLength
1274
1407
  for (
@@ -1289,7 +1422,7 @@ export class TlsServer {
1289
1422
  * Answers 0 with `alpn` set, or empty when nothing is negotiated, or
1290
1423
  * `no_application_protocol`.
1291
1424
  */
1292
- chooseAlpn(hello: TlsClientHelloView): i32 {
1425
+ private chooseAlpn(hello: TlsClientHelloView): i32 {
1293
1426
  this.alpn = ""
1294
1427
  if (hello.hasAlpn && toI32(this.config.alpn.length) > 0) {
1295
1428
  const data: u8[] = hello.data
@@ -1315,7 +1448,7 @@ export class TlsServer {
1315
1448
  * already spells those bytes, so a slot whose clients name one host makes
1316
1449
  * the string once, and made again only when the name changes.
1317
1450
  */
1318
- takeServerName(hello: TlsClientHelloView): void {
1451
+ private takeServerName(hello: TlsClientHelloView): void {
1319
1452
  if (!hello.hasServerName) {
1320
1453
  this.serverName = ""
1321
1454
  return
@@ -1334,7 +1467,7 @@ export class TlsServer {
1334
1467
  * the suite, the extensions §9.2 requires, the group, the signature scheme,
1335
1468
  * the share itself, and the application protocol.
1336
1469
  */
1337
- handleClientHello(length: i32): i32 {
1470
+ private handleClientHello(length: i32): i32 {
1338
1471
  const hello: TlsClientHelloView = this.hello
1339
1472
  const data: u8[] = this.input
1340
1473
  tlsReadClientHello(hello, data, 4, length)
@@ -1495,7 +1628,7 @@ export class TlsServer {
1495
1628
  * does not resume, the checks a certificate needs and the full flight.
1496
1629
  * Answers 0 or the alert.
1497
1630
  */
1498
- answerHello(index: i32): i32 {
1631
+ private answerHello(index: i32): i32 {
1499
1632
  const hello: TlsClientHelloView = this.hello
1500
1633
  if (!this.resumed) {
1501
1634
  if (!hello.hasSignatureAlgorithms) {
@@ -1538,7 +1671,7 @@ export class TlsServer {
1538
1671
  * the negotiated one, its PSK is that long, and it names the server name
1539
1672
  * this hello names, or none when the hello names none (rows 4 and 5).
1540
1673
  */
1541
- ticketFits(): boolean {
1674
+ private ticketFits(): boolean {
1542
1675
  const hello: TlsClientHelloView = this.hello
1543
1676
  const opened: TlsTicketState = this.opened
1544
1677
  const h: i32 = this.hashLength
@@ -1562,7 +1695,7 @@ export class TlsServer {
1562
1695
  * counted with `take`, so that a full register fails closed into a full
1563
1696
  * handshake (row 7).
1564
1697
  */
1565
- selectTicket(
1698
+ private selectTicket(
1566
1699
  current: Secret<u8[]>,
1567
1700
  currentInfo: TlsTicketKeyInfo,
1568
1701
  previous: Secret<u8[]>,
@@ -1617,7 +1750,7 @@ export class TlsServer {
1617
1750
  * hello's binder for it verifies (§4.2.11.2). The PSK and binder key are
1618
1751
  * zeroed before it returns; the early secret stays for `saltFromEarly`.
1619
1752
  */
1620
- bindTicket(): boolean {
1753
+ private bindTicket(): boolean {
1621
1754
  const hello: TlsClientHelloView = this.hello
1622
1755
  const pool: TlsSecretPool = this.secrets()
1623
1756
  const h: i32 = this.hashLength
@@ -1650,7 +1783,7 @@ export class TlsServer {
1650
1783
  }
1651
1784
 
1652
1785
  /** The salt a resumed handshake secret is extracted under, `Derive-Secret(early, "derived", "")`, into `salt`. */
1653
- saltFromEarly(): void {
1786
+ private saltFromEarly(): void {
1654
1787
  const pool: TlsSecretPool = this.secrets()
1655
1788
  using _scope = arena()
1656
1789
  const early: u8[] = expose(pool.early, tlsHeldClone)
@@ -1666,6 +1799,16 @@ export class TlsServer {
1666
1799
  * table of "Resumption" in `docs/security/tls.md` says. A selected ticket
1667
1800
  * whose binder fails is `decrypt_error`, with nothing recorded (row 9).
1668
1801
  * Answers 0, or the alert the server fails with.
1802
+ *
1803
+ * @param current The newest ticket key, lent: read only inside `exposeWith`, and the carrier's to wipe.
1804
+ * @param currentInfo The current key's record.
1805
+ * @param previous The key before it, lent as `current` is.
1806
+ * @param previousInfo The previous key's record.
1807
+ * @param strikes The register a resumed ticket's id is recorded in, so that it resumes only once.
1808
+ * @param now The time to judge the tickets at, in `monotonicNanos()`.
1809
+ * @returns 0 when the hello was answered, resumed or not, or the `TLS_ALERT_*` the server failed with:
1810
+ * the recorded alert in `TLS_STATE_FAILED`, `internal_error` in any other state but
1811
+ * `TLS_STATE_WAIT_TICKET`.
1669
1812
  */
1670
1813
  resume(
1671
1814
  current: Secret<u8[]>,
@@ -1707,7 +1850,7 @@ export class TlsServer {
1707
1850
  * handshake traffic secrets, EncryptedExtensions and the server's
1708
1851
  * Finished, after which the server waits for the client's.
1709
1852
  */
1710
- writeResumedFlight(index: i32): void {
1853
+ private writeResumedFlight(index: i32): void {
1711
1854
  const hello: TlsClientHelloView = this.hello
1712
1855
  const none: u8[] = []
1713
1856
  this.reserveOutput(
@@ -1741,7 +1884,7 @@ export class TlsServer {
1741
1884
  }
1742
1885
 
1743
1886
  /** The resumed ServerHello, the handshake traffic secrets and EncryptedExtensions, in the room `writeResumedFlight` reserved. */
1744
- writeResumedHello(pool: TlsSecretPool, index: i32): void {
1887
+ private writeResumedHello(pool: TlsSecretPool, index: i32): void {
1745
1888
  const hello: TlsClientHelloView = this.hello
1746
1889
  using _scope = arena()
1747
1890
  const helloAt: i32 = this.outputInitialLength
@@ -1786,7 +1929,7 @@ export class TlsServer {
1786
1929
  * `Secret` field a word at a time; the record layer wipes it once the
1787
1930
  * ServerHello is written (TLS-1).
1788
1931
  */
1789
- exchangeKeys(): i32 {
1932
+ private exchangeKeys(): i32 {
1790
1933
  const w: TlsExchangeWords = this.exchange
1791
1934
  const share: u8[] = this.input
1792
1935
  const at: i32 = this.hello.x25519ShareAt
@@ -1825,7 +1968,7 @@ export class TlsServer {
1825
1968
  * EncryptedExtensions and Certificate at the Handshake level, then the
1826
1969
  * CertificateVerify input: all in place, inside one arena block.
1827
1970
  */
1828
- writeServerFlight(): void {
1971
+ private writeServerFlight(): void {
1829
1972
  const hello: TlsClientHelloView = this.hello
1830
1973
  const h: i32 = this.hashLength
1831
1974
  // Room for the messages first, outside the block, measured by writing
@@ -1908,7 +2051,7 @@ export class TlsServer {
1908
2051
  * held secret `dst` (RFC 8446 §7.1): derived into a plain array that dies
1909
2052
  * with the caller's arena block, copied in, and zeroed.
1910
2053
  */
1911
- deriveInto(prk: u8[], label: string, dst: Secret<u8[]>): void {
2054
+ private deriveInto(prk: u8[], label: string, dst: Secret<u8[]>): void {
1912
2055
  const out: u8[] = new Array<u8>(this.hashLength)
1913
2056
  tlsDeriveSecretInto(this.kdf, this.hashLength, prk, label, this.hashes, TLS_FROM, out)
1914
2057
  exposeWith(dst, out, tlsHeldCopyIn)
@@ -1918,6 +2061,9 @@ export class TlsServer {
1918
2061
  /**
1919
2062
  * What CertificateVerify signs (RFC 8446 §4.4.3), while the state is
1920
2063
  * `TLS_STATE_WAIT_SIGNATURE`; `null` at any other time.
2064
+ *
2065
+ * @returns The pool's own `toBeSigned` array, not a copy: 98 bytes and the transcript hash, which the
2066
+ * caller signs and does not change. `null` outside `TLS_STATE_WAIT_SIGNATURE`.
1921
2067
  */
1922
2068
  signatureInput(): u8[] | null {
1923
2069
  if (this.state !== TLS_STATE_WAIT_SIGNATURE) {
@@ -1933,6 +2079,9 @@ export class TlsServer {
1933
2079
  * when called in another state or with an empty or over-long signature.
1934
2080
  * The signature is not checked here: a wrong one is the caller's bug, and
1935
2081
  * the client's verification is what catches it.
2082
+ *
2083
+ * @param signature The signature bytes, 1 to 65,535 of them, such as `tlsSignEcdsaP256` answers.
2084
+ * @returns 0, or the `TLS_ALERT_*` the server failed with.
1936
2085
  */
1937
2086
  sign(signature: u8[]): i32 {
1938
2087
  if (this.state === TLS_STATE_FAILED) {
@@ -1954,7 +2103,7 @@ export class TlsServer {
1954
2103
  }
1955
2104
 
1956
2105
  /** CertificateVerify, carrying `signature`, at the Handshake level, in the room `sign` reserved. */
1957
- writeCertificateVerify(signature: u8[]): void {
2106
+ private writeCertificateVerify(signature: u8[]): void {
1958
2107
  using _scope = arena()
1959
2108
  const verifyAt: i32 = this.outputHandshakeLength
1960
2109
  const verifyEnd: i32 = tlsWriteCertificateVerify(
@@ -1971,7 +2120,7 @@ export class TlsServer {
1971
2120
  * it: its `verify_data`, under the server's handshake traffic secret, goes
1972
2121
  * straight into its place in the flight.
1973
2122
  */
1974
- writeServerFinished(pool: TlsSecretPool): void {
2123
+ private writeServerFinished(pool: TlsSecretPool): void {
1975
2124
  const h: i32 = this.hashLength
1976
2125
  using _scope = arena()
1977
2126
  const at: i32 = this.outputHandshakeLength
@@ -1997,7 +2146,7 @@ export class TlsServer {
1997
2146
  * Finished the server expects, and the resumption master secret, after
1998
2147
  * which the server waits for that Finished.
1999
2148
  */
2000
- masterSecretStep(pool: TlsSecretPool): void {
2149
+ private masterSecretStep(pool: TlsSecretPool): void {
2001
2150
  const h: i32 = this.hashLength
2002
2151
  using _scope = arena()
2003
2152
  this.transcript.hashInto(this.hashes, TLS_FROM)
@@ -2042,6 +2191,11 @@ export class TlsServer {
2042
2191
  * `wipeResumption`. Before the handshake is done, or on a second call, it
2043
2192
  * answers false and touches nothing: a secret wiped then would leave no
2044
2193
  * ticket to issue, and one wiped already has nothing left to wipe.
2194
+ *
2195
+ * @param key The current ticket key, lent: read only inside `exposeWith`, and still the carrier's to wipe.
2196
+ * @param info The key's record, which counts the ticket when one is sealed.
2197
+ * @param now The issue time, in `monotonicNanos()`.
2198
+ * @returns True when a NewSessionTicket was written for `takeOutput(TLS_LEVEL_APPLICATION)`.
2045
2199
  */
2046
2200
  issue(key: Secret<u8[]>, info: TlsTicketKeyInfo, now: i64): boolean {
2047
2201
  if (this.state !== TLS_STATE_CONNECTED || this.issued) {
@@ -2054,7 +2208,7 @@ export class TlsServer {
2054
2208
  }
2055
2209
 
2056
2210
  /** The resumption PSK for nonce `ticketNonce`, into `issuing.psk` (§4.6.1). */
2057
- resumptionPsk(): void {
2211
+ private resumptionPsk(): void {
2058
2212
  const pool: TlsSecretPool = this.secrets()
2059
2213
  using _scope = arena()
2060
2214
  const resumption: u8[] = expose(pool.resumption, tlsHeldClone)
@@ -2071,7 +2225,7 @@ export class TlsServer {
2071
2225
  }
2072
2226
 
2073
2227
  /** `issue`'s ticket: sealed into `ticketScratch`, its PSK zeroed, and the NewSessionTicket written. */
2074
- writeTicket(key: Secret<u8[]>, info: TlsTicketKeyInfo, now: i64): boolean {
2228
+ private writeTicket(key: Secret<u8[]>, info: TlsTicketKeyInfo, now: i64): boolean {
2075
2229
  const issuing: TlsTicketState = this.issuing
2076
2230
  issuing.suite = this.suite
2077
2231
  issuing.lifetime = TLS_TICKET_LIFETIME_SECONDS
@@ -2114,7 +2268,7 @@ export class TlsServer {
2114
2268
  * secret `sign` derived is the connection's, and known. The transcript already holds this Finished: `sign` absorbed the
2115
2269
  * one it expected, and these bytes are equal to it.
2116
2270
  */
2117
- handleFinished(length: i32): i32 {
2271
+ private handleFinished(length: i32): i32 {
2118
2272
  if (length !== this.hashLength) {
2119
2273
  return TLS_ALERT_DECODE_ERROR
2120
2274
  }
@@ -2133,7 +2287,7 @@ export class TlsServer {
2133
2287
  * A message the server wrote at `level`, `output[at .. end)` of that
2134
2288
  * level's buffer, goes into the transcript and stays on the output.
2135
2289
  */
2136
- sent(level: i32, at: i32, end: i32): void {
2290
+ private sent(level: i32, at: i32, end: i32): void {
2137
2291
  if (level === TLS_LEVEL_INITIAL) {
2138
2292
  this.transcript.update(this.outputInitial, at, end - at)
2139
2293
  this.outputInitialLength = end
@@ -2148,7 +2302,11 @@ export class TlsServer {
2148
2302
  * array, and forgets them. Bytes are only ever written at a level whose
2149
2303
  * secrets are already known, so a carrier that installs keys as they appear
2150
2304
  * can always protect what this answers. A carrier that reads the output
2151
- * buffers in place calls `clearOutput` instead, and allocates nothing.
2305
+ * buffers in place (the record server and QUIC, inside the standard
2306
+ * library) forgets them with `clearOutput` instead, and allocates nothing.
2307
+ *
2308
+ * @param level The `TLS_LEVEL_*` level to take the bytes of.
2309
+ * @returns The pending bytes, owned by the caller; empty when there are none or `level` is not a level.
2152
2310
  */
2153
2311
  takeOutput(level: i32): u8[] {
2154
2312
  const none: u8[] = []
@@ -2182,7 +2340,11 @@ export class TlsServer {
2182
2340
  }
2183
2341
  }
2184
2342
 
2185
- /** Forgets the handshake bytes written at `level`, which a carrier has read out of the buffer itself. */
2343
+ /**
2344
+ * Forgets the handshake bytes written at `level`, which a carrier has read out of the buffer itself.
2345
+ *
2346
+ * @internal Read by `net/tls/record-server.ts` and `net/quic.ts`.
2347
+ */
2186
2348
  clearOutput(level: i32): void {
2187
2349
  if (level === TLS_LEVEL_INITIAL) {
2188
2350
  this.outputInitialLength = 0