Skip to content

Commit

Permalink
Separate domestic and foreign RRN validators
Browse files Browse the repository at this point in the history
Signed-off-by: Sunghyun Hwang <[email protected]>
  • Loading branch information
0xd669 committed Dec 7, 2018
1 parent b3bdff9 commit a31b6a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
26 changes: 20 additions & 6 deletions rrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ def _validate_hash(rrn: str) -> bool:
return True


def _is_valid_domestic_rrn(rrn: str) -> bool:
return (
rrn.isdigit() and
_validate_birth(rrn) and
_validate_location(rrn) and
_validate_hash(rrn)
)


def _is_valid_foreign_rrn(rrn: str) -> bool:
return (
rrn.isdigit() and
_validate_birth(rrn)
)


def is_valid_rrn(rrn: str) -> bool:
"""
Validate given RRN and returns if it might be valid or not.
Expand All @@ -81,12 +97,10 @@ def is_valid_rrn(rrn: str) -> bool:
"""
try:
rrn = HYPHEN.sub('', rrn)
return (
rrn.isdigit() and
_validate_birth(rrn) and
_validate_location(rrn) and
_validate_hash(rrn)
)
if is_foreign(rrn):
return _is_valid_foreign_rrn(rrn)
else:
return _is_valid_domestic_rrn(rrn)
except TypeError:
return False

Expand Down
6 changes: 5 additions & 1 deletion tests/test_rrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def test_is_valid_rrn(self):
('9408121001751', valid),
('9408121001750', invalid),
('9408221001740', valid),
('9408221001741', invalid)
('9408221001741', invalid),
('9408225', valid),
('940822699', valid),
('940822700888', valid),
('9408228008889', valid)
]:
self.assertEqual(expected, rrn.is_valid_rrn(s))

Expand Down

0 comments on commit a31b6a5

Please sign in to comment.