@amritk/nish-x86_64-linux 0.18.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.
Files changed (59) hide show
  1. package/INSTALL.md +43 -25
  2. package/bin/nish +0 -0
  3. package/package.json +2 -2
  4. package/runtime/nish.d.ts +55 -5
  5. package/runtime/nish.h +215 -18
  6. package/runtime/nish.mjs +16 -0
  7. package/runtime/runtime-aes.c +490 -0
  8. package/runtime/runtime-cross.c +366 -0
  9. package/runtime/runtime-host.c +7 -6
  10. package/runtime/runtime-net.c +93 -34
  11. package/runtime/runtime-os.c +213 -15
  12. package/runtime/runtime-parallel.c +590 -107
  13. package/runtime/runtime-simd.c +4 -4
  14. package/runtime/runtime-wasm.c +5 -3
  15. package/runtime/runtime.c +69 -13
  16. package/runtime/shim.mjs +71 -1
  17. package/scripts/build.sh +223 -22
  18. package/std/README.md +81 -51
  19. package/std/bytes.ts +163 -0
  20. package/std/crypto/LICENSE-libsecp256k1 +19 -0
  21. package/std/crypto/aes.ts +238 -76
  22. package/std/crypto/chacha20poly1305.ts +43 -9
  23. package/std/crypto/ed25519.ts +840 -0
  24. package/std/crypto/hkdf.ts +304 -12
  25. package/std/crypto/hmac.ts +245 -53
  26. package/std/crypto/p256.ts +932 -61
  27. package/std/crypto/x25519.ts +55 -37
  28. package/std/crypto/x509-random.ts +71 -0
  29. package/std/crypto/x509.ts +9 -9
  30. package/std/json-tokenizer.ts +1296 -0
  31. package/std/json-typed.ts +1014 -0
  32. package/std/json-value.ts +1163 -0
  33. package/std/json.ts +1120 -34
  34. package/std/net/buffer-pool.ts +151 -0
  35. package/std/net/hpack.ts +416 -112
  36. package/std/net/http-fields.ts +93 -0
  37. package/std/net/http1-server.ts +417 -55
  38. package/std/net/http1.ts +31 -6
  39. package/std/net/http2-tls.ts +112 -24
  40. package/std/net/http2.ts +333 -75
  41. package/std/net/http3-server.ts +211 -31
  42. package/std/net/http3.ts +187 -28
  43. package/std/net/prefork.ts +412 -0
  44. package/std/net/quic-listener.ts +88 -7
  45. package/std/net/quic-packet.ts +243 -82
  46. package/std/net/quic-recovery.ts +361 -30
  47. package/std/net/quic-stream.ts +424 -24
  48. package/std/net/quic.ts +519 -167
  49. package/std/net/router.ts +676 -0
  50. package/std/net/tls/codec.ts +426 -27
  51. package/std/net/tls/record-server.ts +478 -132
  52. package/std/net/tls/record.ts +133 -42
  53. package/std/net/tls/schedule.ts +464 -55
  54. package/std/net/tls/ticket.ts +610 -0
  55. package/std/net/tls-tcp.ts +196 -53
  56. package/std/net/tls.ts +1018 -260
  57. package/std/net/url.ts +571 -0
  58. package/std/random.ts +94 -0
  59. package/std/threads.ts +438 -14
@@ -50,6 +50,11 @@
50
50
  * that disagree (`HTTP_FIELDS_BAD_CONTENT_LENGTH`). Matching it against
51
51
  * the body is the version's job, since only it sees the body.
52
52
  *
53
+ * **The date.** `httpDateWrite` writes a second since 1970 as an IMF-fixdate
54
+ * (RFC 9110 §5.6.7), `Fri, 16 Oct 2026 08:11:54 GMT`, the form every version's
55
+ * `Date` field takes. It reads no clock, so a wasm32 build can import it; the
56
+ * caller supplies the second.
57
+ *
53
58
  * Names and values are octets (`u8[]`), as HPACK and QPACK answer them. A
54
59
  * section that passes keeps references to the caller's arrays, not copies, so
55
60
  * it is valid for as long as they are.
@@ -602,3 +607,91 @@ export class HttpFields {
602
607
  return seen < 0 ? seen : HTTP_FIELDS_OK
603
608
  }
604
609
  }
610
+
611
+ // ---- The date ------------------------------------------------------------------
612
+
613
+ /** An IMF-fixdate's length: `Sun, 06 Nov 1994 08:49:37 GMT` (RFC 9110 §5.6.7). */
614
+ export const HTTP_DATE_SIZE: i32 = 29
615
+
616
+ /** The last second an IMF-fixdate can name, 9999-12-31T23:59:59Z, in seconds since 1970. */
617
+ export const HTTP_DATE_LAST_SECOND: i64 = 253402300799
618
+
619
+ /** The day names from Sunday, then the month names from January, three letters each. */
620
+ const HTTP_FIELDS_DATE_NAMES: string = "SunMonTueWedThuFriSatJanFebMarAprMayJunJulAugSepOctNovDec"
621
+
622
+ /** Writes the three letters at `HTTP_FIELDS_DATE_NAMES[3 * index ..)` at `out[at ..)`. */
623
+ const httpFieldsPutName = (out: u8[], at: i32, index: i32): void => {
624
+ for (let k: i32 = 0; k < 3; k++) {
625
+ out[at + k] = toU8(HTTP_FIELDS_DATE_NAMES.charCodeAt(3 * index + k))
626
+ }
627
+ }
628
+
629
+ /** Writes `n`, 0 to 99, as two digits at `out[at ..)`. */
630
+ const httpFieldsPutTwo = (out: u8[], at: i32, n: i32): void => {
631
+ const tens: i32 = n / 10
632
+ const ones: i32 = n % 10
633
+ out[at] = toU8(48 + tens)
634
+ out[at + 1] = toU8(48 + ones)
635
+ }
636
+
637
+ /**
638
+ * Writes the IMF-fixdate of `seconds` since 1970-01-01T00:00:00Z at
639
+ * `out[at .. at + HTTP_DATE_SIZE)` and answers where it ends; -1, with nothing
640
+ * written, for a second before 1970 or after `HTTP_DATE_LAST_SECOND`, whose
641
+ * year has no four digits, or for an `out` without the room. It reads no
642
+ * clock, so it compiles for wasm32 too: `HttpDate` in `nish/net/http1-server`
643
+ * is the cache that reads one and calls this at most once a second.
644
+ *
645
+ * The date follows Howard Hinnant's `civil_from_days` ("chrono-Compatible
646
+ * Low-Level Date Algorithms"), step for step and with its constants, which
647
+ * its author donated to the public domain: days are counted from 0000-03-01,
648
+ * so a leap day is the last day of its year and a 400-year era is always
649
+ * 146,097 days long. Every step
650
+ * is `i64` arithmetic on numbers that are not negative, so `--number-mode
651
+ * f64` writes the same bytes.
652
+ */
653
+ export const httpDateWrite = (out: u8[], at: i32, seconds: i64): i32 => {
654
+ if (
655
+ seconds < 0 ||
656
+ seconds > HTTP_DATE_LAST_SECOND ||
657
+ at < 0 ||
658
+ toI64(at) + toI64(HTTP_DATE_SIZE) > toI64(out.length)
659
+ ) {
660
+ return -1
661
+ }
662
+ const days: i64 = seconds / 86400
663
+ const inDay: i32 = toI32(seconds - days * 86400)
664
+ // 1970-01-01 was a Thursday, and 0 is Sunday.
665
+ const weekday: i32 = toI32((days + 4) % 7)
666
+ // From 0000-03-01 to 1970-01-01 is 719,468 days.
667
+ const z: i64 = days + 719468
668
+ const era: i64 = z / 146097
669
+ const dayOfEra: i64 = z - era * 146097
670
+ const yearOfEra: i64 = (dayOfEra - dayOfEra / 1460 + dayOfEra / 36524 - dayOfEra / 146096) / 365
671
+ const dayOfYear: i64 = dayOfEra - (365 * yearOfEra + yearOfEra / 4 - yearOfEra / 100)
672
+ // Months from March, each 30 or 31 days by the 153-day rule.
673
+ const marchMonth: i64 = (5 * dayOfYear + 2) / 153
674
+ const day: i32 = toI32(dayOfYear - (153 * marchMonth + 2) / 5 + 1)
675
+ const month: i32 = toI32(marchMonth < 10 ? marchMonth + 3 : marchMonth - 9)
676
+ const year: i32 = toI32(yearOfEra + era * 400) + (month <= 2 ? 1 : 0)
677
+ httpFieldsPutName(out, at, weekday)
678
+ out[at + 3] = 44
679
+ out[at + 4] = 32
680
+ httpFieldsPutTwo(out, at + 5, day)
681
+ out[at + 7] = 32
682
+ httpFieldsPutName(out, at + 8, 6 + month)
683
+ out[at + 11] = 32
684
+ httpFieldsPutTwo(out, at + 12, year / 100)
685
+ httpFieldsPutTwo(out, at + 14, year % 100)
686
+ out[at + 16] = 32
687
+ httpFieldsPutTwo(out, at + 17, inDay / 3600)
688
+ out[at + 19] = 58
689
+ httpFieldsPutTwo(out, at + 20, (inDay / 60) % 60)
690
+ out[at + 22] = 58
691
+ httpFieldsPutTwo(out, at + 23, inDay % 60)
692
+ out[at + 25] = 32
693
+ out[at + 26] = 71
694
+ out[at + 27] = 77
695
+ out[at + 28] = 84
696
+ return at + HTTP_DATE_SIZE
697
+ }