From c522e5f4c22b53b349b05486fa28cdf58f4ffc26 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 14 Nov 2024 00:13:18 +0100 Subject: Core/Misc: Support IPv6 ip2location --- src/common/Cryptography/BigNumber.cpp | 6 ++++++ src/common/Cryptography/BigNumber.h | 2 ++ 2 files changed, 8 insertions(+) (limited to 'src/common/Cryptography') diff --git a/src/common/Cryptography/BigNumber.cpp b/src/common/Cryptography/BigNumber.cpp index f220ca319be..66071006a7f 100644 --- a/src/common/Cryptography/BigNumber.cpp +++ b/src/common/Cryptography/BigNumber.cpp @@ -61,6 +61,12 @@ void BigNumber::SetBinary(uint8 const* bytes, int32 len, bool littleEndian) BN_bin2bn(bytes, len, _bn); } +bool BigNumber::SetDecStr(char const* str) +{ + int n = BN_dec2bn(&_bn, str); + return n > 0; +} + bool BigNumber::SetHexStr(char const* str) { int n = BN_hex2bn(&_bn, str); diff --git a/src/common/Cryptography/BigNumber.h b/src/common/Cryptography/BigNumber.h index 3ec6cc65590..3815339d9cf 100644 --- a/src/common/Cryptography/BigNumber.h +++ b/src/common/Cryptography/BigNumber.h @@ -46,6 +46,8 @@ class TC_COMMON_API BigNumber void SetBinary(uint8 const* bytes, int32 len, bool littleEndian = true); template auto SetBinary(Container const& c, bool littleEndian = true) -> std::enable_if_t>> { SetBinary(std::data(c), std::size(c), littleEndian); } + bool SetDecStr(char const* str); + bool SetDecStr(std::string const& str) { return SetDecStr(str.c_str()); } bool SetHexStr(char const* str); bool SetHexStr(std::string const& str) { return SetHexStr(str.c_str()); } -- cgit v1.2.3