From 914668c622b60eab4129d0a6b3776c20d8e614bd Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 9 Oct 2018 09:12:04 +0200 Subject: Fix checksum check. --- libdevcore/CommonData.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libdevcore/CommonData.cpp') diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 445d11cd..6d7c74d7 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -76,18 +76,18 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw) bool dev::passesAddressChecksum(string const& _str, bool _strict) { - string s = _str.substr(0, 2) == "0x" ? _str.substr(2) : _str; + string s = _str.substr(0, 2) == "0x" ? _str : "0x" + _str; - if (s.length() != 40) + if (s.length() != 42) return false; if (!_strict && ( - _str.find_first_of("abcdef") == string::npos || - _str.find_first_of("ABCDEF") == string::npos + s.find_first_of("abcdef") == string::npos || + s.find_first_of("ABCDEF") == string::npos )) return true; - return _str == dev::getChecksummedAddress(_str); + return s == dev::getChecksummedAddress(s); } string dev::getChecksummedAddress(string const& _addr) -- cgit v1.2.3 From e78b95d9d4ecb6d8d56ca0f04a6f9b4f7d974fbb Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 18 Oct 2018 13:35:20 +0200 Subject: Renamed SHA3.{h,cpp} files. --- libdevcore/CommonData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdevcore/CommonData.cpp') diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 6d7c74d7..cb79fa98 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include -- cgit v1.2.3 From 19be6cd818e4bb1a49325d8bfea7f7727d85c933 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 16 Oct 2018 17:58:17 +0200 Subject: Some well-formedness checks for the Yul AST. --- libdevcore/CommonData.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libdevcore/CommonData.cpp') diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 6d7c74d7..fa1a5353 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -110,3 +110,26 @@ string dev::getChecksummedAddress(string const& _addr) } return ret; } + +bool dev::isValidHex(string const& _string) +{ + if (_string.substr(0, 2) != "0x") + return false; + if (_string.find_first_not_of("0123456789abcdefABCDEF", 2) != string::npos) + return false; + return true; +} + +bool dev::isValidDecimal(string const& _string) +{ + if (_string.empty()) + return false; + if (_string == "0") + return true; + // No leading zeros + if (_string.front() == '0') + return false; + if (_string.find_first_not_of("0123456789") != string::npos) + return false; + return true; +} -- cgit v1.2.3 From ab0de38f16a9eff13ee5a32a3408b890d87941f6 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 7 Nov 2018 12:04:46 +0100 Subject: Eliminate `byte`-typedef and use `uint8_t` in all their places instead. This change is made to (easily) be forward compatible with future C++ standards, in order to allow compiling the code with newer standards at some point in the future. * Removed the `using byte = uint8_t;` line from Common.h * Mechanically change all uses of `byte` to `uint8_t`. Tested with GCC 7.3 in C++11/14/17 modes :-) --- libdevcore/CommonData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdevcore/CommonData.cpp') diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index fa1a5353..91c60ffe 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -64,7 +64,7 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw) int h = fromHex(_s[i], WhenError::DontThrow); int l = fromHex(_s[i + 1], WhenError::DontThrow); if (h != -1 && l != -1) - ret.push_back((byte)(h * 16 + l)); + ret.push_back((uint8_t)(h * 16 + l)); else if (_throw == WhenError::Throw) BOOST_THROW_EXCEPTION(BadHexCharacter()); else -- cgit v1.2.3