@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
@@ -94,6 +94,19 @@ const base64urlSextetOf = (c: i32): i32 => {
94
94
  return value | ~(upper | lower | digit | dash | underscore)
95
95
  }
96
96
 
97
+ /**
98
+ * Writes `byte` to `out[at]` and answers `at + 1`. Every caller writes inside
99
+ * an array it sized or checked for the text or bytes it puts there; the test
100
+ * is the shape that proves the store, not a check a caller can fail.
101
+ */
102
+ const base64Put = (out: u8[], at: i32, byte: u8): i32 => {
103
+ if (at >= 0 && at < toI32(out.length)) {
104
+ out[at] = byte
105
+ return at + 1
106
+ }
107
+ return at
108
+ }
109
+
97
110
  /**
98
111
  * `data` as unpadded base64url: four characters per three bytes, and two or
99
112
  * three for a short final group.
@@ -164,49 +177,57 @@ export const base64urlDecode = (text: string): u8[] | null => {
164
177
  return null
165
178
  }
166
179
  // Three bytes per full group of four, and one fewer than the characters in a
167
- // short final group; `n * 3 / 4` would overflow for a text over 700 MB.
168
- const out: u8[] = new Array<u8>((n >> 2) * 3 + (tail === 0 ? 0 : tail - 1))
169
- const outLen: i32 = toI32(out.length)
180
+ // short final group; `n * 3 / 4` would overflow for a text over 700 MB. The
181
+ // sum is a `u32`, exact for any `n` here.
182
+ const out: u8[] = new Array<u8>(toU32(n >> 2) * 3 + (tail === 0 ? 0 : toU32(tail) - 1))
170
183
  // All ones once any character is outside the alphabet (a sextet of `-1`
171
184
  // shifted right by 31), and non-zero once the text ends on a bit that
172
185
  // encodes no byte.
173
186
  let bad: i32 = 0
174
187
  // Four characters make one 24-bit word and three bytes, so a full group has
175
188
  // no count of waiting bits to test, and its four sextets are independent.
189
+ // `full` is where the short final group starts, `n` less its tail.
190
+ //
191
+ // Each read is written out here rather than in a helper: a function that
192
+ // hands its `string` parameter to another is taken to keep it, and then a
193
+ // caller decoding a string it built inside `using a = arena()` is refused.
194
+ // The test on each position is the shape that proves the read, and depends
195
+ // on the position alone; positions are `u32`s so that `k + 3` wraps rather
196
+ // than overflows.
197
+ const full: u32 = toU32(n & ~3)
176
198
  let j: i32 = 0
177
- for (let k: i32 = 0; k + 3 < n; k += 4) {
178
- const s0: i32 = base64urlSextetOf(toI32(text.charCodeAt(k)))
179
- const s1: i32 = base64urlSextetOf(toI32(text.charCodeAt(k + 1)))
180
- const s2: i32 = base64urlSextetOf(toI32(text.charCodeAt(k + 2)))
181
- const s3: i32 = base64urlSextetOf(toI32(text.charCodeAt(k + 3)))
199
+ for (let k: u32 = 0; k < full; k += 4) {
200
+ const i0: i32 = toI32(k)
201
+ const i1: i32 = toI32(k + 1)
202
+ const i2: i32 = toI32(k + 2)
203
+ const i3: i32 = toI32(k + 3)
204
+ const s0: i32 = i0 >= 0 && i0 < n ? base64urlSextetOf(toI32(text.charCodeAt(i0))) : -1
205
+ const s1: i32 = i1 >= 0 && i1 < n ? base64urlSextetOf(toI32(text.charCodeAt(i1))) : -1
206
+ const s2: i32 = i2 >= 0 && i2 < n ? base64urlSextetOf(toI32(text.charCodeAt(i2))) : -1
207
+ const s3: i32 = i3 >= 0 && i3 < n ? base64urlSextetOf(toI32(text.charCodeAt(i3))) : -1
182
208
  bad = bad | ((s0 | s1 | s2 | s3) >> 31)
183
209
  const word: i32 = ((s0 & 63) << 18) | ((s1 & 63) << 12) | ((s2 & 63) << 6) | (s3 & 63)
184
- // Always true — `out` was sized from the same length — but written out so
185
- // that the three stores keep no bounds check.
186
- if (j >= 0 && j + 2 < outLen) {
187
- out[j] = toU8(word >> 16)
188
- out[j + 1] = toU8((word >> 8) & 255)
189
- out[j + 2] = toU8(word & 255)
190
- }
191
- j += 3
210
+ j = base64Put(out, j, toU8(word >> 16))
211
+ j = base64Put(out, j, toU8((word >> 8) & 255))
212
+ j = base64Put(out, j, toU8(word & 255))
192
213
  }
193
214
  // A short final group of two or three characters: one or two bytes, and the
194
215
  // four or two bits left over belong to no byte, so they must be zero for `AA`
195
216
  // to be the only spelling of a zero byte and `AB` refused (RFC 4648 §3.5).
196
217
  if (tail !== 0) {
197
- const k: i32 = n - tail
198
- const s0: i32 = base64urlSextetOf(toI32(text.charCodeAt(k)))
199
- const s1: i32 = base64urlSextetOf(toI32(text.charCodeAt(k + 1)))
218
+ const i0: i32 = toI32(full)
219
+ const i1: i32 = toI32(full + 1)
220
+ const i2: i32 = toI32(full + 2)
221
+ const s0: i32 = i0 >= 0 && i0 < n ? base64urlSextetOf(toI32(text.charCodeAt(i0))) : -1
222
+ const s1: i32 = i1 >= 0 && i1 < n ? base64urlSextetOf(toI32(text.charCodeAt(i1))) : -1
200
223
  // A third character only when the tail has one; a two-character tail reads
201
224
  // its place as `A`, the zero sextet, which adds no bits.
202
- const s2: i32 = tail === 3 ? base64urlSextetOf(toI32(text.charCodeAt(k + 2))) : 0
225
+ const s2: i32 = tail === 3 && i2 >= 0 && i2 < n ? base64urlSextetOf(toI32(text.charCodeAt(i2))) : 0
203
226
  bad = bad | ((s0 | s1 | s2) >> 31)
204
227
  const word: i32 = ((s0 & 63) << 18) | ((s1 & 63) << 12) | ((s2 & 63) << 6)
205
- if (j >= 0 && j < outLen) {
206
- out[j] = toU8(word >> 16)
207
- }
208
- if (tail === 3 && j + 1 >= 0 && j + 1 < outLen) {
209
- out[j + 1] = toU8((word >> 8) & 255)
228
+ j = base64Put(out, j, toU8(word >> 16))
229
+ if (tail === 3) {
230
+ base64Put(out, j, toU8((word >> 8) & 255))
210
231
  }
211
232
  // The bits under the last byte written: sixteen of the word when one byte
212
233
  // was, eight when two were.
@@ -306,33 +327,34 @@ export const base64StdPadEncodeInto = (data: u8[], start: i32, length: i32, out:
306
327
  if (start < 0 || length < 0 || start > toI32(data.length) - length || length > 1610612733) {
307
328
  panic("base64StdPadEncodeInto: bytes outside their buffer")
308
329
  }
309
- const end: i32 = at + ((length + 2) / 3) * 4
310
- if (at < 0 || at > toI32(out.length) || end > toI32(out.length)) {
330
+ // The text's length, and the room after `at`, as `u32`s: exact, since
331
+ // `length` is at most 1610612733 and `at` at most `out.length`.
332
+ const textLength: u32 = ((toU32(length) + 2) / 3) * 4
333
+ if (at < 0 || at > toI32(out.length) || textLength > toU32(toI32(out.length)) - toU32(at)) {
311
334
  panic("base64StdPadEncodeInto: text that does not fit its buffer")
312
335
  }
336
+ const end: i32 = toI32(toU32(at) + textLength)
337
+ // `k` runs through `data[start .. start + length)` and `j` through the text;
338
+ // the bounds on them only let the prover see what the tests above checked.
313
339
  let j: i32 = at
340
+ let k: i32 = start
314
341
  let acc: i32 = 0
315
342
  let bits: u32 = 0
316
- for (let k: i32 = start; k < start + length; k++) {
317
- if (k >= 0 && k < toI32(data.length)) {
318
- acc = ((acc << 8) | toI32(data[k])) & 0xfff
319
- }
343
+ for (let n: i32 = 0; n < length && k >= 0 && k < toI32(data.length); n++) {
344
+ acc = ((acc << 8) | toI32(data[k])) & 0xfff
345
+ k += 1
320
346
  bits += 8
321
347
  while (bits >= 6) {
322
348
  bits -= 6
323
- if (j >= 0 && j < toI32(out.length)) {
324
- out[j] = toU8(base64StdPadCharOf((acc >> toI32(bits)) & 63))
325
- }
326
- j++
349
+ j = base64Put(out, j, toU8(base64StdPadCharOf((acc >> toI32(bits)) & 63)))
327
350
  }
328
351
  }
329
352
  if (bits > 0) {
330
- out[j] = toU8(base64StdPadCharOf((acc << toI32(6 - bits)) & 63))
331
- j++
353
+ j = base64Put(out, j, toU8(base64StdPadCharOf((acc << toI32(6 - bits)) & 63)))
332
354
  }
333
- while (j < end) {
355
+ while (j >= 0 && j < end && j < toI32(out.length)) {
334
356
  out[j] = 61
335
- j++
357
+ j += 1
336
358
  }
337
359
  return end
338
360
  }
@@ -360,16 +382,22 @@ export const base64StdPadDecodedLength = (text: u8[], start: i32, length: i32):
360
382
  if ((length & 3) !== 0) {
361
383
  return -1
362
384
  }
363
- let pad: i32 = 0
364
- if (length > 0 && toI32(text[start + length - 1]) === 61) {
365
- pad = toI32(text[start + length - 2]) === 61 ? 2 : 1
385
+ // The text's last character, a `u32` sum that is exact once the range is
386
+ // inside `text`; a length that is a multiple of four and not 0 is at least 4,
387
+ // so the character before it is in the range too.
388
+ const last: i32 = toI32(toU32(start) + toU32(length) - 1)
389
+ let pad: u32 = 0
390
+ if (length > 0 && last >= 1 && last < toI32(text.length) && toI32(text[last]) === 61) {
391
+ pad = toI32(text[last - 1]) === 61 ? 2 : 1
366
392
  }
367
- const chars: i32 = length - pad
393
+ const chars: i32 = toI32(toU32(length) - pad)
368
394
  let bad: i32 = 0
369
395
  let acc: i32 = 0
370
- let bits: i32 = 0
371
- for (let k: i32 = 0; k < chars; k++) {
372
- const v: i32 = base64StdPadSextetOf(toI32(text[start + k]))
396
+ let bits: u32 = 0
397
+ let p: i32 = start
398
+ for (let k: i32 = 0; k < chars && p >= 0 && p < toI32(text.length); k++) {
399
+ const v: i32 = base64StdPadSextetOf(toI32(text[p]))
400
+ p += 1
373
401
  bad = bad | (v >> 31)
374
402
  acc = ((acc << 6) | (v & 63)) & 0xfff
375
403
  bits += 6
@@ -377,11 +405,11 @@ export const base64StdPadDecodedLength = (text: u8[], start: i32, length: i32):
377
405
  bits -= 8
378
406
  }
379
407
  }
380
- bad = bad | (acc & ((1 << bits) - 1))
408
+ bad = bad | (acc & toI32((toU32(1) << bits) - 1))
381
409
  if (bad !== 0) {
382
410
  return -1
383
411
  }
384
- return (length >> 2) * 3 - pad
412
+ return toI32(toU32(length >> 2) * 3 - pad)
385
413
  }
386
414
 
387
415
  /**
@@ -406,16 +434,16 @@ export const base64StdPadDecode = (text: string): u8[] | null => {
406
434
  if ((n & 3) !== 0) {
407
435
  return null
408
436
  }
409
- let pad: i32 = 0
410
- if (n > 0 && toI32(text.charCodeAt(n - 1)) === 61) {
437
+ // A length that is a multiple of four and not 0 is at least 4.
438
+ let pad: u32 = 0
439
+ if (n >= 4 && toI32(text.charCodeAt(n - 1)) === 61) {
411
440
  pad = toI32(text.charCodeAt(n - 2)) === 61 ? 2 : 1
412
441
  }
413
- const chars: i32 = n - pad
414
- const out: u8[] = new Array<u8>((n >> 2) * 3 - pad)
415
- const outLen: i32 = toI32(out.length)
442
+ const chars: i32 = toI32(toU32(n) - pad)
443
+ const out: u8[] = new Array<u8>(toU32(n >> 2) * 3 - pad)
416
444
  let bad: i32 = 0
417
445
  let acc: i32 = 0
418
- let bits: i32 = 0
446
+ let bits: u32 = 0
419
447
  let j: i32 = 0
420
448
  // The padding is past `chars` and is not data; which positions those are is
421
449
  // a fact about the length. A `=` before them is outside the alphabet.
@@ -426,15 +454,10 @@ export const base64StdPadDecode = (text: string): u8[] | null => {
426
454
  bits += 6
427
455
  if (bits >= 8) {
428
456
  bits -= 8
429
- // Always true — `out` was sized from the same length — and written so
430
- // the store keeps no bounds check.
431
- if (j >= 0 && j < outLen) {
432
- out[j] = toU8((acc >> bits) & 255)
433
- }
434
- j++
457
+ j = base64Put(out, j, toU8((acc >> toI32(bits)) & 255))
435
458
  }
436
459
  }
437
- bad = bad | (acc & ((1 << bits) - 1))
460
+ bad = bad | (acc & toI32((toU32(1) << bits) - 1))
438
461
  if (bad !== 0) {
439
462
  return null
440
463
  }