@amritk/nish-x86_64-linux 0.17.0 → 0.20.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 +43 -25
- package/bin/nish +0 -0
- package/package.json +2 -2
- package/runtime/nish.d.ts +55 -5
- package/runtime/nish.h +231 -20
- package/runtime/nish.mjs +16 -0
- package/runtime/runtime-aes.c +490 -0
- package/runtime/runtime-cross.c +366 -0
- package/runtime/runtime-host.c +7 -6
- package/runtime/runtime-net.c +93 -34
- package/runtime/runtime-os.c +213 -15
- package/runtime/runtime-parallel.c +590 -107
- package/runtime/runtime-simd.c +203 -0
- package/runtime/runtime-wasm.c +16 -3
- package/runtime/runtime.c +89 -23
- package/runtime/shim.mjs +71 -1
- package/scripts/build.sh +225 -20
- package/std/README.md +86 -55
- package/std/bytes.ts +163 -0
- package/std/crypto/LICENSE-libsecp256k1 +19 -0
- package/std/crypto/aes.ts +238 -76
- package/std/crypto/chacha20poly1305.ts +43 -9
- package/std/crypto/ed25519.ts +840 -0
- package/std/crypto/hkdf.ts +304 -12
- package/std/crypto/hmac.ts +245 -53
- package/std/crypto/p256.ts +1376 -42
- package/std/crypto/x25519.ts +55 -37
- package/std/crypto/x509-random.ts +71 -0
- package/std/crypto/x509.ts +9 -9
- package/std/json-tokenizer.ts +1296 -0
- package/std/json-typed.ts +1014 -0
- package/std/json-value.ts +1163 -0
- package/std/json.ts +1412 -70
- package/std/net/buffer-pool.ts +151 -0
- package/std/net/hpack.ts +416 -112
- package/std/net/http-fields.ts +93 -0
- package/std/net/http1-server.ts +417 -55
- package/std/net/http1.ts +31 -6
- package/std/net/http2-tls.ts +112 -24
- package/std/net/http2.ts +333 -75
- package/std/net/http3-server.ts +231 -45
- package/std/net/http3.ts +187 -28
- package/std/net/prefork.ts +412 -0
- package/std/net/quic-conn-params.ts +86 -16
- package/std/net/quic-listener.ts +576 -219
- package/std/net/quic-packet.ts +443 -58
- package/std/net/quic-recovery.ts +361 -30
- package/std/net/quic-stream.ts +434 -28
- package/std/net/quic.ts +922 -206
- package/std/net/router.ts +676 -0
- package/std/net/tls/codec.ts +426 -27
- package/std/net/tls/record-server.ts +478 -132
- package/std/net/tls/record.ts +133 -42
- package/std/net/tls/schedule.ts +464 -55
- package/std/net/tls/ticket.ts +610 -0
- package/std/net/tls-tcp.ts +204 -57
- package/std/net/tls.ts +1132 -305
- package/std/net/url.ts +571 -0
- package/std/random.ts +94 -0
- package/std/text.ts +77 -0
- package/std/threads.ts +438 -14
package/std/bytes.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `std/bytes` — fixed-width integers and doubles read from, and written into,
|
|
3
|
+
* a byte array at an offset, in either byte order.
|
|
4
|
+
*
|
|
5
|
+
* A wire format, a file header or a hash's message schedule is a `u8[]` with
|
|
6
|
+
* numbers laid out in it, and every reader of one writes the same four-line
|
|
7
|
+
* shift-and-or. This module is that loop written once:
|
|
8
|
+
*
|
|
9
|
+
* import { getU32BE, setU16LE } from "nish/bytes";
|
|
10
|
+
*
|
|
11
|
+
* const header: u8[] = [0, 0, 1, 0, 0, 0];
|
|
12
|
+
* const length = getU32BE(header, 0); // 256
|
|
13
|
+
* setU16LE(header, 4, toU16(513)); // header[4] = 1, header[5] = 2
|
|
14
|
+
*
|
|
15
|
+
* Every function takes the array and the offset of its first byte; the `LE`
|
|
16
|
+
* name puts the least significant byte there, the `BE` name the most
|
|
17
|
+
* significant. The widths are `u16`, `u32` and `u64`, the signed `i32` and
|
|
18
|
+
* `i64`, which are the same bytes read as two's complement, and `f64`, whose
|
|
19
|
+
* bytes are its IEEE 754 bits (`f64ToBits`). There is no `f32`: the language
|
|
20
|
+
* has no bit cast for one.
|
|
21
|
+
*
|
|
22
|
+
* Each access is an ordinary index, so an offset whose bytes do not all lie in
|
|
23
|
+
* the array panics `index`, naming the first byte that does not. A guard in
|
|
24
|
+
* the caller does not yet remove these checks: in a loop guarded by
|
|
25
|
+
* `off + 3 < b.length`, the checker proves an index it can see but not one
|
|
26
|
+
* inside a call, and after `getU32LE` inlines, LLVM keeps the checks on
|
|
27
|
+
* `off + 1` to `off + 3`, because the guard compares the length truncated to
|
|
28
|
+
* `i32` and the checks compare it unsigned at 64 bits. A loop that needs them
|
|
29
|
+
* gone indexes the bytes itself.
|
|
30
|
+
*
|
|
31
|
+
* The in-range answers are byte for byte those of the copies `std/` keeps for
|
|
32
|
+
* itself: `sha256LoadWord` (`std/crypto/sha256.ts`) for `getU32BE`,
|
|
33
|
+
* `chacha20Word` and `poly1305Le64` (`std/crypto/chacha20poly1305.ts`) for
|
|
34
|
+
* `getU32LE` and `getU64LE`, `loadWord` and `storeWord` (`std/crypto/sha512.ts`)
|
|
35
|
+
* for `getU64BE` and `setU64BE`, `http2FramePut32` (`std/net/http2-frame.ts`)
|
|
36
|
+
* for `setU32BE`, and `tlsPutU16` (`std/net/tls/codec.ts`) for `setU16BE`. None
|
|
37
|
+
* of them is replaced by this module. Out of range they differ: the AES and
|
|
38
|
+
* TLS word helpers read zero past the end and drop bytes written there, which
|
|
39
|
+
* their callers rely on, where this module panics.
|
|
40
|
+
*
|
|
41
|
+
* Under Node (`docs/RUN_UNDER_NODE.md`) the `u16` and `u32` functions are
|
|
42
|
+
* expected to answer as they do natively, because the top byte of a `u32` is
|
|
43
|
+
* multiplied in rather than shifted and each byte written is masked before
|
|
44
|
+
* its `toU8`: there `<<` turns bit 31 into a sign and the prelude's `toU8`
|
|
45
|
+
* and `toU32` saturate, and natively the multiply and the mask fold into the
|
|
46
|
+
* shift and the truncation. The others do not yet answer there: the `i32`
|
|
47
|
+
* functions cross between signed and unsigned with `toI32` and `toU32`, which
|
|
48
|
+
* the prelude saturates too (`setI32LE(b, 0, -2)` writes zeros), and the
|
|
49
|
+
* 64-bit functions and `f64` meet its BigInt `u64` and `i64`, which `toU8`
|
|
50
|
+
* refuses.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/** The `u16` whose low byte is `b[off]` and high byte `b[off + 1]`. */
|
|
54
|
+
export const getU16LE = (b: u8[], off: i32): u16 => toU16(b[off]) | (toU16(b[off + 1]) << 8)
|
|
55
|
+
|
|
56
|
+
/** The `u16` whose high byte is `b[off]` and low byte `b[off + 1]`. */
|
|
57
|
+
export const getU16BE = (b: u8[], off: i32): u16 => (toU16(b[off]) << 8) | toU16(b[off + 1])
|
|
58
|
+
|
|
59
|
+
/** The `u32` whose bytes, least significant first, are `b[off]` to `b[off + 3]`. */
|
|
60
|
+
export const getU32LE = (b: u8[], off: i32): u32 =>
|
|
61
|
+
(toU32(b[off]) | (toU32(b[off + 1]) << 8) | (toU32(b[off + 2]) << 16)) +
|
|
62
|
+
toU32(b[off + 3]) * toU32(0x1000000)
|
|
63
|
+
|
|
64
|
+
/** The `u32` whose bytes, most significant first, are `b[off]` to `b[off + 3]`. */
|
|
65
|
+
export const getU32BE = (b: u8[], off: i32): u32 =>
|
|
66
|
+
toU32(b[off]) * toU32(0x1000000) +
|
|
67
|
+
((toU32(b[off + 1]) << 16) | (toU32(b[off + 2]) << 8) | toU32(b[off + 3]))
|
|
68
|
+
|
|
69
|
+
/** The `u64` whose bytes, least significant first, are `b[off]` to `b[off + 7]`. */
|
|
70
|
+
export const getU64LE = (b: u8[], off: i32): u64 => {
|
|
71
|
+
let v = toU64(0)
|
|
72
|
+
for (let i: i32 = 0; i < 8; i++) {
|
|
73
|
+
v = v | (toU64(b[off + i]) << toU64(i * 8))
|
|
74
|
+
}
|
|
75
|
+
return v
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The `u64` whose bytes, most significant first, are `b[off]` to `b[off + 7]`. */
|
|
79
|
+
export const getU64BE = (b: u8[], off: i32): u64 => {
|
|
80
|
+
let v = toU64(0)
|
|
81
|
+
for (let i: i32 = 0; i < 8; i++) {
|
|
82
|
+
v = (v << toU64(8)) | toU64(b[off + i])
|
|
83
|
+
}
|
|
84
|
+
return v
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `getU32LE`'s bits as a two's-complement `i32`. */
|
|
88
|
+
export const getI32LE = (b: u8[], off: i32): i32 => toI32(getU32LE(b, off))
|
|
89
|
+
|
|
90
|
+
/** `getU32BE`'s bits as a two's-complement `i32`. */
|
|
91
|
+
export const getI32BE = (b: u8[], off: i32): i32 => toI32(getU32BE(b, off))
|
|
92
|
+
|
|
93
|
+
/** `getU64LE`'s bits as a two's-complement `i64`. */
|
|
94
|
+
export const getI64LE = (b: u8[], off: i32): i64 => toI64(getU64LE(b, off))
|
|
95
|
+
|
|
96
|
+
/** `getU64BE`'s bits as a two's-complement `i64`. */
|
|
97
|
+
export const getI64BE = (b: u8[], off: i32): i64 => toI64(getU64BE(b, off))
|
|
98
|
+
|
|
99
|
+
/** The `f64` whose IEEE 754 bits are `getU64LE`'s. */
|
|
100
|
+
export const getF64LE = (b: u8[], off: i32): f64 => bitsToF64(toI64(getU64LE(b, off)))
|
|
101
|
+
|
|
102
|
+
/** The `f64` whose IEEE 754 bits are `getU64BE`'s. */
|
|
103
|
+
export const getF64BE = (b: u8[], off: i32): f64 => bitsToF64(toI64(getU64BE(b, off)))
|
|
104
|
+
|
|
105
|
+
/** Writes `v` into `b[off]` and `b[off + 1]`, low byte first. */
|
|
106
|
+
export const setU16LE = (b: u8[], off: i32, v: u16): void => {
|
|
107
|
+
b[off] = toU8(v & 255)
|
|
108
|
+
b[off + 1] = toU8((v >> 8) & 255)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Writes `v` into `b[off]` and `b[off + 1]`, high byte first. */
|
|
112
|
+
export const setU16BE = (b: u8[], off: i32, v: u16): void => {
|
|
113
|
+
b[off] = toU8((v >> 8) & 255)
|
|
114
|
+
b[off + 1] = toU8(v & 255)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Writes `v` into `b[off]` to `b[off + 3]`, least significant byte first. */
|
|
118
|
+
export const setU32LE = (b: u8[], off: i32, v: u32): void => {
|
|
119
|
+
b[off] = toU8(v & 255)
|
|
120
|
+
b[off + 1] = toU8((v >> 8) & 255)
|
|
121
|
+
b[off + 2] = toU8((v >> 16) & 255)
|
|
122
|
+
b[off + 3] = toU8((v >> 24) & 255)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Writes `v` into `b[off]` to `b[off + 3]`, most significant byte first. */
|
|
126
|
+
export const setU32BE = (b: u8[], off: i32, v: u32): void => {
|
|
127
|
+
b[off] = toU8((v >> 24) & 255)
|
|
128
|
+
b[off + 1] = toU8((v >> 16) & 255)
|
|
129
|
+
b[off + 2] = toU8((v >> 8) & 255)
|
|
130
|
+
b[off + 3] = toU8(v & 255)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Writes `v` into `b[off]` to `b[off + 7]`, least significant byte first. */
|
|
134
|
+
export const setU64LE = (b: u8[], off: i32, v: u64): void => {
|
|
135
|
+
for (let i: i32 = 0; i < 8; i++) {
|
|
136
|
+
b[off + i] = toU8((v >> toU64(i * 8)) & toU64(255))
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Writes `v` into `b[off]` to `b[off + 7]`, most significant byte first. */
|
|
141
|
+
export const setU64BE = (b: u8[], off: i32, v: u64): void => {
|
|
142
|
+
for (let i: i32 = 0; i < 8; i++) {
|
|
143
|
+
b[off + i] = toU8((v >> toU64((7 - i) * 8)) & toU64(255))
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Writes `v`'s two's-complement bits as `setU32LE` does. */
|
|
148
|
+
export const setI32LE = (b: u8[], off: i32, v: i32): void => setU32LE(b, off, toU32(v))
|
|
149
|
+
|
|
150
|
+
/** Writes `v`'s two's-complement bits as `setU32BE` does. */
|
|
151
|
+
export const setI32BE = (b: u8[], off: i32, v: i32): void => setU32BE(b, off, toU32(v))
|
|
152
|
+
|
|
153
|
+
/** Writes `v`'s two's-complement bits as `setU64LE` does. */
|
|
154
|
+
export const setI64LE = (b: u8[], off: i32, v: i64): void => setU64LE(b, off, toU64(v))
|
|
155
|
+
|
|
156
|
+
/** Writes `v`'s two's-complement bits as `setU64BE` does. */
|
|
157
|
+
export const setI64BE = (b: u8[], off: i32, v: i64): void => setU64BE(b, off, toU64(v))
|
|
158
|
+
|
|
159
|
+
/** Writes `v`'s IEEE 754 bits as `setU64LE` does. */
|
|
160
|
+
export const setF64LE = (b: u8[], off: i32, v: f64): void => setU64LE(b, off, toU64(f64ToBits(v)))
|
|
161
|
+
|
|
162
|
+
/** Writes `v`'s IEEE 754 bits as `setU64BE` does. */
|
|
163
|
+
export const setF64BE = (b: u8[], off: i32, v: f64): void => setU64BE(b, off, toU64(f64ToBits(v)))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2013 Pieter Wuille
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|