mirror of
https://github.com/shadps4-emu/ext-cryptopp.git
synced 2024-11-26 19:30:21 +00:00
Add specialization for SafeConvert
This commit is contained in:
parent
dced966b7a
commit
df86e69902
50
misc.h
50
misc.h
@ -707,7 +707,9 @@ template <class T1, class T2> inline const T1 UnsignedMin(const T1& a, const T2&
|
||||
/// \tparam T2 class or type
|
||||
/// \param from the first value
|
||||
/// \param to the second value
|
||||
/// \return true if its safe to convert from into to, false otherwise.
|
||||
/// \return true if its safe to convert \p from to \p to, false otherwise.
|
||||
/// \details if the function returns true, then it is safe to use \p to. If the function returns false,
|
||||
/// then \p to is undefined and should not be used.
|
||||
template <class T1, class T2>
|
||||
inline bool SafeConvert(T1 from, T2 &to)
|
||||
{
|
||||
@ -717,6 +719,52 @@ inline bool SafeConvert(T1 from, T2 &to)
|
||||
return true;
|
||||
}
|
||||
|
||||
/// \brief Tests whether a conversion from -> to is safe to perform
|
||||
/// \param from the first value
|
||||
/// \param to the second value
|
||||
/// \return true if its safe to convert \p from to \p to, false otherwise.
|
||||
/// \details if the function returns true, then it is safe to use \p to. If the function returns false,
|
||||
/// then \p to is undefined and should not be used.
|
||||
/// \since Crypto++ 8.7
|
||||
template<>
|
||||
inline bool SafeConvert(word32 from, word64 &to)
|
||||
{
|
||||
to = static_cast<word64>(from);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// \brief Tests whether a conversion from -> to is safe to perform
|
||||
/// \param from the first value
|
||||
/// \param to the second value
|
||||
/// \return true if its safe to convert \p from to \p to, false otherwise.
|
||||
/// \details if the function returns true, then it is safe to use \p to. If the function returns false,
|
||||
/// then \p to is undefined and should not be used.
|
||||
/// \since Crypto++ 8.7
|
||||
template<>
|
||||
inline bool SafeConvert(word64 from, sword64 &to)
|
||||
{
|
||||
if (from > static_cast<word64>(std::numeric_limits<sword64>::max()))
|
||||
return false;
|
||||
to = static_cast<sword64>(from);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// \brief Tests whether a conversion from -> to is safe to perform
|
||||
/// \param from the first value
|
||||
/// \param to the second value
|
||||
/// \return true if its safe to convert \p from to \p to, false otherwise.
|
||||
/// \details if the function returns true, then it is safe to use \p to. If the function returns false,
|
||||
/// then \p to is undefined and should not be used.
|
||||
/// \since Crypto++ 8.7
|
||||
template<>
|
||||
inline bool SafeConvert(sword64 from, word64 &to)
|
||||
{
|
||||
if (from < 0)
|
||||
return false;
|
||||
to = static_cast<sword64>(from);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// \brief Converts a value to a string
|
||||
/// \tparam T class or type
|
||||
/// \param value the value to convert
|
||||
|
Loading…
Reference in New Issue
Block a user