From 35aad180195430ed73987f4cab267359ca34400a Mon Sep 17 00:00:00 2001 From: Simon Sawert Date: Tue, 16 Jun 2020 18:25:38 +0200 Subject: [PATCH] Ensure serial is not 000 --- src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 75180d2..bc6cdb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,9 +137,10 @@ impl Personnummer { self.date.month(), self.date.day() ); + let to_control = format!("{:06}{:03}", ymd, self.serial); - luhn(to_control) == self.control + self.serial > 0 && luhn(to_control) == self.control } /// Return the age of the person holding the personal identity number. The dates used for the @@ -211,7 +212,12 @@ mod tests { #[test] fn test_valid_date_invalid_digits() { - let cases = vec!["19900101-1111", "20160229-1111", "6403273814"]; + let cases = vec![ + "19900101-1111", + "20160229-1111", + "6403273814", + "20150916-0006", + ]; for tc in cases { assert!(!Personnummer::new(tc).valid());