Commit 7766d42
committed
feat(security): replace Record<string, any> getUIntOption with typed helper
The previous getUIntOption signature defeated the type checker:
function getUIntOption(options: Record<string, any>, key: string)
`any` everywhere meant the value extracted by `options[key]` was typed
as `any` and passed to the cipher constructor with zero validation
beyond the cryptic `value >>> 0 !== value` check. The function also
returned `-1` as a sentinel for "missing", forcing every caller into
the awkward `getUIntOption(...) !== -1 ? getUIntOption(...) : default`
pattern (which double-evaluates).
Replace with a typed helper:
- Input: `Readonly<Record<string, unknown>> | undefined` — narrows from
`any` to `unknown`, requiring runtime checks before use.
- Return: `number | undefined` — the missing case is type-encoded.
- Validation: explicit `Number.isFinite/Integer + range [0, 2^32-1]`
with a typed `RangeError` and a descriptive message.
The single call site collapses from a 4-line conditional to:
const authTagLen = getUIntOption(options, 'authTagLength') ?? 16;
Adds 4 regression tests covering negative, NaN, fractional, and
missing-defaults-to-16 paths.
Phase 1.4 of plans/todo/security-audit.md.1 parent 73ea9f3 commit 7766d42
3 files changed
Lines changed: 81 additions & 12 deletions
File tree
- example/src/tests/cipher
- packages/react-native-quick-crypto/src
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
58 | 80 | | |
59 | | - | |
| 81 | + | |
60 | 82 | | |
0 commit comments