@amritk/nish-aarch64-linux 0.49.1 → 0.51.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 +237 -160
- package/package.json +1 -1
- package/runtime/gfx/nish-gfx.h +373 -61
- package/runtime/nish.d.ts +94 -11
- package/runtime/nish.h +5 -0
- package/runtime/runtime-host.c +21 -5
- package/std/README.md +14 -11
- package/std/base64.ts +74 -35
- package/std/bytes.ts +207 -97
- package/std/cli-args.ts +150 -107
- package/std/compress/checksum.ts +68 -10
- package/std/compress/deflate.ts +213 -115
- package/std/compress/gzip.ts +124 -49
- package/std/compress/zlib.ts +57 -15
- package/std/crypto/aes.ts +51 -9
- package/std/crypto/base64url.ts +93 -66
- package/std/crypto/bcrypt.ts +25 -21
- package/std/crypto/ed25519.ts +12 -10
- package/std/crypto/hkdf.ts +405 -283
- package/std/crypto/hmac.ts +484 -149
- package/std/crypto/jwt.ts +51 -40
- package/std/crypto/p256.ts +14 -19
- package/std/crypto/pki-roots.ts +35 -12
- package/std/crypto/pki.ts +43 -55
- package/std/crypto/rsa-sign.ts +1635 -0
- package/std/crypto/rsa.ts +26 -4
- package/std/crypto/sha256.ts +212 -90
- package/std/crypto/sha512.ts +135 -49
- 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 +236 -119
- package/std/json.ts +81 -46
- package/std/net/buffer-pool.ts +25 -14
- 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 +224 -61
- package/std/net/handler.ts +189 -88
- package/std/net/hpack.ts +216 -103
- package/std/net/http-compress.ts +104 -42
- package/std/net/http-fields.ts +327 -31
- package/std/net/http-server.ts +326 -24
- package/std/net/http1-client-codec.ts +159 -55
- package/std/net/http1-codec.ts +427 -237
- 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 +139 -60
- package/std/net/http3.ts +140 -79
- package/std/net/multipart.ts +592 -0
- package/std/net/outbound.ts +24 -8
- package/std/net/postgres-async.ts +97 -64
- 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 +147 -40
- 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 +61 -39
- package/std/net/quic-packet.ts +91 -50
- package/std/net/quic-recovery.ts +11 -9
- package/std/net/quic-stream.ts +36 -27
- package/std/net/quic.ts +84 -54
- package/std/net/router.ts +136 -24
- package/std/net/serve.ts +59 -5
- package/std/net/static.ts +86 -36
- package/std/net/tls/client.ts +81 -34
- package/std/net/tls/codec.ts +3 -4
- package/std/net/tls/record.ts +80 -35
- package/std/net/tls/schedule.ts +339 -149
- package/std/net/tls/ticket.ts +6 -5
- package/std/net/tls-tcp.ts +69 -30
- package/std/net/tls.ts +194 -50
- package/std/net/upstream.ts +83 -38
- package/std/net/url.ts +170 -94
- package/std/net/websocket.ts +19 -20
- package/std/net/webtransport.ts +123 -33
- package/std/raster.ts +12 -2
- 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 +176 -24
- package/std/term-rate.ts +8 -3
- package/std/term.ts +4 -4
- package/std/text.ts +38 -16
- 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/base64.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* export const main = (): i32 => {
|
|
8
8
|
* const hi: u8[] = [72, 105]; // "Hi"
|
|
9
|
-
* const text: string = base64Encode(hi);
|
|
9
|
+
* const text: string | null = base64Encode(hi); // "SGk="
|
|
10
10
|
* const out: u8[] = new Array<u8>(base64EncodedLength(2) + 1);
|
|
11
11
|
* const end: i32 = base64EncodeInto(hi, 0, 2, out, 1); // out[1..5) is "SGk=", end is 5
|
|
12
12
|
* return end;
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
* - `base64EncodeInto(src, off, len, dst, at)` writes the encoding of
|
|
22
22
|
* `src[off..off+len)` into `dst` from `at` and allocates nothing, so a frame
|
|
23
23
|
* can be encoded chunk by chunk straight into its output buffer.
|
|
24
|
-
* - `
|
|
24
|
+
* - `base64EncodeIfFits(src, off, len, dst, at)` is the same write and the
|
|
25
|
+
* same answer, kept for callers written against it.
|
|
26
|
+
* - `base64Encode(bytes)` is the whole array as a string, or `null` for an
|
|
27
|
+
* array past 1,610,612,733 bytes, whose encoding no string can hold.
|
|
25
28
|
*
|
|
26
29
|
* **This module only encodes**: what it is for writes base64 and never reads it
|
|
27
30
|
* back. It is not the strict decoder of `nish/crypto/base64url`, which is a
|
|
@@ -42,20 +45,18 @@ const BASE64_PAD: i32 = 61
|
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
47
|
* The characters `n` bytes encode to: four for every three, a short final
|
|
45
|
-
* group counted as a whole one.
|
|
46
|
-
* would pass 2^31 - 1,
|
|
48
|
+
* group counted as a whole one. A negative `n`, or one above 1,610,612,733
|
|
49
|
+
* whose length would pass 2^31 - 1, answers -1.
|
|
47
50
|
*
|
|
48
51
|
* @param n How many bytes are to be encoded; zero answers zero.
|
|
49
52
|
* @returns The number of base64 characters, padding included, that `n` bytes
|
|
50
|
-
* encode to: always a multiple of four.
|
|
53
|
+
* encode to: always a multiple of four. -1 for a negative `n` or one whose
|
|
54
|
+
* encoding would be longer than 2^31 - 1 characters.
|
|
51
55
|
*/
|
|
52
56
|
export const base64EncodedLength = (n: i32): i32 => {
|
|
53
|
-
if (n < 0) {
|
|
54
|
-
panic("base64EncodedLength: a negative byte count")
|
|
55
|
-
}
|
|
56
57
|
// (2^31 - 1) / 4 * 3 groups' worth of bytes is the most whose encoding fits.
|
|
57
|
-
if (n > 1610612733) {
|
|
58
|
-
|
|
58
|
+
if (n < 0 || n > 1610612733) {
|
|
59
|
+
return -1
|
|
59
60
|
}
|
|
60
61
|
const groups: i32 = toI32((n + 2) / 3)
|
|
61
62
|
return groups * 4
|
|
@@ -64,9 +65,10 @@ export const base64EncodedLength = (n: i32): i32 => {
|
|
|
64
65
|
/**
|
|
65
66
|
* Write the base64 of `src[off..off+len)` into `dst` from index `at`, and
|
|
66
67
|
* answer the index just past the last character written, which is
|
|
67
|
-
* `at + base64EncodedLength(len)`. Nothing is allocated.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
68
|
+
* `at + base64EncodedLength(len)`. Nothing is allocated. A source range not
|
|
69
|
+
* inside `src`, an encoding that does not fit in `dst` from `at`, or either
|
|
70
|
+
* array longer than 2^31 - 1 bytes answers -1 with nothing written: all three
|
|
71
|
+
* are checked before anything is written.
|
|
70
72
|
*
|
|
71
73
|
* @param src The bytes to encode from; only `src[off..off+len)` is read.
|
|
72
74
|
* @param off Where in `src` the bytes to encode start.
|
|
@@ -75,32 +77,40 @@ export const base64EncodedLength = (n: i32): i32 => {
|
|
|
75
77
|
* @param dst The buffer the characters are written into, one ASCII byte per
|
|
76
78
|
* character; bytes outside the written range are left as they were.
|
|
77
79
|
* @param at Where in `dst` the first character goes.
|
|
78
|
-
* @returns The index in `dst` just past the last character written
|
|
80
|
+
* @returns The index in `dst` just past the last character written, or -1
|
|
81
|
+
* when the range does not fit.
|
|
79
82
|
*/
|
|
80
83
|
export const base64EncodeInto = (src: u8[], off: i32, len: i32, dst: u8[], at: i32): i32 => {
|
|
81
84
|
// Refused before `toI32`, which saturates a longer length under
|
|
82
85
|
// `--number-mode f64` and would let a range past the true end through.
|
|
83
86
|
if (src.length > 2147483647 || dst.length > 2147483647) {
|
|
84
|
-
|
|
87
|
+
return -1
|
|
85
88
|
}
|
|
86
89
|
const srcLength: i32 = toI32(src.length)
|
|
87
90
|
const dstLength: i32 = toI32(dst.length)
|
|
88
|
-
if (off < 0 || len < 0 ||
|
|
89
|
-
|
|
91
|
+
if (off < 0 || len < 0 || len > srcLength - off) {
|
|
92
|
+
return -1
|
|
90
93
|
}
|
|
91
|
-
|
|
94
|
+
// Past this many bytes the encoding is longer than 2^31 - 1 characters, as
|
|
95
|
+
// in `base64EncodedLength`.
|
|
96
|
+
if (len > 1610612733) {
|
|
97
|
+
return -1
|
|
98
|
+
}
|
|
99
|
+
const need: i32 = toI32((len + 2) / 3) * 4
|
|
92
100
|
if (at < 0 || need > dstLength - at) {
|
|
93
|
-
|
|
101
|
+
return -1
|
|
94
102
|
}
|
|
95
103
|
// A local, so that `abc.length >= 64` below is a fact about the string each
|
|
96
104
|
// character is read from.
|
|
97
105
|
const abc: string = BASE64_ALPHABET
|
|
98
106
|
let i: i32 = off
|
|
99
107
|
let o: i32 = at
|
|
100
|
-
|
|
108
|
+
// At most `srcLength`, by the range check above; summed as `i64` because
|
|
109
|
+
// the overflow proof reads each operand's range alone.
|
|
110
|
+
const end: i32 = toI32(toI64(off) + toI64(len))
|
|
101
111
|
// The checks above make every term after the first true; they are written out
|
|
102
112
|
// because they are what proves the loop's accesses in range.
|
|
103
|
-
while (
|
|
113
|
+
while (i >= 0 && i < srcLength - 2 && i + 2 < end && o >= 0 && o < dstLength - 3 && abc.length >= 64) {
|
|
104
114
|
const group: i32 = (toI32(src[i]) << 16) | (toI32(src[i + 1]) << 8) | toI32(src[i + 2])
|
|
105
115
|
dst[o] = toU8(abc.charCodeAt((group >> 18) & 63))
|
|
106
116
|
dst[o + 1] = toU8(abc.charCodeAt((group >> 12) & 63))
|
|
@@ -108,36 +118,65 @@ export const base64EncodeInto = (src: u8[], off: i32, len: i32, dst: u8[], at: i
|
|
|
108
118
|
dst[o + 3] = toU8(abc.charCodeAt(group & 63))
|
|
109
119
|
i = i + 3
|
|
110
120
|
o = o + 4
|
|
111
|
-
rest = rest - 3
|
|
112
121
|
}
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
|
|
122
|
+
const rest: i64 = toI64(end) - toI64(i)
|
|
123
|
+
// A short final group of one or two bytes, padded; `rest` is 0, 1 or 2, tested
|
|
124
|
+
// by order (`===` 2 on an i64 misreads under runtime/nish.mjs). Every later term is false.
|
|
125
|
+
if (rest < 1 || i < 0 || i >= srcLength || o < 0 || o >= dstLength - 3 || abc.length < 64) {
|
|
116
126
|
return o
|
|
117
127
|
}
|
|
118
128
|
let group: i32 = toI32(src[i]) << 16
|
|
119
|
-
if (rest
|
|
129
|
+
if (rest > 1 && i < srcLength - 1) {
|
|
120
130
|
group = group | (toI32(src[i + 1]) << 8)
|
|
121
131
|
}
|
|
122
132
|
dst[o] = toU8(abc.charCodeAt((group >> 18) & 63))
|
|
123
133
|
dst[o + 1] = toU8(abc.charCodeAt((group >> 12) & 63))
|
|
124
|
-
dst[o + 2] = rest
|
|
134
|
+
dst[o + 2] = rest > 1 ? toU8(abc.charCodeAt((group >> 6) & 63)) : toU8(BASE64_PAD)
|
|
125
135
|
dst[o + 3] = toU8(BASE64_PAD)
|
|
126
136
|
return o + 4
|
|
127
137
|
}
|
|
128
138
|
|
|
129
139
|
/**
|
|
130
|
-
* `
|
|
131
|
-
*
|
|
140
|
+
* `base64EncodeInto` under its earlier name: the same bytes written to the same
|
|
141
|
+
* place, or -1, with nothing written, when `src[off..off+len)` is not inside
|
|
142
|
+
* `src`, the encoding does not fit in `dst` from `at`, or either array is
|
|
143
|
+
* longer than 2^31 - 1 bytes.
|
|
144
|
+
*
|
|
145
|
+
* @param src The bytes to encode from; only `src[off..off+len)` is read.
|
|
146
|
+
* @param off Where in `src` the bytes to encode start.
|
|
147
|
+
* @param len How many bytes of `src` to encode; zero writes nothing and
|
|
148
|
+
* answers `at` when `at` is inside `dst` or just past it.
|
|
149
|
+
* @param dst The buffer the characters are written into, one ASCII byte per
|
|
150
|
+
* character; bytes outside the written range are left as they were.
|
|
151
|
+
* @param at Where in `dst` the first character goes.
|
|
152
|
+
* @returns The index in `dst` just past the last character written, or -1
|
|
153
|
+
* when the range does not fit.
|
|
154
|
+
*/
|
|
155
|
+
export const base64EncodeIfFits = (src: u8[], off: i32, len: i32, dst: u8[], at: i32): i32 =>
|
|
156
|
+
base64EncodeInto(src, off, len, dst, at)
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* `bytes` as padded base64, or `null` past 1,610,612,733 bytes, whose encoding
|
|
160
|
+
* would be longer than 2^31 - 1 characters and so would not fit a string.
|
|
132
161
|
*
|
|
133
162
|
* @param bytes The bytes to encode, all of them; an empty array answers `""`.
|
|
134
|
-
* @returns A fresh string holding the padded encoding
|
|
163
|
+
* @returns A fresh string holding the padded encoding, or `null` for an array
|
|
164
|
+
* too long to encode.
|
|
135
165
|
*/
|
|
136
|
-
export const base64Encode = (bytes: u8[]): string => {
|
|
166
|
+
export const base64Encode = (bytes: u8[]): string | null => {
|
|
137
167
|
// A longer length saturates to the largest `i32` under `--number-mode f64`,
|
|
138
|
-
// which
|
|
168
|
+
// which this refuses, as it does any count past 1,610,612,733 (the most
|
|
169
|
+
// bytes whose encoding fits, as in `base64EncodedLength`).
|
|
139
170
|
const n: i32 = toI32(bytes.length)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
171
|
+
if (n > 1610612733) {
|
|
172
|
+
return null
|
|
173
|
+
}
|
|
174
|
+
// `n` is at most 1,610,612,733 here, so the length is never -1.
|
|
175
|
+
const length: i32 = base64EncodedLength(n)
|
|
176
|
+
const out: u8[] = length > 0 ? new Array<u8>(length) : []
|
|
177
|
+
// `out` is exactly the encoding's length and the range is all of `bytes`,
|
|
178
|
+
// so this writes all of it and never answers -1.
|
|
179
|
+
base64EncodeInto(bytes, 0, n, out, 0)
|
|
180
|
+
// The encoding fills `out` exactly, so its length is where the string ends.
|
|
181
|
+
return String.fromBytes(out, 0, toI32(out.length))
|
|
143
182
|
}
|