@@ -425,6 +425,7 @@ impl<const NUM_LIMBS: usize> UnsignedInteger<NUM_LIMBS> {
425
425
/// Creates an `UnsignedInteger` from a hexstring. It can contain `0x` or not.
426
426
/// Returns an `CreationError::InvalidHexString`if the value is not a hexstring.
427
427
/// Returns a `CreationError::EmptyString` if the input string is empty.
428
+ /// Returns a `CreationError::HexStringIsTooBig` if the the imput hex string is bigger than the maximum amount of characters for this element.
428
429
pub fn from_hex ( value : & str ) -> Result < Self , CreationError > {
429
430
let mut string = value;
430
431
let mut char_iterator = value. chars ( ) ;
@@ -447,7 +448,7 @@ impl<const NUM_LIMBS: usize> UnsignedInteger<NUM_LIMBS> {
447
448
if string. len ( ) > max_amount_of_hex_chars {
448
449
return Err ( CreationError :: HexStringIsTooBig ) ;
449
450
}
450
-
451
+
451
452
Ok ( Self :: from_hex_unchecked ( string) )
452
453
}
453
454
@@ -1258,12 +1259,15 @@ mod tests_u384 {
1258
1259
fn from_hex_with_overflowing_hexstring_should_error ( ) {
1259
1260
let u256_from_big_string = U256 :: from_hex ( & "f" . repeat ( 65 ) ) ;
1260
1261
assert ! ( u256_from_big_string. is_err( ) ) ;
1261
- assert ! ( u256_from_big_string == Err ( crate :: unsigned_integer:: element:: CreationError :: HexStringIsTooBig ) ) ;
1262
+ assert ! (
1263
+ u256_from_big_string
1264
+ == Err ( crate :: unsigned_integer:: element:: CreationError :: HexStringIsTooBig )
1265
+ ) ;
1262
1266
}
1263
1267
1264
1268
#[ test]
1265
1269
fn from_hex_with_non_overflowing_hexstring_should_work ( ) {
1266
- assert_eq ! ( U256 :: from_hex( & "0" . repeat( 64 ) ) . unwrap( ) . limbs, [ 0 , 0 , 0 , 0 ] )
1270
+ assert_eq ! ( U256 :: from_hex( & "0" . repeat( 64 ) ) . unwrap( ) . limbs, [ 0 , 0 , 0 , 0 ] )
1267
1271
}
1268
1272
1269
1273
#[ test]
0 commit comments