@amritk/nish-x86_64-linux 0.44.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/bin/nish +0 -0
- package/docs/AI.md +18 -16
- package/package.json +1 -1
- package/runtime/core/numbers.mjs +3 -1
- package/runtime/core/strings.mjs +90 -38
- package/runtime/core.d.ts +8 -0
- package/runtime/core.mjs +16 -0
- package/runtime/nish.d.ts +47 -5
- package/runtime/nish.mjs +4 -0
- package/std/README.md +3 -3
- 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 +84 -61
- 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 +3 -4
- package/std/crypto/sha1.ts +107 -65
- 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/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 +1275 -217
- 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 -602
- package/std/net/http1-client-codec.ts +372 -161
- package/std/net/http1-codec.ts +665 -331
- package/std/net/http1-server.ts +660 -278
- 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 +647 -192
- package/std/net/http3.ts +667 -189
- package/std/net/oidc.ts +63 -24
- package/std/net/outbound.ts +207 -142
- package/std/net/postgres-async.ts +1165 -443
- package/std/net/postgres-carrier.ts +575 -372
- package/std/net/postgres.ts +1459 -559
- 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 +50 -18
- 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 +225 -124
- package/std/net/quic-listener.ts +197 -89
- 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 +568 -257
- package/std/net/router.ts +450 -99
- package/std/net/serve.ts +651 -232
- 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 +370 -186
- package/std/net/webtransport.ts +755 -436
- package/std/regex.ts +1659 -829
- package/std/sync/ring.ts +320 -156
- package/std/sync/shm.ts +53 -6
- package/std/text.ts +205 -124
- package/std/threads.ts +22 -2
package/std/crypto/hkdf.ts
CHANGED
|
@@ -119,7 +119,7 @@ const HKDF_LABEL_PREFIX: string = "tls13 "
|
|
|
119
119
|
* code says what the RFC says.
|
|
120
120
|
*/
|
|
121
121
|
const hkdfSalt = (salt: u8[], hashLen: i32): u8[] =>
|
|
122
|
-
toI32(salt.length) === 0 ? new Array<u8>(hashLen) : salt
|
|
122
|
+
toI32(salt.length) === 0 ? new Array<u8>(toU16(hashLen)) : salt
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* Copies `block[0 .. n)` to `out[at .. at + n)`, where `n` is as much of the
|
|
@@ -128,12 +128,25 @@ const hkdfSalt = (salt: u8[], hashLen: i32): u8[] =>
|
|
|
128
128
|
const hkdfAppend = (out: u8[], at: i32, block: u8[]): i32 => {
|
|
129
129
|
const outLength: i32 = toI32(out.length)
|
|
130
130
|
const blockLength: i32 = toI32(block.length)
|
|
131
|
-
let
|
|
132
|
-
|
|
133
|
-
out[
|
|
134
|
-
|
|
131
|
+
let p: i32 = at
|
|
132
|
+
for (let k: i32 = 0; k < blockLength && p >= 0 && p < outLength; k += 1) {
|
|
133
|
+
out[p] = block[k]
|
|
134
|
+
p += 1
|
|
135
|
+
}
|
|
136
|
+
return p
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Writes `byte` to `out[at]` and answers `at + 1`. Every caller writes inside
|
|
141
|
+
* a buffer it sized for the bytes it puts there; the test is the shape that
|
|
142
|
+
* proves the store, not a check a caller can fail.
|
|
143
|
+
*/
|
|
144
|
+
const hkdfPut = (out: u8[], at: i32, byte: u8): i32 => {
|
|
145
|
+
if (at >= 0 && at < toI32(out.length)) {
|
|
146
|
+
out[at] = byte
|
|
147
|
+
return at + 1
|
|
135
148
|
}
|
|
136
|
-
return at
|
|
149
|
+
return at
|
|
137
150
|
}
|
|
138
151
|
|
|
139
152
|
/**
|
|
@@ -177,17 +190,21 @@ export const hkdfExpandSha256 = (prk: u8[], info: u8[], length: i32): u8[] | nul
|
|
|
177
190
|
) {
|
|
178
191
|
return null
|
|
179
192
|
}
|
|
180
|
-
|
|
193
|
+
// At most 255 blocks of 48 bytes, so `toU16` keeps every length exactly.
|
|
194
|
+
const out: u8[] = new Array<u8>(toU16(length))
|
|
181
195
|
const counter: u8[] = new Array<u8>(1)
|
|
182
196
|
const counterLength: i32 = 1
|
|
183
197
|
let previous: u8[] = []
|
|
184
198
|
let at: i32 = 0
|
|
185
|
-
|
|
199
|
+
// At most 255, so the byte below is the counter itself.
|
|
200
|
+
let i: u32 = 1
|
|
186
201
|
while (at < length) {
|
|
187
202
|
const mac = new HmacSha256(prk)
|
|
188
203
|
mac.update(previous, HKDF_FROM, toI32(previous.length))
|
|
189
204
|
mac.update(info, HKDF_FROM, toI32(info.length))
|
|
190
|
-
counter
|
|
205
|
+
if (toI32(counter.length) >= 1) {
|
|
206
|
+
counter[0] = toU8(i)
|
|
207
|
+
}
|
|
191
208
|
mac.update(counter, HKDF_FROM, counterLength)
|
|
192
209
|
const block: u8[] = mac.digest()
|
|
193
210
|
wipe(previous)
|
|
@@ -220,17 +237,21 @@ export const hkdfExpandSha384 = (prk: u8[], info: u8[], length: i32): u8[] | nul
|
|
|
220
237
|
) {
|
|
221
238
|
return null
|
|
222
239
|
}
|
|
223
|
-
|
|
240
|
+
// At most 255 blocks of 48 bytes, so `toU16` keeps every length exactly.
|
|
241
|
+
const out: u8[] = new Array<u8>(toU16(length))
|
|
224
242
|
const counter: u8[] = new Array<u8>(1)
|
|
225
243
|
const counterLength: i32 = 1
|
|
226
244
|
let previous: u8[] = []
|
|
227
245
|
let at: i32 = 0
|
|
228
|
-
|
|
246
|
+
// At most 255, so the byte below is the counter itself.
|
|
247
|
+
let i: u32 = 1
|
|
229
248
|
while (at < length) {
|
|
230
249
|
const mac = new HmacSha384(prk)
|
|
231
250
|
mac.update(previous, HKDF_FROM, toI32(previous.length))
|
|
232
251
|
mac.update(info, HKDF_FROM, toI32(info.length))
|
|
233
|
-
counter
|
|
252
|
+
if (toI32(counter.length) >= 1) {
|
|
253
|
+
counter[0] = toU8(i)
|
|
254
|
+
}
|
|
234
255
|
mac.update(counter, HKDF_FROM, counterLength)
|
|
235
256
|
const block: u8[] = mac.digest()
|
|
236
257
|
wipe(previous)
|
|
@@ -411,22 +432,18 @@ const hkdfLabel = (caller: string, label: string, context: u8[], length: i32): u
|
|
|
411
432
|
const full: string = `${HKDF_LABEL_PREFIX}${label}`
|
|
412
433
|
const fullLength: i32 = toI32(full.length)
|
|
413
434
|
const contextLength: i32 = toI32(context.length)
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
out[
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
out[3 + k] = toU8(toI32(full.charCodeAt(k)))
|
|
427
|
-
}
|
|
428
|
-
out[3 + fullLength] = toU8(contextLength)
|
|
429
|
-
hkdfAppend(out, 4 + fullLength, context)
|
|
435
|
+
// At most 4 + 255 + 255 bytes after the tests above, so the `u32` sum is
|
|
436
|
+
// exact and `toU16` keeps it.
|
|
437
|
+
const out: u8[] = new Array<u8>(toU16(toU32(fullLength) + toU32(contextLength) + 4))
|
|
438
|
+
let p: i32 = hkdfPut(out, 0, toU8(length >> 8))
|
|
439
|
+
p = hkdfPut(out, p, toU8(length & 0xff))
|
|
440
|
+
p = hkdfPut(out, p, toU8(fullLength))
|
|
441
|
+
for (let k: i32 = 0; k < fullLength && p >= 0 && p < toI32(out.length); k += 1) {
|
|
442
|
+
out[p] = toU8(toI32(full.charCodeAt(k)))
|
|
443
|
+
p += 1
|
|
444
|
+
}
|
|
445
|
+
p = hkdfPut(out, p, toU8(contextLength))
|
|
446
|
+
hkdfAppend(out, p, context)
|
|
430
447
|
return out
|
|
431
448
|
}
|
|
432
449
|
|
|
@@ -637,6 +654,15 @@ const hkdfMacUpdate = (s: HkdfScratch, hashLength: i32, data: u8[], off: i32, le
|
|
|
637
654
|
}
|
|
638
655
|
}
|
|
639
656
|
|
|
657
|
+
/** Feeds the whole of `data`, at any length, to the scratch's HMAC for `hashLength`. */
|
|
658
|
+
const hkdfMacUpdateAll = (s: HkdfScratch, hashLength: i32, data: u8[]): void => {
|
|
659
|
+
if (hashLength === SHA384_SIZE) {
|
|
660
|
+
s.sha384.inner.engine.absorbAll(data)
|
|
661
|
+
} else {
|
|
662
|
+
s.sha256.inner.updateAll(data)
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
640
666
|
/** Writes the HMAC for `hashLength`'s tag at `out[at]`. */
|
|
641
667
|
const hkdfMacFinish = (s: HkdfScratch, hashLength: i32, out: u8[], at: i32): void => {
|
|
642
668
|
if (hashLength === SHA384_SIZE) {
|
|
@@ -650,8 +676,8 @@ const hkdfMacFinish = (s: HkdfScratch, hashLength: i32, out: u8[], at: i32): voi
|
|
|
650
676
|
* HKDF-Extract (RFC 5869 §2.2) over the hash `hashLength` names, the PRK's
|
|
651
677
|
* HashLen bytes written at `out[at]`. An empty `salt` keys HMAC with no bytes,
|
|
652
678
|
* which HMAC pads to the block with zeros, exactly as the HashLen zeros §2.2
|
|
653
|
-
* asks for would be.
|
|
654
|
-
* `hmacSha256`
|
|
679
|
+
* asks for would be. The whole `ikm` is hashed, at any length, as
|
|
680
|
+
* `hmacSha256` hashes its message.
|
|
655
681
|
*
|
|
656
682
|
* @param s The scratch to compute in; what the call leaves in it is wiped.
|
|
657
683
|
* @param hashLength 32 for HMAC-SHA-256, 48 for HMAC-SHA-384.
|
|
@@ -671,11 +697,8 @@ export const hkdfExtractInto = (
|
|
|
671
697
|
): void => {
|
|
672
698
|
hkdfCheckHash("hkdfExtractInto", hashLength)
|
|
673
699
|
hkdfCheckOutput("hkdfExtractInto", out, at, hashLength)
|
|
674
|
-
if (ikm.length > 2147483647) {
|
|
675
|
-
panic("hkdfExtractInto: input keying material longer than 2^31 - 1 bytes")
|
|
676
|
-
}
|
|
677
700
|
hkdfMacBegin(s, hashLength, salt, HKDF_FROM, toI32(salt.length))
|
|
678
|
-
|
|
701
|
+
hkdfMacUpdateAll(s, hashLength, ikm)
|
|
679
702
|
hkdfMacFinish(s, hashLength, out, at)
|
|
680
703
|
hkdfWipe(s, hashLength)
|
|
681
704
|
}
|
|
@@ -696,19 +719,30 @@ const hkdfExpandWindow = (
|
|
|
696
719
|
length: i32
|
|
697
720
|
): void => {
|
|
698
721
|
const counterLength: i32 = 1
|
|
722
|
+
// `p` runs through the window `out[at .. at + length)`; the bounds on it in
|
|
723
|
+
// the loops only let the prover see what the callers checked. The counter is
|
|
724
|
+
// a `u32`, which wraps rather than overflows; it never passes 255.
|
|
725
|
+
let p: i32 = at
|
|
699
726
|
let done: i32 = 0
|
|
700
|
-
let i:
|
|
701
|
-
while (done < length) {
|
|
727
|
+
let i: u32 = 1
|
|
728
|
+
while (done < length && p >= 0 && p < toI32(out.length)) {
|
|
702
729
|
hkdfMacBegin(s, hashLength, prk, HKDF_FROM, toI32(prk.length))
|
|
703
730
|
if (i > 1) {
|
|
704
731
|
hkdfMacUpdate(s, hashLength, s.previous, HKDF_FROM, hashLength)
|
|
705
732
|
}
|
|
706
733
|
hkdfMacUpdate(s, hashLength, info, HKDF_FROM, infoLen)
|
|
707
|
-
s.counter
|
|
734
|
+
if (toI32(s.counter.length) >= 1) {
|
|
735
|
+
s.counter[0] = toU8(i)
|
|
736
|
+
}
|
|
708
737
|
hkdfMacUpdate(s, hashLength, s.counter, HKDF_FROM, counterLength)
|
|
709
738
|
hkdfMacFinish(s, hashLength, s.previous, HKDF_FROM)
|
|
710
|
-
for (
|
|
711
|
-
|
|
739
|
+
for (
|
|
740
|
+
let k: i32 = 0;
|
|
741
|
+
k < hashLength && done < length && p >= 0 && p < toI32(out.length) && k < toI32(s.previous.length);
|
|
742
|
+
k += 1
|
|
743
|
+
) {
|
|
744
|
+
out[p] = s.previous[k]
|
|
745
|
+
p += 1
|
|
712
746
|
done += 1
|
|
713
747
|
}
|
|
714
748
|
i += 1
|
|
@@ -747,7 +781,7 @@ export const hkdfExpandInto = (
|
|
|
747
781
|
hkdfCheckHash("hkdfExpandInto", hashLength)
|
|
748
782
|
if (
|
|
749
783
|
length < 0 ||
|
|
750
|
-
length > HKDF_MAX_BLOCKS *
|
|
784
|
+
length > (hashLength === SHA384_SIZE ? HKDF_MAX_BLOCKS * SHA384_SIZE : HKDF_MAX_BLOCKS * SHA256_SIZE) ||
|
|
751
785
|
info.length > 2147483647 ||
|
|
752
786
|
toI32(prk.length) < hashLength
|
|
753
787
|
) {
|
|
@@ -800,8 +834,8 @@ export const hkdfExpandLabelInto = (
|
|
|
800
834
|
if (
|
|
801
835
|
contextOff < 0 ||
|
|
802
836
|
contextLen < 0 ||
|
|
803
|
-
|
|
804
|
-
|
|
837
|
+
contextLen > 255 ||
|
|
838
|
+
contextOff > toI32(context.length) - contextLen
|
|
805
839
|
) {
|
|
806
840
|
panic("hkdfExpandLabelInto: the context window is outside its array or longer than 255 bytes")
|
|
807
841
|
}
|
|
@@ -809,26 +843,36 @@ export const hkdfExpandLabelInto = (
|
|
|
809
843
|
panic("hkdfExpandLabelInto: a secret shorter than HashLen")
|
|
810
844
|
}
|
|
811
845
|
hkdfCheckOutput("hkdfExpandLabelInto", out, at, length)
|
|
812
|
-
// The `HkdfLabel` struct, as `hkdfLabel` builds it, into the scratch
|
|
813
|
-
|
|
846
|
+
// The `HkdfLabel` struct, as `hkdfLabel` builds it, into the scratch, whose
|
|
847
|
+
// HKDF_LABEL_MAX bytes hold the longest one the tests above let through.
|
|
848
|
+
const prefix: string = HKDF_LABEL_PREFIX
|
|
849
|
+
const prefixLength: i32 = toI32(prefix.length)
|
|
814
850
|
const labelLength: i32 = toI32(label.length)
|
|
815
|
-
const fullLength: i32 = prefixLength + labelLength
|
|
816
851
|
const info: u8[] = s.label
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
852
|
+
const infoLength: i32 = toI32(info.length)
|
|
853
|
+
let p: i32 = hkdfPut(info, 0, toU8(length >> 8))
|
|
854
|
+
p = hkdfPut(info, p, toU8(length & 0xff))
|
|
855
|
+
p = hkdfPut(info, p, toU8(toU32(prefixLength) + toU32(labelLength)))
|
|
856
|
+
for (let k: i32 = 0; k < prefixLength && p >= 0 && p < infoLength; k += 1) {
|
|
857
|
+
info[p] = toU8(toI32(prefix.charCodeAt(k)))
|
|
858
|
+
p += 1
|
|
859
|
+
}
|
|
860
|
+
for (let k: i32 = 0; k < labelLength && p >= 0 && p < infoLength; k += 1) {
|
|
861
|
+
info[p] = toU8(toI32(label.charCodeAt(k)))
|
|
862
|
+
p += 1
|
|
863
|
+
}
|
|
864
|
+
p = hkdfPut(info, p, toU8(contextLen))
|
|
865
|
+
let q: i32 = contextOff
|
|
866
|
+
for (
|
|
867
|
+
let k: i32 = 0;
|
|
868
|
+
k < contextLen && q >= 0 && q < toI32(context.length) && p >= 0 && p < infoLength;
|
|
869
|
+
k += 1
|
|
870
|
+
) {
|
|
871
|
+
info[p] = context[q]
|
|
872
|
+
p += 1
|
|
873
|
+
q += 1
|
|
830
874
|
}
|
|
831
|
-
hkdfExpandWindow(s, hashLength, prk, info,
|
|
875
|
+
hkdfExpandWindow(s, hashLength, prk, info, p, out, at, length)
|
|
832
876
|
}
|
|
833
877
|
|
|
834
878
|
// ---- From and into a held `Secret` -----------------------------------------
|
|
@@ -868,7 +912,7 @@ const hkdfHeldDerive = (
|
|
|
868
912
|
: exposeWith(prk, request, hkdfExpandSha384Exposed)
|
|
869
913
|
if (okm === null) {
|
|
870
914
|
panic(
|
|
871
|
-
`${caller}: a secret shorter than ${hashLength} bytes, or more than ${
|
|
915
|
+
`${caller}: a secret shorter than ${hashLength} bytes, or more than ${toU32(hashLength) * 255} bytes asked`
|
|
872
916
|
)
|
|
873
917
|
}
|
|
874
918
|
return okm
|
|
@@ -965,8 +1009,6 @@ export const hkdfExpandLabelHeldInto = (
|
|
|
965
1009
|
): void => {
|
|
966
1010
|
hkdfCheckOutput("hkdfExpandLabelHeldInto", out, at, length)
|
|
967
1011
|
const okm: u8[] = hkdfHeldDerive("hkdfExpandLabelHeldInto", hashLength, prk, label, context, length)
|
|
968
|
-
|
|
969
|
-
out[at + k] = okm[k]
|
|
970
|
-
}
|
|
1012
|
+
hkdfAppend(out, at, okm)
|
|
971
1013
|
wipe(okm)
|
|
972
1014
|
}
|