Skip to content

perry-stdlib: split crypto.rs and webcrypto.rs into per-algorithm submodules #1435

Description

@TheHypnoo

Background

crates/perry-stdlib/src/crypto.rs (4997 lines) and crates/perry-stdlib/src/webcrypto.rs (2809 lines) grew past the 2000-line limit while #1419 expanded the node:crypto parity surface. Both are currently allowlisted in scripts/check_file_size.sh so CI passes.

crates/perry-hir/src/ir/expr.rs (2009 lines) also crossed the boundary; this is the Expr enum + the walker trait implementations, and the PR added the WebCrypto variants.

Goal

Move these out of the allowlist by following the chore/split-large-files pattern (v0.5.1019/v0.5.1020 commits).

perry-stdlib/src/crypto.rs

Split into per-algorithm-family submodules:

  • crypto/hash.rsHash / Hmac (already partly factored as HashState / HmacState).
  • crypto/cipher.rsCipherHandle, AES-CBC / GCM / KW.
  • crypto/sign.rsSignHandle, RSA-PKCS#1 v1.5 / RSA-PSS.
  • crypto/ecdh.rsEcdhHandle, ECDH P-256, X25519.
  • crypto/dh.rsDiffieHellmanHandle.
  • crypto/kdf.rs — PBKDF2, scrypt, HKDF.
  • crypto/random.rs — randomBytes, randomInt, randomUUID, randomFill.
  • crypto/keys.rs — createSecretKey, generateKeySync, generateKeyPairSync, KeyObject helpers.
  • crypto/prime.rs — generatePrime, checkPrime.
  • crypto/util.rsbytes_from_ptr, alloc_buffer_from_slice, encoding helpers.

perry-stdlib/src/webcrypto.rs

Same shape but for subtle.*:

  • webcrypto/digest.rs, webcrypto/hmac.rs, webcrypto/aes.rs, webcrypto/ec.rs, webcrypto/rsa.rs, webcrypto/kdf.rs, webcrypto/wrap.rs, webcrypto/jwk.rs, webcrypto/util.rs.

perry-hir/src/ir/expr.rs

Variants are alphabetized today. Could split by surface family: expr/cryptographic.rs, expr/string.rs, etc. Higher risk because the walker traits need symmetric updates; consider doing this last.

Validation

After each split:

  • cargo build --release --workspace clean.
  • cargo test --release --workspace --exclude perry-ui-* passes.
  • ./run_parity_tests.sh 100% on the touched module.
  • Remove the corresponding line from scripts/check_file_size.sh ALLOWLIST.

Tracked under #793. Pattern reference: commits on chore/split-large-files for compile.rs and entries.rs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions