@@ -568,7 +568,7 @@ impl SimpleAsn1Writable for UniversalString<'_> {
568568 }
569569}
570570
571- fn validate_integer ( data : & [ u8 ] , signed : bool ) -> ParseResult < ( ) > {
571+ const fn validate_integer ( data : & [ u8 ] , signed : bool ) -> ParseResult < ( ) > {
572572 if data. is_empty ( ) {
573573 return Err ( ParseError :: new ( ParseErrorKind :: InvalidValue ) ) ;
574574 }
@@ -656,9 +656,11 @@ impl<'a> BigUint<'a> {
656656 /// as required by DER: minimally and if the high bit would be set in the
657657 /// first octet, a leading `\x00` should be prepended (to disambiguate from
658658 /// negative values).
659- pub fn new ( data : & ' a [ u8 ] ) -> Option < Self > {
660- validate_integer ( data, false ) . ok ( ) ?;
661- Some ( BigUint { data } )
659+ pub const fn new ( data : & ' a [ u8 ] ) -> Option < Self > {
660+ match validate_integer ( data, false ) {
661+ Ok ( ( ) ) => Some ( BigUint { data } ) ,
662+ Err ( _) => None ,
663+ }
662664 }
663665
664666 /// Returns the contents of the integer as big-endian bytes.
@@ -731,9 +733,11 @@ impl<'a> BigInt<'a> {
731733 /// as required by DER: minimally and if the high bit would be set in the
732734 /// first octet, a leading `\x00` should be prepended (to disambiguate from
733735 /// negative values).
734- pub fn new ( data : & ' a [ u8 ] ) -> Option < Self > {
735- validate_integer ( data, true ) . ok ( ) ?;
736- Some ( BigInt { data } )
736+ pub const fn new ( data : & ' a [ u8 ] ) -> Option < Self > {
737+ match validate_integer ( data, true ) {
738+ Ok ( ( ) ) => Some ( BigInt { data } ) ,
739+ Err ( _) => None ,
740+ }
737741 }
738742
739743 /// Returns the contents of the integer as big-endian bytes.
@@ -874,7 +878,7 @@ fn read_4_digits(data: &mut &[u8]) -> ParseResult<u16> {
874878 + u16:: from ( read_digit ( data) ?) )
875879}
876880
877- fn validate_date ( year : u16 , month : u8 , day : u8 ) -> ParseResult < ( ) > {
881+ const fn validate_date ( year : u16 , month : u8 , day : u8 ) -> ParseResult < ( ) > {
878882 if day < 1 {
879883 return Err ( ParseError :: new ( ParseErrorKind :: InvalidValue ) ) ;
880884 }
@@ -934,26 +938,28 @@ pub struct DateTime {
934938}
935939
936940impl DateTime {
937- pub fn new (
941+ pub const fn new (
938942 year : u16 ,
939943 month : u8 ,
940944 day : u8 ,
941945 hour : u8 ,
942946 minute : u8 ,
943947 second : u8 ,
944948 ) -> ParseResult < DateTime > {
945- validate_date ( year, month, day) ?;
946949 if hour > 23 || minute > 59 || second > 59 {
947950 return Err ( ParseError :: new ( ParseErrorKind :: InvalidValue ) ) ;
948951 }
949- Ok ( DateTime {
950- year,
951- month,
952- day,
953- hour,
954- minute,
955- second,
956- } )
952+ match validate_date ( year, month, day) {
953+ Ok ( ( ) ) => Ok ( DateTime {
954+ year,
955+ month,
956+ day,
957+ hour,
958+ minute,
959+ second,
960+ } ) ,
961+ Err ( e) => Err ( e) ,
962+ }
957963 }
958964
959965 /// The calendar year.
0 commit comments