Skip to content

feat(zlib/crypto): zlib.constants + subtle.generateKey (AES-GCM)#955

Merged
proggeramlug merged 1 commit into
mainfrom
zlib-constants-subtle-generatekey
May 17, 2026
Merged

feat(zlib/crypto): zlib.constants + subtle.generateKey (AES-GCM)#955
proggeramlug merged 1 commit into
mainfrom
zlib-constants-subtle-generatekey

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

Moves the two compilePackages smoke targets from #952 past their next compile gates by adding two same-family manifest entries + runtime bindings:

  • zlib.constants — the ~50 Z_* / flush / return-code / DEFLATE/INFLATE/GZIP/BROTLI_*/ZSTD_* table Node exposes on require('node:zlib').constants. Routed through the existing crypto.constants / os.constants sub-namespace plumbing in get_native_module_constant (perry-runtime/src/object.rs). Required by axios for stream wiring.
  • crypto.subtle.generateKey(algorithm, extractable, keyUsages) — initial AES-GCM coverage (128 / 256 bit; 192-bit explicitly rejected to mirror the existing encrypt/decrypt path keyed on aes-gcm 0.10's Aes128Gcm/Aes256Gcm type set). New Expr::WebCryptoGenerateKey variant + HIR lowering + codegen + runtime extern. The returned CryptoKey is registered with (AesGcm, Sha256) so the existing subtle.encrypt/decrypt paths round-trip on it. Required by jose's generateSecret('A256GCM').

Asymmetric algorithms (RSA / ECDSA / ECDH), wrapKey/unwrapKey, deriveKey, and HMAC keygen remain TODO follow-ups tracked alongside #561.

Bumps to v0.5.973.

Test plan

  • test-files/test_zlib_constants.ts reads 11 constants — output byte-matches node -e 'const z=require("node:zlib").constants; ...'.
  • test-files/test_crypto_subtle_generateKey.ts round-trips encrypt + decrypt on a freshly generated 256-bit AES-GCM key, asserts ciphertext-length-equals-plaintext-plus-16-byte-tag.
  • cargo test -p perry-codegen --tests manifest_consistency — all 4 drift guards pass.
  • cargo test -p perry-stdlib --lib webcrypto — all 9 webcrypto tests pass.
  • Axios repro (import axios from "axios"; perry main.ts -o out) advances past the zlib.constants gate — next gap is zlib.createBrotliDecompress, separate follow-up.
  • Jose repro (import * as jose from "jose"; perry main.ts -o out) advances past the subtle.generateKey gate — next gap is subtle.wrapKey, separate follow-up.
  • API docs regenerated via ./scripts/regen_api_docs.sh (zlib.constants added; manifest now 869 entries across 71 modules).

Moves axios + jose past the next `compilePackages` compile gates after

- `zlib.constants` — adds the ~50 `Z_*` / flush / return-code /
  `DEFLATE`/`INFLATE`/`GZIP`/`BROTLI_*`/`ZSTD_*` table Node ships on
  `require('node:zlib').constants`. Routed through the existing
  `crypto.constants` / `os.constants` sub-namespace plumbing in
  `get_native_module_constant`. Required by axios stream wiring.
- `crypto.subtle.generateKey(algorithm, extractable, keyUsages)` —
  initial AES-GCM coverage (128 / 256 bit; 192-bit rejected, mirroring
  the existing encrypt/decrypt path keyed on `aes-gcm` 0.10's
  `Aes128Gcm`/`Aes256Gcm` types). Returned CryptoKey is registered
  with `(AesGcm, Sha256)` so `subtle.encrypt`/`decrypt` round-trip on
  it. Required by jose's `generateSecret('A256GCM')`.

Asymmetric algorithms (RSA / ECDSA / ECDH), `wrapKey`/`unwrapKey`,
`deriveKey`, and HMAC keygen remain TODO follow-ups (jose's next
blocker is now `subtle.wrapKey`).

Regression tests:
- test-files/test_zlib_constants.ts — output byte-matches Node.
- test-files/test_crypto_subtle_generateKey.ts — round-trips
  encrypt + decrypt on the freshly generated key.
@proggeramlug proggeramlug force-pushed the zlib-constants-subtle-generatekey branch from f8bcba5 to f6f5293 Compare May 17, 2026 20:34
@proggeramlug proggeramlug merged commit d0b612f into main May 17, 2026
7 of 9 checks passed
@proggeramlug proggeramlug deleted the zlib-constants-subtle-generatekey branch May 17, 2026 20:34
proggeramlug added a commit that referenced this pull request May 17, 2026
Moves axios + jose past the next compilePackages compile gates after #955:

- `zlib.createBrotliDecompress(options?)` — axios feature-checks this at
  module init. Manifest entry + native shim in perry-stdlib's zlib module
  returns a registered Buffer-shaped handle (the typeof check is what
  axios needs; the real Brotli decode pipe only fires on
  `content-encoding: br` and is a TODO follow-up). Adds
  `brotli = "8.0.2"` under the compression feature.

- `crypto.subtle.wrapKey` / `unwrapKey` — full HIR/codegen/runtime path
  with AES-KW (RFC 3394 via `aes-kw = "0.3.0"`, 128/192/256-bit) and
  AES-GCM (reusing existing encrypt/decrypt helpers). The unwrapped
  CryptoKey is registered under the supplied `unwrappedKeyAlgorithm`
  (currently AES-GCM) so subsequent encrypt/decrypt round-trip on it.
  New HIR variants WebCryptoWrapKey / WebCryptoUnwrapKey with walker +
  stable-hash tags 470/471.

Regression tests:
- test-files/test_zlib_brotli_decompress.ts — feature-check pass.
- test-files/test_crypto_subtle_wrap_unwrap.ts — generate two AES-GCM
  keys, AES-GCM wrap the inner key with the KEK, unwrap, then decrypt a
  ciphertext made with the original to confirm bytes round-trip.

Bumps to v0.5.976.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant