mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 05:52:46 +00:00 
			
		
		
		
	LibCrypto: Make constructing a BigInteger from string fallible
Previously, constructing a `UnsignedBigInteger::from_base()` could produce an incorrect result if the input string contained a valid Base36 digit that was out of range of the given base. The same method would also crash if the input string contained an invalid Base36 digit. An error is now returned in both these cases. Constructing a BigFraction from string is now also fallible, so that we can handle the case where we are given an input string with invalid digits.
This commit is contained in:
		
							parent
							
								
									0b0c7693e2
								
							
						
					
					
						commit
						48a3a02238
					
				
					 11 changed files with 68 additions and 57 deletions
				
			
		|  | @ -273,12 +273,12 @@ Bytecode::CodeGenerationErrorOr<void> BigIntLiteral::generate_bytecode(Bytecode: | |||
|     auto integer = [&] { | ||||
|         if (m_value[0] == '0' && m_value.length() >= 3) | ||||
|             if (m_value[1] == 'x' || m_value[1] == 'X') | ||||
|                 return Crypto::SignedBigInteger::from_base(16, m_value.substring(2, m_value.length() - 3)); | ||||
|                 return MUST(Crypto::SignedBigInteger::from_base(16, m_value.substring(2, m_value.length() - 3))); | ||||
|         if (m_value[1] == 'o' || m_value[1] == 'O') | ||||
|             return Crypto::SignedBigInteger::from_base(8, m_value.substring(2, m_value.length() - 3)); | ||||
|             return MUST(Crypto::SignedBigInteger::from_base(8, m_value.substring(2, m_value.length() - 3))); | ||||
|         if (m_value[1] == 'b' || m_value[1] == 'B') | ||||
|             return Crypto::SignedBigInteger::from_base(2, m_value.substring(2, m_value.length() - 3)); | ||||
|         return Crypto::SignedBigInteger::from_base(10, m_value.substring(0, m_value.length() - 1)); | ||||
|             return MUST(Crypto::SignedBigInteger::from_base(2, m_value.substring(2, m_value.length() - 3))); | ||||
|         return MUST(Crypto::SignedBigInteger::from_base(10, m_value.substring(0, m_value.length() - 1))); | ||||
|     }(); | ||||
| 
 | ||||
|     generator.emit<Bytecode::Op::NewBigInt>(integer); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tim Ledbetter
						Tim Ledbetter