nish 0.42.0 → 0.45.1
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/README.md +11 -5
- package/docs/AI.md +287 -129
- package/package.json +9 -9
- package/runtime/core/numbers.mjs +3 -1
- package/runtime/core/strings.mjs +90 -38
- package/runtime/core.d.ts +24 -0
- package/runtime/core.mjs +21 -0
- package/runtime/nish.d.ts +167 -24
- package/runtime/nish.mjs +7 -1
- package/runtime/runtime-cross.c +9 -0
- package/runtime/runtime-net.c +51 -13
- package/runtime/runtime-region.c +13 -0
- package/runtime/runtime-text.c +11 -0
- package/runtime/runtime-uring.c +83 -25
- package/runtime/runtime-wasm.c +3 -0
- package/runtime/runtime.c +329 -6
- package/runtime/sqlite/README.md +16 -3
- package/runtime/sqlite/nish-sqlite.c +940 -29
- package/scripts/build.sh +111 -29
- package/skills/writing-nish/SKILL.md +12 -4
- package/std/README.md +6 -6
- package/std/array.ts +10 -2
- package/std/bytes.ts +239 -26
- package/std/cli-args.ts +1072 -606
- package/std/cli-flags.ts +180 -98
- package/std/cli.ts +21 -13
- package/std/collections.ts +245 -127
- package/std/compress/checksum.ts +32 -37
- package/std/compress/deflate.ts +1102 -542
- package/std/compress/gzip.ts +290 -145
- package/std/compress/zlib.ts +57 -21
- package/std/crypto/aes.ts +153 -75
- package/std/crypto/base64url.ts +163 -39
- package/std/crypto/bcrypt-batch.ts +164 -90
- package/std/crypto/bcrypt.ts +185 -107
- package/std/crypto/chacha20poly1305.ts +84 -68
- package/std/crypto/ct.ts +9 -7
- package/std/crypto/ed25519.ts +64 -27
- package/std/crypto/hkdf.ts +105 -63
- package/std/crypto/hmac.ts +95 -89
- package/std/crypto/jwt.ts +248 -126
- package/std/crypto/p256.ts +758 -444
- package/std/crypto/p384.ts +20 -13
- package/std/crypto/pki-roots.ts +95 -38
- package/std/crypto/pki.ts +164 -60
- package/std/crypto/rsa.ts +266 -223
- package/std/crypto/scram.ts +141 -0
- package/std/crypto/sha1.ts +157 -57
- package/std/crypto/sha256.ts +502 -422
- package/std/crypto/sha512.ts +204 -135
- package/std/crypto/x509-random.ts +9 -3
- package/std/crypto/x509.ts +331 -171
- package/std/host/ring.ts +1 -1
- package/std/host/text.ts +1 -1
- package/std/json-equal.ts +35 -19
- package/std/json-format.ts +215 -108
- package/std/json-number.ts +126 -72
- package/std/json-pointer.ts +42 -13
- package/std/json-tokenizer.ts +498 -307
- package/std/json-typed.ts +115 -36
- package/std/json-value.ts +341 -152
- package/std/json.ts +300 -158
- package/std/net/buffer-pool.ts +17 -7
- package/std/net/dns-config.ts +427 -236
- package/std/net/dns-message.ts +114 -47
- package/std/net/dns-resolver.ts +736 -237
- package/std/net/dns.ts +205 -52
- package/std/net/fetch.ts +320 -184
- package/std/net/grpc.ts +948 -0
- package/std/net/handler.ts +1276 -218
- package/std/net/hpack.ts +395 -180
- package/std/net/http-compress.ts +502 -65
- package/std/net/http-fields.ts +85 -49
- package/std/net/http-server.ts +1764 -603
- package/std/net/http1-client-codec.ts +372 -161
- package/std/net/http1-codec.ts +665 -331
- package/std/net/http1-server.ts +881 -269
- package/std/net/http2-cleartext.ts +165 -95
- package/std/net/http2-frame.ts +232 -89
- package/std/net/http2-tls.ts +42 -12
- package/std/net/http2.ts +327 -101
- package/std/net/http3-frame.ts +68 -33
- package/std/net/http3-server.ts +672 -206
- package/std/net/http3.ts +669 -191
- package/std/net/oidc.ts +63 -24
- package/std/net/outbound.ts +207 -142
- package/std/net/postgres-async.ts +1223 -470
- package/std/net/postgres-carrier.ts +575 -372
- package/std/net/postgres.ts +1521 -632
- package/std/net/prefork.ts +254 -98
- package/std/net/protobuf.ts +1017 -0
- package/std/net/qpack.ts +143 -92
- package/std/net/quic-conn-ack.ts +104 -22
- package/std/net/quic-conn-cid.ts +66 -26
- package/std/net/quic-conn-params.ts +13 -7
- package/std/net/quic-datagram.ts +90 -27
- package/std/net/quic-frame.ts +324 -121
- package/std/net/quic-listener.ts +206 -91
- package/std/net/quic-packet.ts +289 -163
- package/std/net/quic-recovery.ts +279 -128
- package/std/net/quic-stream.ts +466 -167
- package/std/net/quic.ts +584 -258
- package/std/net/router.ts +450 -99
- package/std/net/serve.ts +661 -240
- package/std/net/static.ts +1458 -0
- package/std/net/tls/client.ts +140 -45
- package/std/net/tls/codec.ts +510 -260
- package/std/net/tls/record-client.ts +268 -76
- package/std/net/tls/record-server.ts +236 -79
- package/std/net/tls/record.ts +173 -47
- package/std/net/tls/schedule.ts +58 -39
- package/std/net/tls/ticket.ts +295 -103
- package/std/net/tls/verify.ts +1 -1
- package/std/net/tls-tcp.ts +218 -75
- package/std/net/tls.ts +260 -152
- package/std/net/upstream.ts +283 -86
- package/std/net/url.ts +277 -102
- package/std/net/websocket.ts +532 -209
- package/std/net/webtransport.ts +755 -436
- package/std/regex.ts +1659 -829
- package/std/sqlite.ts +325 -0
- package/std/sync/ring.ts +320 -156
- package/std/sync/shm.ts +53 -6
- package/std/text.ts +285 -135
- package/std/threads.ts +22 -2
package/std/crypto/p384.ts
CHANGED
|
@@ -5582,11 +5582,7 @@ const p384CurveB = (): u32[] => [
|
|
|
5582
5582
|
* The plain 1, `[1, 0, …, 0]`. A Montgomery multiply by it divides by R, which
|
|
5583
5583
|
* takes an element out of the Montgomery domain: fiat's `from_montgomery`.
|
|
5584
5584
|
*/
|
|
5585
|
-
const p384PlainOne = (): u32[] =>
|
|
5586
|
-
const out: u32[] = p384Limbs()
|
|
5587
|
-
out[0] = 1
|
|
5588
|
-
return out
|
|
5589
|
-
}
|
|
5585
|
+
const p384PlainOne = (): u32[] => [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
5590
5586
|
|
|
5591
5587
|
/** `out = a`, limb by limb. */
|
|
5592
5588
|
const p384Copy = (out: u32[], a: u32[]): void => {
|
|
@@ -5682,8 +5678,12 @@ const p384Bit = (e: u32[], i: i32): boolean => {
|
|
|
5682
5678
|
* which are a constant.
|
|
5683
5679
|
*/
|
|
5684
5680
|
const p384FieldInvert = (out: u32[], a: u32[]): void => {
|
|
5685
|
-
|
|
5686
|
-
|
|
5681
|
+
// p - 2: `p384Prime` with its low limb lowered by 2, spelled out so the
|
|
5682
|
+
// array's length is the literal's.
|
|
5683
|
+
const e: u32[] = [
|
|
5684
|
+
0xfffffffd, 0x0, 0x0, 0xffffffff, 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
|
|
5685
|
+
0xffffffff, 0xffffffff,
|
|
5686
|
+
]
|
|
5687
5687
|
const acc: u32[] = p384Limbs()
|
|
5688
5688
|
p384FiatSetOne(acc)
|
|
5689
5689
|
for (let i: i32 = 383; i >= 0; i--) {
|
|
@@ -5697,8 +5697,11 @@ const p384FieldInvert = (out: u32[], a: u32[]): void => {
|
|
|
5697
5697
|
|
|
5698
5698
|
/** `out = 1 / a` mod n, as `a^(n - 2)` with the scalar Montgomery multiply. */
|
|
5699
5699
|
const p384ScalarInvert = (out: u32[], a: u32[]): void => {
|
|
5700
|
-
|
|
5701
|
-
e[
|
|
5700
|
+
// n - 2: `p384Order` with its low limb lowered by 2.
|
|
5701
|
+
const e: u32[] = [
|
|
5702
|
+
0xccc52971, 0xecec196a, 0x48b0a77a, 0x581a0db2, 0xf4372ddf, 0xc7634d81, 0xffffffff, 0xffffffff,
|
|
5703
|
+
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
|
|
5704
|
+
]
|
|
5702
5705
|
const acc: u32[] = p384Limbs()
|
|
5703
5706
|
p384FiatScalarSetOne(acc)
|
|
5704
5707
|
for (let i: i32 = 383; i >= 0; i--) {
|
|
@@ -5991,10 +5994,14 @@ const p384ScalarInRange = (out: u32[], bytes: u8[], at: i32): boolean => {
|
|
|
5991
5994
|
const p384DigestScalar = (out: u32[], digest: u8[]): void => {
|
|
5992
5995
|
const length: i32 = toI32(digest.length)
|
|
5993
5996
|
const bytes: u8[] = new Array<u8>(48)
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
for (let i: i32 = 0; i <
|
|
5997
|
-
|
|
5997
|
+
// The leftmost 48 bytes, big-endian: each one shifts the buffer up a byte
|
|
5998
|
+
// and comes in at the bottom, so a shorter digest ends right-aligned.
|
|
5999
|
+
for (let i: i32 = 0; i < length && i < 48; i++) {
|
|
6000
|
+
for (let j: i32 = 0; j < 47; j++) {
|
|
6001
|
+
const above: i32 = j + 1
|
|
6002
|
+
bytes[j] = bytes[above]
|
|
6003
|
+
}
|
|
6004
|
+
bytes[47] = digest[i]
|
|
5998
6005
|
}
|
|
5999
6006
|
const a: u32[] = p384Limbs()
|
|
6000
6007
|
p384LimbsFromBytes(a, bytes, 0)
|
package/std/crypto/pki-roots.ts
CHANGED
|
@@ -105,19 +105,60 @@ class PkiRootsLoad {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Counts one PEM block or file skipped. The count is not capped: past
|
|
110
|
+
* `PKI_ROOTS_MAX_FILES` a trust directory's entries are each counted without
|
|
111
|
+
* a read, so no bound below 2^31 holds for it (PKI-R8).
|
|
112
|
+
*/
|
|
113
|
+
const pkiRootsSkip = (load: PkiRootsLoad): void => {
|
|
114
|
+
load.out.skipped = load.out.skipped + 1
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* What the line `text[from .. to)` is: 1 for a `-----BEGIN ...-----` line, 2
|
|
119
|
+
* for a line that starts `-----END `, 0 for any other. The line is cut here,
|
|
120
|
+
* so it is released when this returns rather than kept by the caller's loop.
|
|
121
|
+
*/
|
|
122
|
+
const pkiRootsLineKind = (text: string, from: i32, to: i32): i32 => {
|
|
123
|
+
const line: string = text.substring(from, to)
|
|
124
|
+
if (line.startsWith("-----BEGIN ") && line.endsWith("-----") && line.length > 16) {
|
|
125
|
+
return 1
|
|
126
|
+
}
|
|
127
|
+
return line.startsWith("-----END ") ? 2 : 0
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The lower-case hex digit of `v`, 0 to 15, as a one-character string. */
|
|
131
|
+
const pkiRootsHexDigit = (v: i32): string => String.fromCharCode(v < 10 ? 48 + v : 87 + v)
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* `bytes` in lower-case hex, the key a DER is kept once by. Linear: a for-of reads each octet,
|
|
135
|
+
* with no index left to prove, and pushes its two one-character digits, and
|
|
136
|
+
* one `join` copies the `2n` digits out, so `n` octets cost about `2n`
|
|
137
|
+
* allocations and `O(n)` time. Not `String.fromBytes`, whose range check no
|
|
138
|
+
* proof removes yet.
|
|
139
|
+
*/
|
|
140
|
+
const pkiRootsHex = (bytes: u8[]): string => {
|
|
141
|
+
const out: string[] = []
|
|
142
|
+
for (const b of bytes) {
|
|
143
|
+
out.push(pkiRootsHexDigit(toI32(b) >> 4))
|
|
144
|
+
out.push(pkiRootsHexDigit(toI32(b) & 15))
|
|
145
|
+
}
|
|
146
|
+
return out.join("")
|
|
147
|
+
}
|
|
148
|
+
|
|
108
149
|
/** Keeps `der` as a root when it parses, is new, and the cap has room; counts it skipped otherwise. */
|
|
109
150
|
const pkiRootsKeep = (load: PkiRootsLoad, der: u8[]): void => {
|
|
110
151
|
const cert: X509Certificate | null = x509ParseCertificate(der)
|
|
111
152
|
if (cert === null) {
|
|
112
|
-
load
|
|
153
|
+
pkiRootsSkip(load)
|
|
113
154
|
return
|
|
114
155
|
}
|
|
115
|
-
const key: string =
|
|
156
|
+
const key: string = pkiRootsHex(der)
|
|
116
157
|
if (load.seen.has(key)) {
|
|
117
158
|
return
|
|
118
159
|
}
|
|
119
160
|
if (toI32(load.out.roots.length) >= PKI_ROOTS_MAX_ROOTS) {
|
|
120
|
-
load
|
|
161
|
+
pkiRootsSkip(load)
|
|
121
162
|
return
|
|
122
163
|
}
|
|
123
164
|
load.seen.add(key)
|
|
@@ -125,16 +166,23 @@ const pkiRootsKeep = (load: PkiRootsLoad, der: u8[]): void => {
|
|
|
125
166
|
}
|
|
126
167
|
|
|
127
168
|
/**
|
|
128
|
-
* One PEM block, `text` whole from its BEGIN line through its END
|
|
129
|
-
* labelled other than CERTIFICATE gives `pemToDer` no DER, so it
|
|
169
|
+
* One PEM block, `text[from .. to)` whole from its BEGIN line through its END
|
|
170
|
+
* line. A block labelled other than CERTIFICATE gives `pemToDer` no DER, so it
|
|
171
|
+
* is skipped too.
|
|
130
172
|
*/
|
|
131
|
-
const pkiRootsBlock = (load: PkiRootsLoad, text: string): void => {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
173
|
+
const pkiRootsBlock = (load: PkiRootsLoad, text: string, from: i32, to: i32): void => {
|
|
174
|
+
const block: string = text.substring(from, to)
|
|
175
|
+
const ders: u8[][] | null = pemToDer(block, "CERTIFICATE")
|
|
176
|
+
if (ders === null) {
|
|
177
|
+
pkiRootsSkip(load)
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
const list: u8[][] = ders
|
|
181
|
+
if (toI32(list.length) < 1 || toI32(list.length) > 1) {
|
|
182
|
+
pkiRootsSkip(load)
|
|
135
183
|
return
|
|
136
184
|
}
|
|
137
|
-
pkiRootsKeep(load,
|
|
185
|
+
pkiRootsKeep(load, list[0])
|
|
138
186
|
}
|
|
139
187
|
|
|
140
188
|
/**
|
|
@@ -148,39 +196,43 @@ const pkiRootsSplit = (load: PkiRootsLoad, text: string): void => {
|
|
|
148
196
|
let open: boolean = false
|
|
149
197
|
let blockStart: i32 = 0
|
|
150
198
|
let lineStart: i32 = 0
|
|
151
|
-
while (lineStart < n) {
|
|
199
|
+
while (lineStart >= 0 && lineStart < n) {
|
|
152
200
|
let lineEnd: i32 = lineStart
|
|
153
|
-
while (lineEnd >= 0 && lineEnd < toI32(text.length)
|
|
154
|
-
lineEnd
|
|
201
|
+
while (lineEnd >= 0 && lineEnd < toI32(text.length)) {
|
|
202
|
+
if (toI32(text.charCodeAt(lineEnd)) === 10) {
|
|
203
|
+
break
|
|
204
|
+
}
|
|
205
|
+
// Unsigned: lineEnd is below text.length, so it cannot wrap.
|
|
206
|
+
lineEnd = toI32(toU32(lineEnd) + 1)
|
|
155
207
|
}
|
|
156
|
-
|
|
208
|
+
// Unsigned: lineEnd is below n on that side, so it cannot wrap.
|
|
209
|
+
const next: i32 = lineEnd < n ? toI32(toU32(lineEnd) + 1) : n
|
|
157
210
|
// A carriage return, space or tab before the line feed is no part of the
|
|
158
211
|
// line, so a BEGIN with trailing whitespace still opens a block and is
|
|
159
212
|
// counted when `pemToDer` refuses it, rather than lost unseen.
|
|
160
213
|
let end: i32 = lineEnd
|
|
161
|
-
while (
|
|
162
|
-
end
|
|
163
|
-
(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
) {
|
|
214
|
+
while (end > lineStart && end >= 1 && end <= toI32(text.length)) {
|
|
215
|
+
const c: i32 = toI32(text.charCodeAt(end - 1))
|
|
216
|
+
if (c !== 13 && c !== 32 && c !== 9) {
|
|
217
|
+
break
|
|
218
|
+
}
|
|
167
219
|
end = end - 1
|
|
168
220
|
}
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
221
|
+
const kind: i32 = pkiRootsLineKind(text, lineStart, end)
|
|
222
|
+
if (kind === 1) {
|
|
171
223
|
if (open) {
|
|
172
|
-
load
|
|
224
|
+
pkiRootsSkip(load)
|
|
173
225
|
}
|
|
174
226
|
open = true
|
|
175
227
|
blockStart = lineStart
|
|
176
|
-
} else if (open &&
|
|
177
|
-
pkiRootsBlock(load, text
|
|
228
|
+
} else if (open && kind === 2) {
|
|
229
|
+
pkiRootsBlock(load, text, blockStart, next)
|
|
178
230
|
open = false
|
|
179
231
|
}
|
|
180
232
|
lineStart = next
|
|
181
233
|
}
|
|
182
234
|
if (open) {
|
|
183
|
-
load
|
|
235
|
+
pkiRootsSkip(load)
|
|
184
236
|
}
|
|
185
237
|
}
|
|
186
238
|
|
|
@@ -200,8 +252,9 @@ const pkiRootsRegular = (path: string): string | null => {
|
|
|
200
252
|
|
|
201
253
|
/** Reads `path` as roots: `false` when it is not a regular file that reads, `true` when it was (or would have been, past a cap). */
|
|
202
254
|
const pkiRootsFile = (load: PkiRootsLoad, path: string): boolean => {
|
|
203
|
-
|
|
204
|
-
|
|
255
|
+
const files: i32 = load.files
|
|
256
|
+
if (files >= PKI_ROOTS_MAX_FILES) {
|
|
257
|
+
pkiRootsSkip(load)
|
|
205
258
|
return true
|
|
206
259
|
}
|
|
207
260
|
const real: string | null = pkiRootsRegular(path)
|
|
@@ -209,10 +262,10 @@ const pkiRootsFile = (load: PkiRootsLoad, path: string): boolean => {
|
|
|
209
262
|
if (text === null) {
|
|
210
263
|
return false
|
|
211
264
|
}
|
|
212
|
-
load.files =
|
|
265
|
+
load.files = files + 1
|
|
213
266
|
load.out.sources.push(path)
|
|
214
267
|
if (toI32(text.length) > PKI_ROOTS_MAX_FILE_BYTES) {
|
|
215
|
-
load
|
|
268
|
+
pkiRootsSkip(load)
|
|
216
269
|
return true
|
|
217
270
|
}
|
|
218
271
|
pkiRootsSplit(load, text)
|
|
@@ -236,7 +289,7 @@ export const pkiRootsDirEntry = (name: string): boolean => {
|
|
|
236
289
|
return name.length > 4
|
|
237
290
|
}
|
|
238
291
|
const n: i32 = toI32(name.length)
|
|
239
|
-
if (n < 10 || toI32(name.charCodeAt(8)) !== 46) {
|
|
292
|
+
if (n < 10 || toI32(name.length) < 10 || toI32(name.charCodeAt(8)) !== 46) {
|
|
240
293
|
return false
|
|
241
294
|
}
|
|
242
295
|
for (let i: i32 = 0; i < 8 && i < toI32(name.length); i = i + 1) {
|
|
@@ -258,9 +311,10 @@ const pkiRootsDir = (load: PkiRootsLoad, dir: string): void => {
|
|
|
258
311
|
if (names === null) {
|
|
259
312
|
return
|
|
260
313
|
}
|
|
314
|
+
const list: string[] = names
|
|
261
315
|
const base: string = dir.endsWith("/") ? dir : `${dir}/`
|
|
262
|
-
for (let i: i32 = 0; i < toI32(
|
|
263
|
-
const name: string =
|
|
316
|
+
for (let i: i32 = 0; i < toI32(list.length); i = i + 1) {
|
|
317
|
+
const name: string = list[i]
|
|
264
318
|
if (pkiRootsDirEntry(name)) {
|
|
265
319
|
pkiRootsFile(load, `${base}${name}`)
|
|
266
320
|
}
|
|
@@ -298,15 +352,18 @@ export const pkiLoadRoots = (file: string | null, dirs: string[], bundles: strin
|
|
|
298
352
|
const pkiRootsSplitDirs = (list: string): string[] => {
|
|
299
353
|
const out: string[] = []
|
|
300
354
|
let start: i32 = 0
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
out.push(list.slice(start, i))
|
|
355
|
+
for (let i: i32 = 0; i < toI32(list.length); i = i + 1) {
|
|
356
|
+
if (toI32(list.charCodeAt(i)) === 58) {
|
|
357
|
+
if (i > start && start >= 0) {
|
|
358
|
+
out.push(list.substring(start, i))
|
|
306
359
|
}
|
|
307
360
|
start = i + 1
|
|
308
361
|
}
|
|
309
362
|
}
|
|
363
|
+
const n: i32 = toI32(list.length)
|
|
364
|
+
if (n > start && start >= 0) {
|
|
365
|
+
out.push(list.substring(start, n))
|
|
366
|
+
}
|
|
310
367
|
return out
|
|
311
368
|
}
|
|
312
369
|
|