nish 0.20.0 → 0.22.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 +23 -59
- package/docs/AI.md +74 -9
- package/docs/INSTALL.md +52 -10
- package/llms.txt +1 -1
- package/package.json +20 -5
- package/runtime/browser.d.ts +6 -0
- package/runtime/browser.mjs +77 -0
- package/runtime/core/arrays.d.ts +36 -0
- package/runtime/core/arrays.mjs +153 -0
- package/runtime/core/checks.mjs +20 -0
- package/runtime/core/host.d.ts +80 -0
- package/runtime/core/host.mjs +325 -0
- package/runtime/core/numbers.d.ts +66 -0
- package/runtime/core/numbers.mjs +343 -0
- package/runtime/core/result.d.ts +45 -0
- package/runtime/core/result.mjs +140 -0
- package/runtime/core/strings.d.ts +14 -0
- package/runtime/core/strings.mjs +169 -0
- package/runtime/core.d.ts +9 -0
- package/runtime/core.mjs +55 -0
- package/runtime/host.d.ts +6 -0
- package/runtime/nish.d.ts +46 -2
- package/runtime/nish.h +75 -2
- package/runtime/nish.mjs +23 -3
- package/runtime/node.mjs +386 -0
- package/runtime/runtime-bytes.c +401 -0
- package/runtime/runtime-cross.c +1 -1
- package/runtime/runtime-host.c +1 -1
- package/runtime/runtime-net.c +12 -1
- package/runtime/runtime-os.c +1 -1
- package/runtime/runtime-parallel.c +1 -1
- package/runtime/runtime-simd.c +231 -7
- package/runtime/runtime-term.c +504 -0
- package/runtime/runtime-wasm.c +0 -11
- package/runtime/runtime.c +190 -6
- package/runtime/shim.mjs +6 -985
- package/runtime/sqlite/LICENSE.md +85 -0
- package/runtime/sqlite/README.md +45 -0
- package/runtime/sqlite/nish-sqlite.c +359 -0
- package/runtime/sqlite/sqlite3.c +271131 -0
- package/runtime/sqlite/sqlite3.h +14447 -0
- package/scripts/build.sh +311 -59
- package/scripts/check-hardening.mjs +202 -0
- package/scripts/fuzz.sh +218 -0
- package/scripts/gen-json-pow5.mjs +130 -0
- package/scripts/platform-package.mjs +3 -1
- package/scripts/security-scope.mjs +139 -0
- package/scripts/smoke.sh +3 -2
- package/std/LICENSE-fast-float +23 -0
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +32 -12
- package/std/base64.ts +116 -0
- package/std/bytes.ts +256 -0
- package/std/cli.ts +344 -0
- package/std/collections.ts +6 -5
- package/std/crypto/LICENSE-crypt_blowfish +26 -0
- package/std/crypto/base64url.ts +125 -0
- package/std/crypto/bcrypt.ts +1557 -0
- package/std/crypto/hmac.ts +138 -2
- package/std/crypto/x509.ts +11 -122
- package/std/json-tokenizer.ts +2998 -57
- package/std/json-value.ts +22 -3
- package/std/json.ts +87 -8
- package/std/math.ts +608 -0
- package/std/net/http1-server.ts +282 -40
- package/std/net/http1.ts +40 -21
- package/std/net/http3-server.ts +50 -12
- package/std/net/postgres.ts +2294 -0
- package/std/net/prefork.ts +23 -3
- package/std/net/quic-listener.ts +20 -4
- package/std/random.ts +66 -4
- package/std/regex.ts +4274 -0
- package/std/sqlite.ts +391 -0
- package/std/term-io.ts +978 -0
- package/std/term-pixels.ts +874 -0
- package/std/term-probe.ts +459 -0
- package/std/term-rate.ts +993 -0
- package/std/term.ts +2453 -0
- package/std/text.ts +90 -7
- package/std/yaml-lines.ts +141 -0
- package/std/yaml.ts +4675 -0
package/std/crypto/base64url.ts
CHANGED
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
* text already says how many bytes the last group holds (RFC 4648 §3.2 lets a
|
|
7
7
|
* specification that knows its lengths drop the padding, and RFC 7515 §2 does).
|
|
8
8
|
*
|
|
9
|
+
* The module also holds RFC 4648 §4 standard base64 — `+` and `/`, padded with
|
|
10
|
+
* `=` — as `base64StdPadEncode` and `base64StdPadDecode`, for PEM
|
|
11
|
+
* (`nish/crypto/x509`) and SCRAM (`nish/net/postgres`). It is as strict and as
|
|
12
|
+
* constant-time as the URL alphabet, by the same masks, and it refuses a `=`
|
|
13
|
+
* anywhere but the last one or two characters of a text whose length is a
|
|
14
|
+
* multiple of four. They are not `nish/base64`'s `base64Encode`, which encodes
|
|
15
|
+
* only, indexes its alphabet and is for pixels; the `StdPad` names keep the two
|
|
16
|
+
* apart in the program's one namespace.
|
|
17
|
+
*
|
|
9
18
|
* **Decoding is strict, so that each byte string has exactly one spelling.**
|
|
10
19
|
* `base64urlDecode` answers `null` for a `=` anywhere, for any character outside
|
|
11
20
|
* the alphabet (whitespace included), for a length of 1 mod 4 — six bits, not a
|
|
@@ -169,3 +178,119 @@ export const base64urlDecode = (text: string): u8[] | null => {
|
|
|
169
178
|
}
|
|
170
179
|
return out
|
|
171
180
|
}
|
|
181
|
+
|
|
182
|
+
// ---------------------------------------------------------------------------
|
|
183
|
+
// Standard base64 (RFC 4648 §4): `+` and `/`, padded with `=`
|
|
184
|
+
// ---------------------------------------------------------------------------
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The standard-alphabet character for the sextet `v`: the same steps as
|
|
188
|
+
* `base64urlCharOf` until 62, which lands on `+` and 63 on `/`.
|
|
189
|
+
*/
|
|
190
|
+
const base64StdPadCharOf = (v: i32): i32 =>
|
|
191
|
+
toI32(
|
|
192
|
+
65 +
|
|
193
|
+
toU32(v) +
|
|
194
|
+
toU32(base64urlRangeMask(v, 26, 63) & 6) -
|
|
195
|
+
toU32(base64urlRangeMask(v, 52, 63) & 75) -
|
|
196
|
+
toU32(base64urlRangeMask(v, 62, 63) & 15) +
|
|
197
|
+
toU32(base64urlRangeMask(v, 63, 63) & 3)
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
/** The sextet the byte `c` stands for in standard base64, or `-1` when it is not in the alphabet. */
|
|
201
|
+
const base64StdPadSextetOf = (c: i32): i32 => {
|
|
202
|
+
const upper: i32 = base64urlRangeMask(c, 65, 90)
|
|
203
|
+
const lower: i32 = base64urlRangeMask(c, 97, 122)
|
|
204
|
+
const digit: i32 = base64urlRangeMask(c, 48, 57)
|
|
205
|
+
const plus: i32 = base64urlRangeMask(c, 43, 43)
|
|
206
|
+
const slash: i32 = base64urlRangeMask(c, 47, 47)
|
|
207
|
+
const value: i32 =
|
|
208
|
+
(upper & toI32(toU32(c) - 65)) |
|
|
209
|
+
(lower & toI32(toU32(c) - 71)) |
|
|
210
|
+
(digit & toI32(toU32(c) + 4)) |
|
|
211
|
+
(plus & 62) |
|
|
212
|
+
(slash & 63)
|
|
213
|
+
return value | ~(upper | lower | digit | plus | slash)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* `data` in padded standard base64, as one line: PEM's body, and SCRAM's
|
|
218
|
+
* nonces, salts and proofs (RFC 5802 §5.1). One `=` closes a final group of
|
|
219
|
+
* two bytes, two a group of one. An array longer than 2^31 - 1 bytes panics.
|
|
220
|
+
*/
|
|
221
|
+
export const base64StdPadEncode = (data: u8[]): string => {
|
|
222
|
+
if (data.length > 2147483647) {
|
|
223
|
+
panic("base64StdPadEncode: more than 2^31 - 1 bytes")
|
|
224
|
+
}
|
|
225
|
+
const parts: string[] = []
|
|
226
|
+
let acc: i32 = 0
|
|
227
|
+
let bits: u32 = 0
|
|
228
|
+
for (let k: i32 = 0; k < toI32(data.length); k++) {
|
|
229
|
+
acc = ((acc << 8) | toI32(data[k])) & 0xfff
|
|
230
|
+
bits += 8
|
|
231
|
+
while (bits >= 6) {
|
|
232
|
+
bits -= 6
|
|
233
|
+
parts.push(String.fromCharCode(base64StdPadCharOf((acc >> toI32(bits)) & 63)))
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (bits > 0) {
|
|
237
|
+
parts.push(String.fromCharCode(base64StdPadCharOf((acc << toI32(6 - bits)) & 63)))
|
|
238
|
+
}
|
|
239
|
+
const tail: i32 = toI32(data.length) % 3
|
|
240
|
+
if (tail > 0) {
|
|
241
|
+
parts.push(tail === 1 ? "==" : "=")
|
|
242
|
+
}
|
|
243
|
+
return parts.join("")
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The bytes of padded standard base64 `text`, or `null` unless it is the one
|
|
248
|
+
* canonical spelling of them: a whole number of four-character groups, `=`
|
|
249
|
+
* only as the last one or two characters, every other character in the
|
|
250
|
+
* alphabet, and the bits the padding leaves over all zero (RFC 4648 §3.5).
|
|
251
|
+
* The empty text is the spelling of no bytes (RFC 4648 §10). Where the padding
|
|
252
|
+
* is depends on the length alone; the characters themselves are read by masks
|
|
253
|
+
* and judged once, after the last.
|
|
254
|
+
*/
|
|
255
|
+
export const base64StdPadDecode = (text: string): u8[] | null => {
|
|
256
|
+
if (text.length > 2147483647) {
|
|
257
|
+
return null
|
|
258
|
+
}
|
|
259
|
+
const n: i32 = toI32(text.length)
|
|
260
|
+
if ((n & 3) !== 0) {
|
|
261
|
+
return null
|
|
262
|
+
}
|
|
263
|
+
let pad: i32 = 0
|
|
264
|
+
if (n > 0 && toI32(text.charCodeAt(n - 1)) === 61) {
|
|
265
|
+
pad = toI32(text.charCodeAt(n - 2)) === 61 ? 2 : 1
|
|
266
|
+
}
|
|
267
|
+
const chars: i32 = n - pad
|
|
268
|
+
const out: u8[] = new Array<u8>((n >> 2) * 3 - pad)
|
|
269
|
+
const outLen: i32 = toI32(out.length)
|
|
270
|
+
let bad: i32 = 0
|
|
271
|
+
let acc: i32 = 0
|
|
272
|
+
let bits: i32 = 0
|
|
273
|
+
let j: i32 = 0
|
|
274
|
+
// The padding is past `chars` and is not data; which positions those are is
|
|
275
|
+
// a fact about the length. A `=` before them is outside the alphabet.
|
|
276
|
+
for (let k: i32 = 0; k < chars && k < toI32(text.length); k++) {
|
|
277
|
+
const v: i32 = base64StdPadSextetOf(toI32(text.charCodeAt(k)))
|
|
278
|
+
bad = bad | (v >> 31)
|
|
279
|
+
acc = ((acc << 6) | (v & 63)) & 0xfff
|
|
280
|
+
bits += 6
|
|
281
|
+
if (bits >= 8) {
|
|
282
|
+
bits -= 8
|
|
283
|
+
// Always true — `out` was sized from the same length — and written so
|
|
284
|
+
// the store keeps no bounds check.
|
|
285
|
+
if (j >= 0 && j < outLen) {
|
|
286
|
+
out[j] = toU8((acc >> bits) & 255)
|
|
287
|
+
}
|
|
288
|
+
j++
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
bad = bad | (acc & ((1 << bits) - 1))
|
|
292
|
+
if (bad !== 0) {
|
|
293
|
+
return null
|
|
294
|
+
}
|
|
295
|
+
return out
|
|
296
|
+
}
|