@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/net/oidc.ts
CHANGED
|
@@ -242,9 +242,11 @@ export class OidcKeySet {
|
|
|
242
242
|
* @returns The key, or null when no key has that `kid`.
|
|
243
243
|
*/
|
|
244
244
|
find(kid: string): JwtKey | null {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
const keys: JwtKey[] = this.keys
|
|
246
|
+
const kids: string[] = this.kids
|
|
247
|
+
for (let i: i32 = 0; i < toI32(keys.length) && i < toI32(kids.length); i += 1) {
|
|
248
|
+
if (kid !== "" && kids[i] === kid) {
|
|
249
|
+
return keys[i]
|
|
248
250
|
}
|
|
249
251
|
}
|
|
250
252
|
return null
|
|
@@ -298,7 +300,7 @@ export const oidcIssuerAllowed = (issuer: string, options: OidcOptions): boolean
|
|
|
298
300
|
* @returns The discovery URL.
|
|
299
301
|
*/
|
|
300
302
|
export const oidcDiscoveryUrl = (issuer: string): string => {
|
|
301
|
-
const base: string = issuer.endsWith("/") ? issuer.
|
|
303
|
+
const base: string = issuer.endsWith("/") ? issuer.substring(0, toI32(issuer.length) - 1) : issuer
|
|
302
304
|
return `${base}${OIDC_WELL_KNOWN}`
|
|
303
305
|
}
|
|
304
306
|
|
|
@@ -716,8 +718,9 @@ export const oidcParseJwks = (doc: u8[]): OidcKeySet => {
|
|
|
716
718
|
}
|
|
717
719
|
const key: JwtKey | null = entry.key
|
|
718
720
|
if (key !== null) {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
+
const kids: string[] = set.kids
|
|
722
|
+
for (let j: i32 = 0; j < toI32(kids.length); j += 1) {
|
|
723
|
+
if (kids[j] === entry.kid) {
|
|
721
724
|
return oidcRefused(OIDC_ERR_DUPLICATE_KID)
|
|
722
725
|
}
|
|
723
726
|
}
|
|
@@ -734,26 +737,33 @@ export const oidcParseJwks = (doc: u8[]): OidcKeySet => {
|
|
|
734
737
|
/** The seconds of one `max-age=<digits>` directive, or -1 when `directive` is not one. */
|
|
735
738
|
const oidcMaxAge = (directive: string): i64 => {
|
|
736
739
|
const eq: i32 = toI32(directive.indexOf(String.fromCharCode(OIDC_CH_EQUALS)))
|
|
737
|
-
|
|
740
|
+
const end: i32 = toI32(directive.length)
|
|
741
|
+
if (eq < 1 || eq >= end || asciiLower(trim(directive.substring(0, eq))) !== "max-age") {
|
|
738
742
|
return toI64(-1)
|
|
739
743
|
}
|
|
740
|
-
const value: string = trim(directive.
|
|
744
|
+
const value: string = trim(directive.substring(eq + 1, end))
|
|
741
745
|
const n: i32 = toI32(value.length)
|
|
742
746
|
if (n < 1) {
|
|
743
747
|
return toI64(-1)
|
|
744
748
|
}
|
|
745
|
-
let age:
|
|
749
|
+
let age: i32 = 0
|
|
746
750
|
for (let i: i32 = 0; i < n; i += 1) {
|
|
747
751
|
const c: i32 = toI32(value.charCodeAt(i))
|
|
748
752
|
if (c < OIDC_CH_0 || c > OIDC_CH_9) {
|
|
749
753
|
return toI64(-1)
|
|
750
754
|
}
|
|
751
|
-
// Saturate rather than overflow (RFC 9111 §1.2.2): the clamp caps it
|
|
752
|
-
|
|
753
|
-
|
|
755
|
+
// Saturate rather than overflow (RFC 9111 §1.2.2): the clamp caps it
|
|
756
|
+
// anyway. 86400 is `OIDC_MAX_LIFETIME`, written as an `i32` the bound
|
|
757
|
+
// proofs read.
|
|
758
|
+
let d: i32 = 0
|
|
759
|
+
if (c >= OIDC_CH_0 && c <= OIDC_CH_9) {
|
|
760
|
+
d = c - OIDC_CH_0
|
|
761
|
+
}
|
|
762
|
+
if (age >= 0 && age <= 86400 && d >= 0 && d <= 9) {
|
|
763
|
+
age = age * 10 + d
|
|
754
764
|
}
|
|
755
765
|
}
|
|
756
|
-
return age
|
|
766
|
+
return toI64(age)
|
|
757
767
|
}
|
|
758
768
|
|
|
759
769
|
/**
|
|
@@ -770,23 +780,50 @@ export const oidcLifetime = (cacheControl: string | null): i64 => {
|
|
|
770
780
|
if (cacheControl === null) {
|
|
771
781
|
return OIDC_DEFAULT_LIFETIME
|
|
772
782
|
}
|
|
773
|
-
const n: i32 = toI32(cacheControl.length)
|
|
774
783
|
let from: i32 = 0
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
784
|
+
const text: string = cacheControl
|
|
785
|
+
for (let i: i32 = 0; i >= 0 && i < toI32(text.length); i += 1) {
|
|
786
|
+
if (toI32(text.charCodeAt(i)) === OIDC_CH_COMMA && from >= 0 && from <= toI32(text.length)) {
|
|
787
|
+
const age: i64 = oidcMaxAge(trim(text.substring(from, i)))
|
|
778
788
|
if (age >= toI64(0)) {
|
|
779
|
-
|
|
780
|
-
return OIDC_MIN_LIFETIME
|
|
781
|
-
}
|
|
782
|
-
return age > OIDC_MAX_LIFETIME ? OIDC_MAX_LIFETIME : age
|
|
789
|
+
return oidcClamp(age)
|
|
783
790
|
}
|
|
784
791
|
from = i + 1
|
|
785
792
|
}
|
|
786
793
|
}
|
|
794
|
+
const n: i32 = toI32(text.length)
|
|
795
|
+
if (from >= 0 && from <= n) {
|
|
796
|
+
const last: i64 = oidcMaxAge(trim(text.substring(from, n)))
|
|
797
|
+
if (last >= toI64(0)) {
|
|
798
|
+
return oidcClamp(last)
|
|
799
|
+
}
|
|
800
|
+
}
|
|
787
801
|
return OIDC_DEFAULT_LIFETIME
|
|
788
802
|
}
|
|
789
803
|
|
|
804
|
+
/** `n` zero bytes, or none when `n` is negative. */
|
|
805
|
+
const oidcZeroes = (n: i32): u8[] => {
|
|
806
|
+
if (n < 0) {
|
|
807
|
+
return []
|
|
808
|
+
}
|
|
809
|
+
if (n <= 65535) {
|
|
810
|
+
return new Array<u8>(toU16(n))
|
|
811
|
+
}
|
|
812
|
+
const out: u8[] = new Array<u8>(65535)
|
|
813
|
+
for (let k: i32 = 65535; k < n; k += 1) {
|
|
814
|
+
out.push(0)
|
|
815
|
+
}
|
|
816
|
+
return out
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** A `max-age` of `age` seconds, clamped to `[OIDC_MIN_LIFETIME, OIDC_MAX_LIFETIME]`. */
|
|
820
|
+
const oidcClamp = (age: i64): i64 => {
|
|
821
|
+
if (age < OIDC_MIN_LIFETIME) {
|
|
822
|
+
return OIDC_MIN_LIFETIME
|
|
823
|
+
}
|
|
824
|
+
return age > OIDC_MAX_LIFETIME ? OIDC_MAX_LIFETIME : age
|
|
825
|
+
}
|
|
826
|
+
|
|
790
827
|
/**
|
|
791
828
|
* An issuer's rotating key set, and a verifier for its tokens. One thread's,
|
|
792
829
|
* like the `JwtVerifier` it holds.
|
|
@@ -843,7 +880,8 @@ export class OidcKeys {
|
|
|
843
880
|
this.hardUntil = toI64(0)
|
|
844
881
|
this.triedAt = toI64(0)
|
|
845
882
|
this.verifier = new JwtVerifier(options.maxToken)
|
|
846
|
-
|
|
883
|
+
// A negative `maxToken` holds no token: `load` refuses every one.
|
|
884
|
+
this.text = oidcZeroes(options.maxToken)
|
|
847
885
|
this.kidBytes = new Array<u8>(OIDC_MAX_KID)
|
|
848
886
|
}
|
|
849
887
|
|
|
@@ -1093,10 +1131,11 @@ const oidcPick = (keys: OidcKeys, token: string, audience: string, now: i64): i3
|
|
|
1093
1131
|
const kid: string | null = keys.peekKid(n)
|
|
1094
1132
|
let key: JwtKey | null = null
|
|
1095
1133
|
if (kid === null) {
|
|
1096
|
-
|
|
1134
|
+
const only: JwtKey[] = set.keys
|
|
1135
|
+
if (toI32(only.length) !== 1) {
|
|
1097
1136
|
return OIDC_ERR_KID_REQUIRED
|
|
1098
1137
|
}
|
|
1099
|
-
key =
|
|
1138
|
+
key = only[0]
|
|
1100
1139
|
} else {
|
|
1101
1140
|
key = keys.key(kid, now)
|
|
1102
1141
|
}
|