feat: add rust stdnum core#130
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new Rust workspace containing standard identifier validation libraries (stella-stdnum-core, stella-stdnum-napi, and stella-stdnum-py) with native bindings for Node.js and Python. Feedback on the core validation library focuses on fixing critical correctness bugs in CNPJ character mapping and Czech special DIC checksums, resolving a potential compilation error with is_multiple_of in a const fn, and improving robustness for Spanish DNI length variations. Additionally, safety and performance improvements are suggested, such as using strip_suffix to avoid risky manual slicing, optimizing string operations to reduce heap allocations, and consolidating multi-pass string checks into a single pass.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c602fde6a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 614ac70ef7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (v.length < 2 || v.length > 9) { | ||
| return err( | ||
| "INVALID_LENGTH", | ||
| "DNI must be 8 digits and 1 letter", | ||
| "DNI must be 1-8 digits and 1 letter", |
There was a problem hiding this comment.
Update DNI discovery metadata for short numbers
After this change, es.dni.validate("1234567L") succeeds, but callers using the patterns API still will not find that value: toRegex() infers DNI length from the single 8-digit example and no lengths metadata, so it builds a 9-character pattern and toRegex(es.dni).test("1234567L") is false. If 1-7 digit DNIs are now valid inputs, the validator metadata/pattern coverage needs to be widened with the validation change, otherwise extraction workflows silently miss newly valid DNIs.
Useful? React with 👍 / 👎.
965a008 to
b4949ec
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b4949ece89
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| affiliate.saturating_add(province.saturating_mul(10_000_000)) | ||
| } else { | ||
| province | ||
| .saturating_mul(100_000_000) |
There was a problem hiding this comment.
Use a wider NSS base before modulo
For Spanish NSS values with province 43-52 and an affiliate number at least 10,000,000, the concatenated base exceeds u32::MAX; for example 493961665403 needs base 4,939,616,654, but this u32 arithmetic saturates before % 97, so the native validator rejects an ID accepted by src/es/nss.ts. Compute the base in u64 or reduce modulo 97 without saturating.
Useful? React with 👍 / 👎.
| let month = d2.saturating_mul(10).saturating_add(d3); | ||
| let yy = d4.saturating_mul(10).saturating_add(d5); | ||
| let year = dk_cpr_century(yy, d6).saturating_add(yy); | ||
| valid_date(year, month, day) |
There was a problem hiding this comment.
When the CPR serial head maps the year into the 2000s, this only checks that the date exists, so future birth dates are accepted; as of 2026-06-25, 3112575000 resolves to 2057-12-31 and returns true here, while src/dk/cpr.ts rejects future birth dates. Native callers will therefore treat not-yet-assignable Danish personal IDs as valid.
Useful? React with 👍 / 👎.
Summary
stella-stdnum-coreboolean validation for the identifier set needed by native consumersValidation
bun run rust:fmt:checkbun run rust:lintbun run rust:testbun run format:checkbun run typecheckbun run lintbun test