@amritk/nish-aarch64-linux 0.49.1 → 0.50.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.
- package/INSTALL.md +1 -1
- package/bin/nish +0 -0
- package/docs/AI.md +233 -159
- package/package.json +1 -1
- package/runtime/gfx/nish-gfx.h +373 -61
- package/runtime/nish.d.ts +12 -9
- package/std/README.md +8 -5
- package/std/base64.ts +74 -1
- package/std/bytes.ts +201 -93
- package/std/compress/deflate.ts +20 -15
- package/std/crypto/base64url.ts +93 -66
- package/std/crypto/bcrypt.ts +25 -21
- package/std/crypto/hmac.ts +1 -1
- package/std/crypto/jwt.ts +32 -19
- package/std/crypto/p256.ts +9 -12
- package/std/crypto/pki-roots.ts +7 -4
- package/std/crypto/pki.ts +43 -55
- package/std/crypto/rsa-sign.ts +1632 -0
- package/std/crypto/rsa.ts +26 -4
- package/std/crypto/sha256.ts +135 -68
- package/std/crypto/x25519.ts +12 -11
- package/std/crypto/x509.ts +164 -40
- package/std/gpu/sys.ts +490 -0
- package/std/json-equal.ts +33 -18
- package/std/json-format.ts +39 -8
- package/std/json-number.ts +15 -3
- package/std/json-tokenizer.ts +4 -3
- package/std/json-typed.ts +12 -6
- package/std/json-value.ts +222 -104
- package/std/json.ts +81 -46
- package/std/net/dns-config.ts +18 -5
- package/std/net/dns-message.ts +60 -27
- package/std/net/dns-resolver.ts +35 -16
- package/std/net/dns.ts +3 -2
- package/std/net/fetch.ts +120 -38
- package/std/net/handler.ts +178 -66
- package/std/net/hpack.ts +192 -98
- package/std/net/http-compress.ts +83 -30
- package/std/net/http-fields.ts +327 -31
- package/std/net/http-server.ts +317 -20
- package/std/net/http1-client-codec.ts +137 -40
- package/std/net/http1-codec.ts +391 -202
- package/std/net/http1-server.ts +220 -38
- package/std/net/http2-cleartext.ts +10 -4
- package/std/net/http2-frame.ts +2 -2
- package/std/net/http2-tls.ts +3 -3
- package/std/net/http2.ts +69 -15
- package/std/net/http3-frame.ts +11 -14
- package/std/net/http3-server.ts +12 -15
- package/std/net/http3.ts +41 -29
- package/std/net/multipart.ts +592 -0
- package/std/net/outbound.ts +24 -8
- package/std/net/postgres-async.ts +92 -54
- package/std/net/postgres-carrier.ts +28 -4
- package/std/net/postgres.ts +166 -65
- package/std/net/prefork.ts +86 -5
- package/std/net/protobuf.ts +6 -2
- package/std/net/qpack.ts +66 -25
- package/std/net/quic-conn-ack.ts +27 -7
- package/std/net/quic-conn-cid.ts +13 -7
- package/std/net/quic-datagram.ts +6 -5
- package/std/net/quic-frame.ts +67 -23
- package/std/net/quic-listener.ts +19 -12
- package/std/net/quic-recovery.ts +11 -9
- package/std/net/quic-stream.ts +7 -5
- package/std/net/quic.ts +36 -31
- package/std/net/router.ts +136 -24
- package/std/net/serve.ts +59 -5
- package/std/net/static.ts +81 -33
- package/std/net/tls/record.ts +26 -13
- package/std/net/tls/ticket.ts +6 -5
- package/std/net/tls-tcp.ts +69 -30
- package/std/net/tls.ts +152 -38
- package/std/net/upstream.ts +65 -19
- package/std/net/url.ts +97 -78
- package/std/net/websocket.ts +16 -9
- package/std/net/webtransport.ts +28 -12
- package/std/regex.ts +600 -388
- package/std/sqlite.ts +37 -19
- package/std/sync/ring.ts +232 -115
- package/std/sync/shm.ts +11 -4
- package/std/temporal.ts +232 -133
- package/std/term-io.ts +12 -6
- package/std/term-pixels.ts +158 -22
- package/std/term-rate.ts +8 -3
- package/std/term.ts +4 -4
- package/std/text.ts +33 -11
- package/std/yaml-json.ts +238 -106
- package/std/yaml-lines.ts +47 -27
- package/std/yaml-write.ts +58 -24
- package/std/yaml.ts +808 -395
package/std/net/fetch.ts
CHANGED
|
@@ -125,6 +125,7 @@ import {
|
|
|
125
125
|
tcpConnect,
|
|
126
126
|
} from "nish:net"
|
|
127
127
|
import { cancelled, readable, readableWithin, sleep, writable, writableWithin } from "nish:async"
|
|
128
|
+
import { wrappingAdd } from "nish:unsafe"
|
|
128
129
|
import { getenv, monotonicNanos, wallClockNanos } from "nish:process"
|
|
129
130
|
import { PkiRoots, pkiLoadRoots, pkiLoadSystemRoots } from "nish/crypto/pki-roots"
|
|
130
131
|
import { TlsClient, TlsClientConfig, tlsClientIsIpLiteral } from "nish/net/tls/client"
|
|
@@ -194,6 +195,8 @@ const HTTP_CLIENT_NS_PER_MS: i64 = 1000000
|
|
|
194
195
|
const HTTP_CLIENT_ASYNC_BODY_MAX: i64 = 2147483647
|
|
195
196
|
/** A deadline that never comes: 146 years of monotonic nanoseconds, far below the overflow of a sum with a timeout. */
|
|
196
197
|
const HTTP_CLIENT_NEVER: i64 = 4611686018 * 1000000000
|
|
198
|
+
/** 2^62 - 1, over `HTTP_CLIENT_NEVER` and so over any deadline: so that adding a timeout to one cannot overflow. */
|
|
199
|
+
const HTTP_CLIENT_LOW62: i64 = 2147483648 * 2147483648 - 1
|
|
197
200
|
/** netRead's and netWrite's answer when the socket has nothing ready. */
|
|
198
201
|
const HTTP_CLIENT_WOULD_BLOCK: i32 = -11
|
|
199
202
|
/** pollAdd's events: readable, writable. */
|
|
@@ -547,8 +550,9 @@ export class FetchSyncClient {
|
|
|
547
550
|
// An unread body is still on the wire ahead of the next response.
|
|
548
551
|
this.drop()
|
|
549
552
|
}
|
|
550
|
-
//
|
|
551
|
-
|
|
553
|
+
// A generation is only compared for equality, so it counts mod 2^32: a
|
|
554
|
+
// wrap after 2^32 responses is the counter's answer, not an overflow.
|
|
555
|
+
this.generation = wrappingAdd(this.generation, 1)
|
|
552
556
|
this.deadline = httpClientDeadline(this.options)
|
|
553
557
|
const fault: HttpClientFault = new HttpClientFault()
|
|
554
558
|
let url: Url | null = httpClientTarget(req.url, this.options, fault)
|
|
@@ -979,8 +983,13 @@ export class FetchSyncClient {
|
|
|
979
983
|
while (left > 0 && at >= 0) {
|
|
980
984
|
const n: i32 = conn.write(bytes, at, left)
|
|
981
985
|
if (n > 0 && n <= left) {
|
|
982
|
-
// At most `off + len`, inside `bytes`, so the
|
|
983
|
-
|
|
986
|
+
// At most `off + len`, inside `bytes`, so the window always has an
|
|
987
|
+
// end; the helper measures it so that the sum is proven to fit.
|
|
988
|
+
at = httpClientWindowEnd(bytes, at, n)
|
|
989
|
+
if (at < 0) {
|
|
990
|
+
this.fail(HTTP_E_IO, "the bytes to write lie outside their buffer")
|
|
991
|
+
return false
|
|
992
|
+
}
|
|
984
993
|
left -= n
|
|
985
994
|
} else if (n > 0 || n !== TLS_RECORD_AGAIN || conn.outputEnd === conn.outputStart) {
|
|
986
995
|
this.lost = true
|
|
@@ -1009,8 +1018,13 @@ export class FetchSyncClient {
|
|
|
1009
1018
|
}
|
|
1010
1019
|
const n: i32 = netWrite(this.fd, bytes, at, left)
|
|
1011
1020
|
if (n > 0 && n <= left) {
|
|
1012
|
-
// At most `off + len`, inside `bytes`, so the
|
|
1013
|
-
|
|
1021
|
+
// At most `off + len`, inside `bytes`, so the window always has an
|
|
1022
|
+
// end; the helper measures it so that the sum is proven to fit.
|
|
1023
|
+
at = httpClientWindowEnd(bytes, at, n)
|
|
1024
|
+
if (at < 0) {
|
|
1025
|
+
this.fail(HTTP_E_IO, "the bytes to write lie outside their buffer")
|
|
1026
|
+
return false
|
|
1027
|
+
}
|
|
1014
1028
|
left -= n
|
|
1015
1029
|
} else if (n === HTTP_CLIENT_WOULD_BLOCK || n === 0) {
|
|
1016
1030
|
const waited: i32 = this.wait(this.fd, HTTP_CLIENT_WRITABLE, this.readDeadline(), HTTP_E_READ_TIMEOUT)
|
|
@@ -1054,8 +1068,13 @@ export class FetchSyncClient {
|
|
|
1054
1068
|
const one: u8[] = new Array<u8>(DNS_ADDRESS_BYTES)
|
|
1055
1069
|
let last: i32 = 0
|
|
1056
1070
|
for (let i: i32 = 0; i < usable && i < DNS_RESOLVE_MAX_ADDRESSES; i += 1) {
|
|
1057
|
-
// i
|
|
1058
|
-
|
|
1071
|
+
// `i` is below `DNS_RESOLVE_MAX_ADDRESSES` (16), so the product stays
|
|
1072
|
+
// inside `addresses`; the test restates that with the literal the
|
|
1073
|
+
// bounds proof reads.
|
|
1074
|
+
if (i > 15) {
|
|
1075
|
+
break
|
|
1076
|
+
}
|
|
1077
|
+
copyBytes(one, 0, addresses, i * DNS_ADDRESS_BYTES, DNS_ADDRESS_BYTES)
|
|
1059
1078
|
const fd: i32 = tcpConnect(one)
|
|
1060
1079
|
if (fd < 0) {
|
|
1061
1080
|
last = fd
|
|
@@ -1252,10 +1271,16 @@ export class FetchSyncClient {
|
|
|
1252
1271
|
}
|
|
1253
1272
|
const take: i32 = n < this.pendLen ? n : this.pendLen
|
|
1254
1273
|
copyBytes(buf, off, this.parser.body, this.pendOff, take)
|
|
1255
|
-
//
|
|
1256
|
-
// so
|
|
1257
|
-
|
|
1258
|
-
|
|
1274
|
+
// The copy above fit `take` bytes at `pendOff` inside the parser's body,
|
|
1275
|
+
// so the window has an end, and `take` is at most `pendLen`. The helper
|
|
1276
|
+
// and the test restate both for the bounds proof.
|
|
1277
|
+
const pendEnd: i32 = httpClientWindowEnd(this.parser.body, this.pendOff, take)
|
|
1278
|
+
const pendLen: i32 = this.pendLen
|
|
1279
|
+
if (pendEnd < 0 || take < 0 || take > pendLen) {
|
|
1280
|
+
return -HTTP_E_IO
|
|
1281
|
+
}
|
|
1282
|
+
this.pendOff = pendEnd
|
|
1283
|
+
this.pendLen = pendLen - take
|
|
1259
1284
|
return take
|
|
1260
1285
|
}
|
|
1261
1286
|
|
|
@@ -1461,17 +1486,41 @@ export const httpNoProxyMatch = (noProxy: string, host: string, port: i32): bool
|
|
|
1461
1486
|
|
|
1462
1487
|
// --- helpers -----------------------------------------------------------------
|
|
1463
1488
|
|
|
1489
|
+
/**
|
|
1490
|
+
* `off + len` when `bytes[off, off + len)` lies inside `bytes`, else -1. Each
|
|
1491
|
+
* step subtracts a value that is not negative from one that is no larger than
|
|
1492
|
+
* `bytes.length`, so the bounds proof sees no sum that can overflow.
|
|
1493
|
+
*/
|
|
1494
|
+
const httpClientWindowEnd = (bytes: u8[], off: i32, len: i32): i32 => {
|
|
1495
|
+
if (off < 0 || len < 0) {
|
|
1496
|
+
return -1
|
|
1497
|
+
}
|
|
1498
|
+
const size: i32 = toI32(bytes.length)
|
|
1499
|
+
const room: i32 = size - off
|
|
1500
|
+
if (room < 0) {
|
|
1501
|
+
return -1
|
|
1502
|
+
}
|
|
1503
|
+
const gap: i32 = room - len
|
|
1504
|
+
let end: i32 = -1
|
|
1505
|
+
if (gap >= 0) {
|
|
1506
|
+
end = size - gap
|
|
1507
|
+
}
|
|
1508
|
+
return end
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1464
1511
|
/**
|
|
1465
1512
|
* `ms` milliseconds after `start` on the monotonic clock, or
|
|
1466
1513
|
* `HTTP_CLIENT_NEVER` for a `start` outside [0, 2^62] or a negative `ms`,
|
|
1467
1514
|
* which the clock and the options never give.
|
|
1468
1515
|
*/
|
|
1469
1516
|
const httpClientAfter = (start: i64, ms: i32): i64 => {
|
|
1470
|
-
if (start <
|
|
1517
|
+
if (start < 0 || start > HTTP_CLIENT_NEVER || ms < 0) {
|
|
1471
1518
|
return HTTP_CLIENT_NEVER
|
|
1472
1519
|
}
|
|
1473
|
-
// start
|
|
1474
|
-
|
|
1520
|
+
// `start` is at most `HTTP_CLIENT_NEVER`, under 2^62, so the mask changes
|
|
1521
|
+
// nothing: it is how the bounds proof learns that top, which it keeps from
|
|
1522
|
+
// no comparison past 2^31. The product is under 2^51, so the sum fits.
|
|
1523
|
+
return (start & HTTP_CLIENT_LOW62) + toI64(ms) * toI64(1000000)
|
|
1475
1524
|
}
|
|
1476
1525
|
|
|
1477
1526
|
/**
|
|
@@ -1482,15 +1531,17 @@ const httpClientWaitMs = (end: i64, now: i64): i64 => {
|
|
|
1482
1531
|
if (end <= now) {
|
|
1483
1532
|
return toI64(0)
|
|
1484
1533
|
}
|
|
1485
|
-
if (now <
|
|
1534
|
+
if (now < 0 || end > HTTP_CLIENT_NEVER) {
|
|
1486
1535
|
return HTTP_CLIENT_MAX_WAIT_MS
|
|
1487
1536
|
}
|
|
1488
|
-
// 0 <= now < end
|
|
1489
|
-
const left: i64 =
|
|
1537
|
+
// 0 <= now < end, so the difference fits.
|
|
1538
|
+
const left: i64 = end - now
|
|
1490
1539
|
let ms: i64 = left / toI64(1000000)
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1540
|
+
// A wait of `HTTP_CLIENT_MAX_WAIT_MS` (3600000) or more is cut to that
|
|
1541
|
+
// below whether it is rounded up or not, so only a shorter one is, and the
|
|
1542
|
+
// literal bound proves the step fits.
|
|
1543
|
+
if (left % toI64(1000000) > toI64(0) && ms < 3600000) {
|
|
1544
|
+
ms = ms + toI64(1)
|
|
1494
1545
|
}
|
|
1495
1546
|
return ms > HTTP_CLIENT_MAX_WAIT_MS ? HTTP_CLIENT_MAX_WAIT_MS : ms
|
|
1496
1547
|
}
|
|
@@ -1584,8 +1635,14 @@ const httpClientDropField = (names: string[], values: string[], lower: string):
|
|
|
1584
1635
|
names[keep] = name
|
|
1585
1636
|
values[keep] = value
|
|
1586
1637
|
}
|
|
1587
|
-
// keep
|
|
1588
|
-
|
|
1638
|
+
// `keep` is at most `i`, below the length, so the step fits. Where
|
|
1639
|
+
// they are equal it is written `i + 1`, the form the bounds proof
|
|
1640
|
+
// reads from the loop test.
|
|
1641
|
+
if (keep < i) {
|
|
1642
|
+
keep = keep + 1
|
|
1643
|
+
} else {
|
|
1644
|
+
keep = i + 1
|
|
1645
|
+
}
|
|
1589
1646
|
}
|
|
1590
1647
|
}
|
|
1591
1648
|
while (toI32(names.length) > keep && toI32(names.length) > 0) {
|
|
@@ -2210,9 +2267,9 @@ const httpClientResolve = (
|
|
|
2210
2267
|
fault: HttpClientFault
|
|
2211
2268
|
): i32 => {
|
|
2212
2269
|
let lookupMs: i64 = toI64(0)
|
|
2213
|
-
if (start >=
|
|
2214
|
-
// 0 <= start < until
|
|
2215
|
-
lookupMs =
|
|
2270
|
+
if (start >= 0 && start < until && until <= HTTP_CLIENT_NEVER) {
|
|
2271
|
+
// 0 <= start < until, so the difference fits.
|
|
2272
|
+
lookupMs = (until - start) / HTTP_CLIENT_NS_PER_MS
|
|
2216
2273
|
}
|
|
2217
2274
|
if (lookupMs < toI64(1)) {
|
|
2218
2275
|
lookupMs = toI64(1)
|
|
@@ -2409,8 +2466,11 @@ export class FetchPool {
|
|
|
2409
2466
|
let count: i32 = 0
|
|
2410
2467
|
for (let i: i32 = 0; i < FETCH_POOL_SLOTS && i < toI32(fds.length); i += 1) {
|
|
2411
2468
|
if (fds[i] >= 0) {
|
|
2412
|
-
// At most i
|
|
2413
|
-
|
|
2469
|
+
// At most `i`, below `FETCH_POOL_SLOTS`, so the step fits; the test
|
|
2470
|
+
// restates that for the bounds proof.
|
|
2471
|
+
if (count < i + 1) {
|
|
2472
|
+
count = count + 1
|
|
2473
|
+
}
|
|
2414
2474
|
}
|
|
2415
2475
|
}
|
|
2416
2476
|
return count
|
|
@@ -2458,8 +2518,11 @@ export class FetchPool {
|
|
|
2458
2518
|
if (fds[i] < 0) {
|
|
2459
2519
|
free = free < 0 ? i : free
|
|
2460
2520
|
} else if (routes[i] === route) {
|
|
2461
|
-
// At most i
|
|
2462
|
-
|
|
2521
|
+
// At most `i`, below `FETCH_POOL_SLOTS`, so the step fits; the test
|
|
2522
|
+
// restates that for the bounds proof.
|
|
2523
|
+
if (same < i + 1) {
|
|
2524
|
+
same = same + 1
|
|
2525
|
+
}
|
|
2463
2526
|
}
|
|
2464
2527
|
}
|
|
2465
2528
|
// free, when found, is an index of both arrays; said again for the prover.
|
|
@@ -2745,8 +2808,13 @@ const httpClientWriteRawAsync = async (
|
|
|
2745
2808
|
}
|
|
2746
2809
|
const n: i32 = netWrite(conn.fd, bytes, at, left)
|
|
2747
2810
|
if (n > 0 && n <= left) {
|
|
2748
|
-
// At most `off + len`, inside `bytes`, so the
|
|
2749
|
-
|
|
2811
|
+
// At most `off + len`, inside `bytes`, so the window always has an
|
|
2812
|
+
// end; the helper measures it so that the sum is proven to fit.
|
|
2813
|
+
at = httpClientWindowEnd(bytes, at, n)
|
|
2814
|
+
if (at < 0) {
|
|
2815
|
+
conn.fault.fail(HTTP_E_IO, "the bytes to write lie outside their buffer")
|
|
2816
|
+
return false
|
|
2817
|
+
}
|
|
2750
2818
|
left -= n
|
|
2751
2819
|
} else if (n === HTTP_CLIENT_WOULD_BLOCK || n === 0) {
|
|
2752
2820
|
const ready = await httpClientWaitPeerAsync(conn, true)
|
|
@@ -2962,8 +3030,13 @@ const httpClientWriteAsync = async (conn: HttpClientConn, bytes: u8[]): Promise<
|
|
|
2962
3030
|
while (left > 0 && at >= 0) {
|
|
2963
3031
|
const n: i32 = tls.write(bytes, at, left)
|
|
2964
3032
|
if (n > 0 && n <= left) {
|
|
2965
|
-
// At most `bytes.length`, so the
|
|
2966
|
-
|
|
3033
|
+
// At most `bytes.length`, so the window always has an end; the helper
|
|
3034
|
+
// measures it so that the sum is proven to fit.
|
|
3035
|
+
at = httpClientWindowEnd(bytes, at, n)
|
|
3036
|
+
if (at < 0) {
|
|
3037
|
+
conn.fault.fail(HTTP_E_IO, "the bytes to write lie outside their buffer")
|
|
3038
|
+
return false
|
|
3039
|
+
}
|
|
2967
3040
|
left -= n
|
|
2968
3041
|
} else if (n > 0 || n !== TLS_RECORD_AGAIN || tls.outputEnd === tls.outputStart) {
|
|
2969
3042
|
conn.lost = true
|
|
@@ -3084,8 +3157,12 @@ const httpClientLookupAsync = async (
|
|
|
3084
3157
|
}
|
|
3085
3158
|
client.tick(after)
|
|
3086
3159
|
status = client.result(lookup, addresses, ttls)
|
|
3087
|
-
// slice stays within 1 to HTTP_CLIENT_DNS_SLICE_MS, so doubling
|
|
3088
|
-
|
|
3160
|
+
// `slice` stays within 1 to `HTTP_CLIENT_DNS_SLICE_MS` (16), so doubling
|
|
3161
|
+
// it fits; the test restates that with the literal the bounds proof reads.
|
|
3162
|
+
let twice: i32 = HTTP_CLIENT_DNS_SLICE_MS
|
|
3163
|
+
if (slice >= 0 && slice <= 16) {
|
|
3164
|
+
twice = slice * 2
|
|
3165
|
+
}
|
|
3089
3166
|
slice = twice < HTTP_CLIENT_DNS_SLICE_MS ? twice : HTTP_CLIENT_DNS_SLICE_MS
|
|
3090
3167
|
}
|
|
3091
3168
|
netClose(loop)
|
|
@@ -3120,8 +3197,13 @@ const httpClientDialAsync = async (conn: HttpClientConn, host: string, port: i32
|
|
|
3120
3197
|
const one: u8[] = new Array<u8>(DNS_ADDRESS_BYTES)
|
|
3121
3198
|
let last: i32 = 0
|
|
3122
3199
|
for (let i: i32 = 0; i < usable && i < DNS_RESOLVE_MAX_ADDRESSES; i += 1) {
|
|
3123
|
-
// i
|
|
3124
|
-
|
|
3200
|
+
// `i` is below `DNS_RESOLVE_MAX_ADDRESSES` (16), so the product stays
|
|
3201
|
+
// inside `addresses`; the test restates that with the literal the bounds
|
|
3202
|
+
// proof reads.
|
|
3203
|
+
if (i > 15) {
|
|
3204
|
+
break
|
|
3205
|
+
}
|
|
3206
|
+
copyBytes(one, 0, addresses, i * DNS_ADDRESS_BYTES, DNS_ADDRESS_BYTES)
|
|
3125
3207
|
const fd: i32 = tcpConnect(one)
|
|
3126
3208
|
if (fd < 0) {
|
|
3127
3209
|
last = fd
|