Skip to content

Add input validation and refactor ResponseApdu#23

Merged
tomkp merged 1 commit intomasterfrom
fix/response-apdu-validation-refactor
Dec 28, 2025
Merged

Add input validation and refactor ResponseApdu#23
tomkp merged 1 commit intomasterfrom
fix/response-apdu-validation-refactor

Conversation

@tomkp
Copy link
Copy Markdown
Owner

@tomkp tomkp commented Dec 28, 2025

Summary

  • Add input validation for buffer length
  • Extract duplicate hex slicing into helper methods
  • Optimize status code matching with pre-compiled RegExp array
  • Expand status code definitions

Changes

  • Validation: Throw error if buffer has less than 2 bytes
  • Refactor: Extract getSW1() and getSW2() private helper methods
  • Performance: Convert status codes from Record<string, string> to Array<[RegExp, string]> with pre-compiled patterns
  • Status codes: Add specific meanings for common codes (6a82, 6300, 69xx, etc.)
  • Tests: Add 6 new tests for constructor validation and status codes

Test plan

  • All 30 tests pass
  • ESLint passes
  • Prettier formatting applied

Fixes #22

- Add validation to throw error if buffer has less than 2 bytes
- Extract getSW1() and getSW2() private helper methods
- Convert status codes from Record<string, string> to Array<[RegExp, string]>
- Use for...of with pre-compiled regex patterns for efficiency
- Add more specific status code meanings (6a82, 6300, 69xx, etc.)
- Order status codes from most specific to least specific
- Add comprehensive tests for constructor validation and status codes

Fixes #22
@tomkp tomkp merged commit 50e1e16 into master Dec 28, 2025
3 checks passed
@tomkp tomkp deleted the fix/response-apdu-validation-refactor branch December 28, 2025 14:39
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.

Add input validation and refactor hex slicing in ResponseApdu

1 participant