@amritk/nish-aarch64-linux 0.44.0 → 0.46.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 +3 -1
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +18 -16
  4. package/package.json +1 -1
  5. package/runtime/core/numbers.mjs +3 -1
  6. package/runtime/core/strings.mjs +90 -38
  7. package/runtime/core.d.ts +8 -0
  8. package/runtime/core.mjs +16 -0
  9. package/runtime/nish.d.ts +88 -5
  10. package/runtime/nish.h +10 -0
  11. package/runtime/nish.mjs +5 -0
  12. package/runtime/runtime-host.c +15 -0
  13. package/runtime/runtime-net.c +223 -4
  14. package/runtime/runtime-os.c +15 -1
  15. package/runtime/runtime-uring.c +291 -31
  16. package/runtime/sqlite/nish-sqlite.c +301 -128
  17. package/std/README.md +15 -15
  18. package/std/array.ts +10 -2
  19. package/std/bytes.ts +239 -26
  20. package/std/cli-args.ts +1072 -606
  21. package/std/cli-flags.ts +180 -98
  22. package/std/cli.ts +21 -13
  23. package/std/collections.ts +245 -127
  24. package/std/compress/checksum.ts +32 -37
  25. package/std/compress/deflate.ts +1102 -542
  26. package/std/compress/gzip.ts +290 -145
  27. package/std/compress/zlib.ts +57 -21
  28. package/std/crypto/aes.ts +153 -75
  29. package/std/crypto/base64url.ts +84 -61
  30. package/std/crypto/bcrypt-batch.ts +164 -90
  31. package/std/crypto/bcrypt.ts +185 -107
  32. package/std/crypto/chacha20poly1305.ts +84 -68
  33. package/std/crypto/ct.ts +9 -7
  34. package/std/crypto/ed25519.ts +64 -27
  35. package/std/crypto/hkdf.ts +105 -63
  36. package/std/crypto/hmac.ts +95 -89
  37. package/std/crypto/jwt.ts +248 -126
  38. package/std/crypto/p256.ts +758 -444
  39. package/std/crypto/p384.ts +20 -13
  40. package/std/crypto/pki-roots.ts +95 -38
  41. package/std/crypto/pki.ts +164 -60
  42. package/std/crypto/rsa.ts +266 -223
  43. package/std/crypto/scram.ts +3 -4
  44. package/std/crypto/sha1.ts +107 -65
  45. package/std/crypto/sha256.ts +502 -422
  46. package/std/crypto/sha512.ts +204 -135
  47. package/std/crypto/x509-random.ts +9 -3
  48. package/std/crypto/x509.ts +331 -171
  49. package/std/json-equal.ts +35 -19
  50. package/std/json-format.ts +215 -108
  51. package/std/json-number.ts +126 -72
  52. package/std/json-pointer.ts +42 -13
  53. package/std/json-tokenizer.ts +498 -307
  54. package/std/json-typed.ts +115 -36
  55. package/std/json-value.ts +341 -152
  56. package/std/json.ts +300 -158
  57. package/std/net/buffer-pool.ts +17 -7
  58. package/std/net/dns-config.ts +427 -236
  59. package/std/net/dns-message.ts +114 -47
  60. package/std/net/dns-resolver.ts +736 -237
  61. package/std/net/dns.ts +205 -52
  62. package/std/net/fetch.ts +320 -184
  63. package/std/net/grpc.ts +948 -0
  64. package/std/net/handler.ts +1315 -222
  65. package/std/net/hpack.ts +395 -180
  66. package/std/net/http-compress.ts +502 -65
  67. package/std/net/http-fields.ts +85 -49
  68. package/std/net/http-server.ts +1764 -602
  69. package/std/net/http1-client-codec.ts +372 -161
  70. package/std/net/http1-codec.ts +665 -331
  71. package/std/net/http1-server.ts +660 -278
  72. package/std/net/http2-cleartext.ts +165 -95
  73. package/std/net/http2-frame.ts +232 -89
  74. package/std/net/http2-tls.ts +42 -12
  75. package/std/net/http2.ts +327 -101
  76. package/std/net/http3-frame.ts +68 -33
  77. package/std/net/http3-server.ts +647 -192
  78. package/std/net/http3.ts +667 -189
  79. package/std/net/oidc.ts +63 -24
  80. package/std/net/outbound.ts +207 -142
  81. package/std/net/postgres-async.ts +1165 -443
  82. package/std/net/postgres-carrier.ts +575 -372
  83. package/std/net/postgres.ts +1459 -559
  84. package/std/net/prefork.ts +254 -98
  85. package/std/net/protobuf.ts +1017 -0
  86. package/std/net/qpack.ts +143 -92
  87. package/std/net/quic-conn-ack.ts +50 -18
  88. package/std/net/quic-conn-cid.ts +66 -26
  89. package/std/net/quic-conn-params.ts +13 -7
  90. package/std/net/quic-datagram.ts +90 -27
  91. package/std/net/quic-frame.ts +225 -124
  92. package/std/net/quic-listener.ts +197 -89
  93. package/std/net/quic-packet.ts +289 -163
  94. package/std/net/quic-recovery.ts +279 -128
  95. package/std/net/quic-stream.ts +466 -167
  96. package/std/net/quic.ts +568 -257
  97. package/std/net/router.ts +450 -99
  98. package/std/net/serve.ts +651 -232
  99. package/std/net/static.ts +1458 -0
  100. package/std/net/tls/client.ts +140 -45
  101. package/std/net/tls/codec.ts +510 -260
  102. package/std/net/tls/record-client.ts +268 -76
  103. package/std/net/tls/record-server.ts +236 -79
  104. package/std/net/tls/record.ts +173 -47
  105. package/std/net/tls/schedule.ts +58 -39
  106. package/std/net/tls/ticket.ts +295 -103
  107. package/std/net/tls/verify.ts +1 -1
  108. package/std/net/tls-tcp.ts +218 -75
  109. package/std/net/tls.ts +260 -152
  110. package/std/net/upstream.ts +283 -86
  111. package/std/net/url.ts +277 -102
  112. package/std/net/websocket.ts +370 -186
  113. package/std/net/webtransport.ts +755 -436
  114. package/std/regex.ts +1659 -829
  115. package/std/sqlite.ts +171 -0
  116. package/std/sync/ring.ts +320 -156
  117. package/std/sync/shm.ts +53 -6
  118. package/std/text.ts +205 -124
  119. package/std/threads.ts +22 -2
@@ -130,6 +130,8 @@ export const H3_SETTINGS_WEBTRANSPORT_MAX_SESSIONS: i64 = 0xc671706a
130
130
 
131
131
  /** How many identifiers `Http3Settings` keeps that it does not understand. */
132
132
  export const H3_SETTINGS_KEEP: i32 = 8
133
+ /** `h3Greased` values are `0x1f * N + 0x21`, so each is 2 more than a multiple of this (`0x21 % 0x1f`). */
134
+ const H3_GREASE_STEP: i64 = 0x1f
133
135
 
134
136
  // ---- Error codes (§8.1) ---------------------------------------------------------
135
137
 
@@ -265,9 +267,11 @@ export class Http3Settings {
265
267
  * identifiers this module understands, which are never kept.
266
268
  */
267
269
  unknown(id: i64): i64 {
268
- for (let k: i32 = 0; k < this.unknownCount && k < H3_SETTINGS_KEEP; k++) {
269
- if (this.unknownIds[k] === id) {
270
- return this.unknownValues[k]
270
+ const ids: i64[] = this.unknownIds
271
+ const values: i64[] = this.unknownValues
272
+ for (let k: i32 = 0; k < this.unknownCount && k < toI32(ids.length) && k < toI32(values.length); k++) {
273
+ if (ids[k] === id) {
274
+ return values[k]
271
275
  }
272
276
  }
273
277
  return H3_FRAME_NONE
@@ -325,12 +329,17 @@ export class Http3Settings {
325
329
  return H3_SETTINGS_ERROR
326
330
  }
327
331
  const at: i32 = this.unknownCount
328
- if (at >= 0 && at < H3_SETTINGS_KEEP) {
329
- this.unknownIds[at] = id
330
- this.unknownValues[at] = value
332
+ const ids: i64[] = this.unknownIds
333
+ const values: i64[] = this.unknownValues
334
+ if (at >= 0 && at < H3_SETTINGS_KEEP && at < toI32(ids.length) && at < toI32(values.length)) {
335
+ ids[at] = id
336
+ values[at] = value
331
337
  this.unknownCount = at + 1
332
- } else if (this.dropped < 2147483647) {
333
- this.dropped = this.dropped + 1
338
+ } else {
339
+ const dropped: i32 = this.dropped
340
+ if (dropped < 2147483647) {
341
+ this.dropped = dropped + 1
342
+ }
334
343
  }
335
344
  return H3_SETTINGS_OK
336
345
  }
@@ -349,6 +358,24 @@ export const h3CheckWindow = (what: string, buf: u8[], off: i32, len: i32): void
349
358
  }
350
359
  }
351
360
 
361
+ /**
362
+ * `off + len`, after `h3CheckWindow` has panicked unless the window lies inside `buf`: the sum is then at
363
+ * most `buf.length`, so the `i64` it is taken in always narrows back exactly.
364
+ */
365
+ const h3WindowEnd = (what: string, buf: u8[], off: i32, len: i32): i32 => {
366
+ h3CheckWindow(what, buf, off, len)
367
+ return toI32(toI64(off) + toI64(len))
368
+ }
369
+
370
+ /**
371
+ * The offset just past the varint at `buf[at]`, or -1 when it does not end at or before `end` (or `at` is
372
+ * outside `buf`). Taken in `i64`, so it narrows back exactly whenever it is at most `end`.
373
+ */
374
+ const h3VarintEnd = (buf: u8[], at: i32, end: i32): i32 => {
375
+ const past: i64 = toI64(at) + toI64(quicVarintLength(buf, at))
376
+ return at >= 0 && past > toI64(at) && past <= toI64(end) ? toI32(past) : -1
377
+ }
378
+
352
379
  /**
353
380
  * `count` plus one, saturating at 2^31 - 1: every counter a peer drives.
354
381
  * @param count The counter's current value.
@@ -394,7 +421,7 @@ export const h3VarintLength = (buf: u8[], at: i32): i32 => quicVarintLength(buf,
394
421
  */
395
422
  export const h3PutVarint = (buf: u8[], at: i32, end: i32, value: i64): i32 => {
396
423
  const size: i32 = quicVarintSize(value)
397
- if (size === 0 || !h3FrameRoom(buf, at, end) || at > end - size) {
424
+ if (size === 0 || !h3FrameRoom(buf, at, end) || toI64(at) > toI64(end) - toI64(size)) {
398
425
  return -1
399
426
  }
400
427
  return quicVarintPut(buf, at, value, size)
@@ -409,7 +436,8 @@ export const h3PutVarint = (buf: u8[], at: i32, end: i32, value: i64): i32 => {
409
436
  export const h3FrameHeaderSize = (type: i64, length: i64): i32 => {
410
437
  const a: i32 = quicVarintSize(type)
411
438
  const b: i32 = quicVarintSize(length)
412
- return a === 0 || b === 0 ? H3_FRAME_ZERO : a + b
439
+ // `quicVarintSize` answers 0, 1, 2, 4 or 8.
440
+ return a <= 0 || b <= 0 || a > 8 || b > 8 ? H3_FRAME_ZERO : a + b
413
441
  }
414
442
 
415
443
  /**
@@ -424,20 +452,20 @@ export const h3FrameHeaderSize = (type: i64, length: i64): i32 => {
424
452
  * @returns The header's size, 2 to 16 bytes, or 0 when the window ends before both varints are whole.
425
453
  */
426
454
  export const h3ReadFrameHeader = (h: Http3FrameHeader, buf: u8[], off: i32, len: i32): i32 => {
427
- h3CheckWindow("h3ReadFrameHeader", buf, off, len)
428
- const end: i32 = off + len
455
+ const end: i32 = h3WindowEnd("h3ReadFrameHeader", buf, off, len)
429
456
  const type: i64 = quicVarintRead(buf, off, end)
430
- if (type < 0) {
457
+ const at: i32 = h3VarintEnd(buf, off, end)
458
+ if (type < 0 || at < 0) {
431
459
  return 0
432
460
  }
433
- const at: i32 = off + quicVarintLength(buf, off)
434
461
  const length: i64 = quicVarintRead(buf, at, end)
435
- if (length < 0) {
462
+ const past: i32 = h3VarintEnd(buf, at, end)
463
+ if (length < 0 || past < 0) {
436
464
  return 0
437
465
  }
438
466
  h.type = type
439
467
  h.length = length
440
- return at + quicVarintLength(buf, at) - off
468
+ return toI32(toI64(past) - toI64(off))
441
469
  }
442
470
 
443
471
  /**
@@ -452,7 +480,7 @@ export const h3ReadFrameHeader = (h: Http3FrameHeader, buf: u8[], off: i32, len:
452
480
  */
453
481
  export const h3PutFrameHeader = (buf: u8[], at: i32, end: i32, type: i64, length: i64): i32 => {
454
482
  const size: i32 = h3FrameHeaderSize(type, length)
455
- if (size === 0 || !h3FrameRoom(buf, at, end) || at > end - size) {
483
+ if (size === 0 || !h3FrameRoom(buf, at, end) || toI64(at) > toI64(end) - toI64(size)) {
456
484
  return -1
457
485
  }
458
486
  return h3PutVarint(buf, h3PutVarint(buf, at, end, type), end, length)
@@ -473,7 +501,7 @@ export const h3ReservedHttp2Frame = (type: i64): boolean =>
473
501
  * @returns True when `value` is 0x21 or above and 0x21 more than a multiple of 0x1f; false otherwise,
474
502
  * negatives included.
475
503
  */
476
- export const h3Greased = (value: i64): boolean => value >= 0x21 && (value - 0x21) % 0x1f === 0
504
+ export const h3Greased = (value: i64): boolean => value >= 0x21 && value % H3_GREASE_STEP === 2
477
505
 
478
506
  /**
479
507
  * Reads a whole SETTINGS payload, `buf[off, off + len)`, into `s` (which it
@@ -491,21 +519,21 @@ export const h3Greased = (value: i64): boolean => value >= 0x21 && (value - 0x21
491
519
  * error.
492
520
  */
493
521
  export const h3ReadSettings = (s: Http3Settings, buf: u8[], off: i32, len: i32): i64 => {
494
- h3CheckWindow("h3ReadSettings", buf, off, len)
522
+ const end: i32 = h3WindowEnd("h3ReadSettings", buf, off, len)
495
523
  s.reset()
496
- const end: i32 = off + len
497
524
  let at: i32 = off
498
525
  while (at < end) {
499
526
  const id: i64 = quicVarintRead(buf, at, end)
500
- if (id < 0) {
527
+ const idEnd: i32 = h3VarintEnd(buf, at, end)
528
+ if (id < 0 || idEnd < 0) {
501
529
  return H3_FRAME_ERROR
502
530
  }
503
- at = at + quicVarintLength(buf, at)
504
- const value: i64 = quicVarintRead(buf, at, end)
505
- if (value < 0) {
531
+ const value: i64 = quicVarintRead(buf, idEnd, end)
532
+ const valueEnd: i32 = h3VarintEnd(buf, idEnd, end)
533
+ if (value < 0 || valueEnd < 0) {
506
534
  return H3_FRAME_ERROR
507
535
  }
508
- at = at + quicVarintLength(buf, at)
536
+ at = valueEnd
509
537
  const result: i64 = s.take(id, value)
510
538
  if (result !== H3_SETTINGS_OK) {
511
539
  return result
@@ -534,17 +562,24 @@ export const h3PutSettings = (buf: u8[], at: i32, end: i32, ids: i64[], values:
534
562
  if (n !== toI32(values.length)) {
535
563
  return -1
536
564
  }
537
- let length: i64 = 0
565
+ let length: i32 = 0
538
566
  for (let k: i32 = 0; k < n && k < toI32(ids.length) && k < toI32(values.length); k++) {
539
567
  const a: i32 = quicVarintSize(ids[k])
540
568
  const b: i32 = quicVarintSize(values[k])
541
- if (a === 0 || b === 0) {
569
+ // `quicVarintSize` answers 0 for no varint, else 1, 2, 4 or 8.
570
+ if (a <= 0 || b <= 0 || a > 8 || b > 8) {
571
+ return -1
572
+ }
573
+ // A payload past 2^31 - 10 bytes takes a 9-byte header, so no such frame fits before an `end` that is
574
+ // at most `buf.length`.
575
+ const next: i64 = toI64(length) + toI64(a + b)
576
+ if (next > 2147483638) {
542
577
  return -1
543
578
  }
544
- length = length + toI64(a + b)
579
+ length = toI32(next)
545
580
  }
546
- let p: i32 = h3PutFrameHeader(buf, at, end, H3_FRAME_SETTINGS, length)
547
- if (p < 0 || toI64(p) + length > toI64(end)) {
581
+ let p: i32 = h3PutFrameHeader(buf, at, end, H3_FRAME_SETTINGS, toI64(length))
582
+ if (p < 0 || toI64(p) + toI64(length) > toI64(end)) {
548
583
  return -1
549
584
  }
550
585
  for (let k: i32 = 0; k < n && k < toI32(ids.length) && k < toI32(values.length); k++) {
@@ -589,7 +624,7 @@ export const h3PutIdFrame = (buf: u8[], at: i32, end: i32, type: i64, id: i64):
589
624
  * bytes after it.
590
625
  */
591
626
  export const h3ReadIdPayload = (buf: u8[], off: i32, len: i32): i64 => {
592
- h3CheckWindow("h3ReadIdPayload", buf, off, len)
593
- const id: i64 = quicVarintRead(buf, off, off + len)
594
- return id >= 0 && quicVarintLength(buf, off) === len ? id : H3_FRAME_NONE
627
+ const end: i32 = h3WindowEnd("h3ReadIdPayload", buf, off, len)
628
+ const id: i64 = quicVarintRead(buf, off, end)
629
+ return id >= 0 && h3VarintEnd(buf, off, end) === end ? id : H3_FRAME_NONE
595
630
  }