| ... | @@ -613,13 +613,14 @@ const Date = struct { | ... | @@ -613,13 +613,14 @@ const Date = struct { |
| 613 | } | 613 | } |
| 614 | }; | 614 | }; |
| 615 | | 615 | |
| 616 | pub fn parseTimeDigits(nn: @Vector(2, u8), min: u8, max: u8) !u8 { | 616 | pub fn parseTimeDigits(nn_u8: @Vector(2, u8), min: u8, max: u8) !u8 { |
| 617 | const zero: @Vector(2, u8) = .{ '0', '0' }; | 617 | const nn: @Vector(2, u16) = .{ nn_u8[0], nn_u8[1] }; |
| 618 | const mm: @Vector(2, u8) = .{ 10, 1 }; | 618 | const zero: @Vector(2, u16) = .{ '0', '0' }; |
| | 619 | const mm: @Vector(2, u16) = .{ 10, 1 }; |
| 619 | const result = @reduce(.Add, (nn -% zero) *% mm); | 620 | const result = @reduce(.Add, (nn -% zero) *% mm); |
| 620 | if (result < min) return error.CertificateTimeInvalid; | 621 | if (result < min) return error.CertificateTimeInvalid; |
| 621 | if (result > max) return error.CertificateTimeInvalid; | 622 | if (result > max) return error.CertificateTimeInvalid; |
| 622 | return result; | 623 | return @truncate(result); |
| 623 | } | 624 | } |
| 624 | | 625 | |
| 625 | test parseTimeDigits { | 626 | test parseTimeDigits { |
| ... | @@ -631,15 +632,16 @@ test parseTimeDigits { | ... | @@ -631,15 +632,16 @@ test parseTimeDigits { |
| 631 | const expectError = std.testing.expectError; | 632 | const expectError = std.testing.expectError; |
| 632 | try expectError(error.CertificateTimeInvalid, parseTimeDigits("13".*, 1, 12)); | 633 | try expectError(error.CertificateTimeInvalid, parseTimeDigits("13".*, 1, 12)); |
| 633 | try expectError(error.CertificateTimeInvalid, parseTimeDigits("00".*, 1, 12)); | 634 | try expectError(error.CertificateTimeInvalid, parseTimeDigits("00".*, 1, 12)); |
| | 635 | try expectError(error.CertificateTimeInvalid, parseTimeDigits("Di".*, 0, 99)); |
| 634 | } | 636 | } |
| 635 | | 637 | |
| 636 | pub fn parseYear4(text: *const [4]u8) !u16 { | 638 | pub fn parseYear4(text: *const [4]u8) !u16 { |
| 637 | const nnnn: @Vector(4, u16) = .{ text[0], text[1], text[2], text[3] }; | 639 | const nnnn: @Vector(4, u32) = .{ text[0], text[1], text[2], text[3] }; |
| 638 | const zero: @Vector(4, u16) = .{ '0', '0', '0', '0' }; | 640 | const zero: @Vector(4, u32) = .{ '0', '0', '0', '0' }; |
| 639 | const mmmm: @Vector(4, u16) = .{ 1000, 100, 10, 1 }; | 641 | const mmmm: @Vector(4, u32) = .{ 1000, 100, 10, 1 }; |
| 640 | const result = @reduce(.Add, (nnnn -% zero) *% mmmm); | 642 | const result = @reduce(.Add, (nnnn -% zero) *% mmmm); |
| 641 | if (result > 9999) return error.CertificateTimeInvalid; | 643 | if (result > 9999) return error.CertificateTimeInvalid; |
| 642 | return result; | 644 | return @truncate(result); |
| 643 | } | 645 | } |
| 644 | | 646 | |
| 645 | test parseYear4 { | 647 | test parseYear4 { |
| ... | @@ -651,6 +653,7 @@ test parseYear4 { | ... | @@ -651,6 +653,7 @@ test parseYear4 { |
| 651 | const expectError = std.testing.expectError; | 653 | const expectError = std.testing.expectError; |
| 652 | try expectError(error.CertificateTimeInvalid, parseYear4("999b")); | 654 | try expectError(error.CertificateTimeInvalid, parseYear4("999b")); |
| 653 | try expectError(error.CertificateTimeInvalid, parseYear4("crap")); | 655 | try expectError(error.CertificateTimeInvalid, parseYear4("crap")); |
| | 656 | try expectError(error.CertificateTimeInvalid, parseYear4("r:bQ")); |
| 654 | } | 657 | } |
| 655 | | 658 | |
| 656 | pub fn parseAlgorithm(bytes: []const u8, element: der.Element) ParseEnumError!Algorithm { | 659 | pub fn parseAlgorithm(bytes: []const u8, element: der.Element) ParseEnumError!Algorithm { |