From 38f9667e090492d0581a5f1a14a48504242ca28e Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Tue, 31 Jul 2018 16:18:00 +0200 Subject: Guard CycleDetector against recursion exhaustion. fixes #3935. --- libdevcore/Algorithms.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/Algorithms.h b/libdevcore/Algorithms.h index b2540668..7fe2472d 100644 --- a/libdevcore/Algorithms.h +++ b/libdevcore/Algorithms.h @@ -32,11 +32,13 @@ template class CycleDetector { public: + using Visitor = std::function; + /// Initializes the cycle detector /// @param _visit function that is given the current vertex /// and is supposed to call @a run on all /// adjacent vertices. - explicit CycleDetector(std::function _visit): + explicit CycleDetector(Visitor _visit): m_visit(std::move(_visit)) { } @@ -55,7 +57,7 @@ public: m_processing.insert(&_vertex); m_depth++; - m_visit(_vertex, *this); + m_visit(_vertex, *this, m_depth); m_depth--; if (m_firstCycleVertex && m_depth == 1) m_firstCycleVertex = &_vertex; @@ -66,7 +68,7 @@ public: } private: - std::function m_visit; + Visitor m_visit; std::set m_processing; std::set m_processed; size_t m_depth = 0; -- cgit v1.2.3 From 3705bcc9bc8c726a60c1eaa1d29cd1d240c0268a Mon Sep 17 00:00:00 2001 From: Evgeniy Filatov Date: Thu, 2 Aug 2018 17:57:16 +0300 Subject: added helper function that joins vectors of strings, refactored suggestions formattingi function to use it --- libdevcore/StringUtils.cpp | 14 ++++---------- libdevcore/StringUtils.h | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 10 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/StringUtils.cpp b/libdevcore/StringUtils.cpp index 2ff86bd5..01bdc675 100644 --- a/libdevcore/StringUtils.cpp +++ b/libdevcore/StringUtils.cpp @@ -85,17 +85,11 @@ size_t dev::stringDistance(string const& _str1, string const& _str2) string dev::quotedAlternativesList(vector const& suggestions) { - if (suggestions.empty()) - return ""; - if (suggestions.size() == 1) - return "\"" + suggestions.front() + "\""; + vector quotedSuggestions; - string choices = "\"" + suggestions.front() + "\""; - for (size_t i = 1; i + 1 < suggestions.size(); ++i) - choices += ", \"" + suggestions[i] + "\""; + for (auto& suggestion: suggestions) + quotedSuggestions.push_back("\"" + suggestion + "\""); - choices += " or \"" + suggestions.back() + "\""; - - return choices; + return joinHumanReadable(quotedSuggestions, ", ", " or "); } diff --git a/libdevcore/StringUtils.h b/libdevcore/StringUtils.h index acd93e32..4fb5a748 100644 --- a/libdevcore/StringUtils.h +++ b/libdevcore/StringUtils.h @@ -36,4 +36,43 @@ size_t stringDistance(std::string const& _str1, std::string const& _str2); // Return a string having elements of suggestions as quoted, alternative suggestions. e.g. "a", "b" or "c" std::string quotedAlternativesList(std::vector const& suggestions); +/// Joins collection of strings into one string with separators between, last separator can be different. +/// @param _list collection of strings to join +/// @param _separator defaults to ", " +/// @param _lastSeparator (optional) will be used to separate last two strings instead of _separator +/// @example join(vector{"a", "b", "c"}, "; ", " or ") == "a; b or c" +template +std::string joinHumanReadable +( + T const& _list, + std::string const& _separator = ", ", + std::string const& _lastSeparator = "" +) +{ + auto it = begin(_list); + auto itEnd = end(_list); + + std::string result; + + // append first string + if (it != itEnd) + { + result += *it; + ++it; + } + + for (;it != itEnd; ++it) + { + if ((next(it) == itEnd) && !_lastSeparator.empty()) + result += _lastSeparator; // last iteration + else + result += _separator; + + // append string + result += *it; + } + + return result; +} + } -- cgit v1.2.3 From 6c3b48ddfcfb0849e1083cea8d4fae4446511be1 Mon Sep 17 00:00:00 2001 From: "Augusto F. Hack" Date: Sat, 21 Jul 2018 19:08:47 -0300 Subject: Added guards for unknown pragmas Removed push/pop if there was no change to the warnings *in the same file* for a given compiler. This assumes the imported boost headers use a warning stack themselves. The pragmas don't seem to be required anymore, but were not removed to mantain compatibility with older versions of the boost library. Compiled with - clang version 6.0.1 (tags/RELEASE_601/final) - gcc (GCC) 8.1.1 20180531 against: - libboost 1.67.0-5 --- libdevcore/Common.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/Common.h b/libdevcore/Common.h index 2543855d..0363d9a2 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -40,7 +40,6 @@ #include #if defined(__GNUC__) -#pragma warning(push) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #endif // defined(__GNUC__) @@ -57,7 +56,6 @@ #include #if defined(__GNUC__) -#pragma warning(pop) #pragma GCC diagnostic pop #endif // defined(__GNUC__) -- cgit v1.2.3 From 3de0b8b7f002bdc76e629f89df73523b36a169f5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 27 Jun 2018 18:08:49 +0200 Subject: Move absolutePath/sanitizePath helpers from CompilerStack to libdevcore --- libdevcore/CommonIO.cpp | 20 ++++++++++++++++++++ libdevcore/CommonIO.h | 6 ++++++ 2 files changed, 26 insertions(+) (limited to 'libdevcore') diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 0063a8d4..9693d02a 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -187,3 +187,23 @@ boost::filesystem::path dev::weaklyCanonicalFilesystemPath(boost::filesystem::pa return head / tail; } } + +string dev::absolutePath(string const& _path, string const& _reference) +{ + boost::filesystem::path p(_path); + // Anything that does not start with `.` is an absolute path. + if (p.begin() == p.end() || (*p.begin() != "." && *p.begin() != "..")) + return _path; + boost::filesystem::path result(_reference); + result.remove_filename(); + for (boost::filesystem::path::iterator it = p.begin(); it != p.end(); ++it) + if (*it == "..") + result = result.parent_path(); + else if (*it != ".") + result /= *it; + return result.generic_string(); +} + +string dev::sanitizePath(string const& _path) { + return boost::filesystem::path(_path).generic_string(); +} diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h index 9ba68e74..928b6d15 100644 --- a/libdevcore/CommonIO.h +++ b/libdevcore/CommonIO.h @@ -62,4 +62,10 @@ std::string toString(_T const& _t) /// Should be replaced by the boost implementation as soon as support for boost<1.60 can be dropped. boost::filesystem::path weaklyCanonicalFilesystemPath(boost::filesystem::path const &_path); +/// @returns the absolute path corresponding to @a _path relative to @a _reference. +std::string absolutePath(std::string const& _path, std::string const& _reference); + +/// Helper function to return path converted strings. +std::string sanitizePath(std::string const& _path); + } -- cgit v1.2.3 From 7dae58cbcc3df64e6add31020a7f44de1b28b3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Aereal=20Ae=C3=B3n?= Date: Wed, 8 Aug 2018 03:55:43 -0300 Subject: Replace boost:lexical_cast for std::to_string. --- libdevcore/Exceptions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdevcore') diff --git a/libdevcore/Exceptions.cpp b/libdevcore/Exceptions.cpp index f204dbc2..c614aece 100644 --- a/libdevcore/Exceptions.cpp +++ b/libdevcore/Exceptions.cpp @@ -43,7 +43,7 @@ string Exception::lineInfo() const ret += *file; ret += ':'; if (line) - ret += boost::lexical_cast(*line); + ret += std::to_string(*line); return ret; } -- cgit v1.2.3 From e902ce1aa02dc5d19cc9dd231fa538646884826d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Aereal=20Ae=C3=B3n?= Date: Wed, 8 Aug 2018 11:26:30 -0300 Subject: Removing std:: from std::to_string and include for boost/lexical_cast --- libdevcore/Exceptions.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/Exceptions.cpp b/libdevcore/Exceptions.cpp index c614aece..97f03f6e 100644 --- a/libdevcore/Exceptions.cpp +++ b/libdevcore/Exceptions.cpp @@ -17,8 +17,6 @@ #include -#include - using namespace std; using namespace dev; @@ -43,7 +41,7 @@ string Exception::lineInfo() const ret += *file; ret += ':'; if (line) - ret += std::to_string(*line); + ret += to_string(*line); return ret; } -- cgit v1.2.3 From 7d9692c31d411a66ea194480bf3963cb97e2c257 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 9 Aug 2018 01:12:39 +0200 Subject: Explicitly use std::next to avoid boost version. --- libdevcore/StringUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdevcore') diff --git a/libdevcore/StringUtils.h b/libdevcore/StringUtils.h index 4fb5a748..94c6e3c5 100644 --- a/libdevcore/StringUtils.h +++ b/libdevcore/StringUtils.h @@ -63,7 +63,7 @@ std::string joinHumanReadable for (;it != itEnd; ++it) { - if ((next(it) == itEnd) && !_lastSeparator.empty()) + if ((std::next(it) == itEnd) && !_lastSeparator.empty()) result += _lastSeparator; // last iteration else result += _separator; -- cgit v1.2.3 From 14e116c1d57e1797e7206299d0fdfed2aa03cdf2 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Aug 2018 11:31:51 +0200 Subject: Make joinHumanReadable work for input iterators. --- libdevcore/StringUtils.h | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/StringUtils.h b/libdevcore/StringUtils.h index 94c6e3c5..f05a426b 100644 --- a/libdevcore/StringUtils.h +++ b/libdevcore/StringUtils.h @@ -49,27 +49,23 @@ std::string joinHumanReadable std::string const& _lastSeparator = "" ) { - auto it = begin(_list); - auto itEnd = end(_list); + auto const itEnd = end(_list); std::string result; - // append first string - if (it != itEnd) + for (auto it = begin(_list); it != itEnd; ) { - result += *it; + std::string element = *it; + bool first = (it == begin(_list)); ++it; - } - - for (;it != itEnd; ++it) - { - if ((std::next(it) == itEnd) && !_lastSeparator.empty()) - result += _lastSeparator; // last iteration - else - result += _separator; - - // append string - result += *it; + if (!first) + { + if (it == itEnd && !_lastSeparator.empty()) + result += _lastSeparator; // last iteration + else + result += _separator; + } + result += std::move(element); } return result; -- cgit v1.2.3 From 3fa8829845bf55df812f81356a3ec43149836bb5 Mon Sep 17 00:00:00 2001 From: bakaoh Date: Fri, 10 Aug 2018 17:31:19 +0700 Subject: Fixes #4718: High CPU usage when using large variable names --- libdevcore/StringUtils.cpp | 5 ++++- libdevcore/StringUtils.h | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/StringUtils.cpp b/libdevcore/StringUtils.cpp index 01bdc675..50bf7cce 100644 --- a/libdevcore/StringUtils.cpp +++ b/libdevcore/StringUtils.cpp @@ -29,13 +29,16 @@ using namespace std; using namespace dev; -bool dev::stringWithinDistance(string const& _str1, string const& _str2, size_t _maxDistance) +bool dev::stringWithinDistance(string const& _str1, string const& _str2, size_t _maxDistance, size_t _lenThreshold) { if (_str1 == _str2) return true; size_t n1 = _str1.size(); size_t n2 = _str2.size(); + if (_lenThreshold > 0 && n1 * n2 > _lenThreshold) + return false; + size_t distance = stringDistance(_str1, _str2); // if distance is not greater than _maxDistance, and distance is strictly less than length of both names, they can be considered similar diff --git a/libdevcore/StringUtils.h b/libdevcore/StringUtils.h index f05a426b..b02b9d12 100644 --- a/libdevcore/StringUtils.h +++ b/libdevcore/StringUtils.h @@ -30,7 +30,8 @@ namespace dev { // Calculates the Damerau–Levenshtein distance between _str1 and _str2 and returns true if that distance is not greater than _maxDistance -bool stringWithinDistance(std::string const& _str1, std::string const& _str2, size_t _maxDistance); +// if _lenThreshold > 0 and the product of the strings length is greater than _lenThreshold, the function will return false +bool stringWithinDistance(std::string const& _str1, std::string const& _str2, size_t _maxDistance, size_t _lenThreshold = 0); // Calculates the Damerau–Levenshtein distance between _str1 and _str2 size_t stringDistance(std::string const& _str1, std::string const& _str2); // Return a string having elements of suggestions as quoted, alternative suggestions. e.g. "a", "b" or "c" -- cgit v1.2.3 From a102f3b783dec236e9a733f5a5338efce3ef8319 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 3 Sep 2018 15:01:15 +0200 Subject: Remove trailing whitespace for all files in the repository. --- libdevcore/Exceptions.cpp | 2 +- ...ultiprecision_number_compare_bug_workaround.hpp | 68 +++++++++++----------- 2 files changed, 35 insertions(+), 35 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/Exceptions.cpp b/libdevcore/Exceptions.cpp index 97f03f6e..cff5abf4 100644 --- a/libdevcore/Exceptions.cpp +++ b/libdevcore/Exceptions.cpp @@ -25,7 +25,7 @@ char const* Exception::what() const noexcept // Return the comment if available. if (string const* cmt = comment()) return cmt->data(); - + // Fallback to base what(). // Boost accepts nullptr, but the C++ standard doesn't // and crashes on some platforms. diff --git a/libdevcore/boost_multiprecision_number_compare_bug_workaround.hpp b/libdevcore/boost_multiprecision_number_compare_bug_workaround.hpp index dae591df..2568e17d 100644 --- a/libdevcore/boost_multiprecision_number_compare_bug_workaround.hpp +++ b/libdevcore/boost_multiprecision_number_compare_bug_workaround.hpp @@ -1,8 +1,8 @@ -// This is a copy of boost/multiprecision/detail/number_compare.hpp from boost 1.59 to replace buggy version from 1.58. +// This is a copy of boost/multiprecision/detail/number_compare.hpp from boost 1.59 to replace buggy version from 1.58. #ifdef BOOST_MP_COMPARE_HPP -#error This bug workaround header must be included before original boost/multiprecision/detail/number_compare.hpp +#error This bug workaround header must be included before original boost/multiprecision/detail/number_compare.hpp #endif /////////////////////////////////////////////////////////////////////////////// @@ -150,11 +150,11 @@ template struct is_valid_mixed_compare, number > : public mpl::false_ {}; template -struct is_valid_mixed_compare, expression > +struct is_valid_mixed_compare, expression > : public mpl::bool_, number >::value> {}; template -struct is_valid_mixed_compare, number > +struct is_valid_mixed_compare, number > : public mpl::bool_, number >::value> {}; template @@ -196,7 +196,7 @@ inline bool operator == (const number& a, const nu return eval_eq(a.backend(), b.backend()); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator == (const number& a, const Arithmetic& b) { using default_ops::eval_eq; @@ -204,7 +204,7 @@ inline typename enable_if_c::canonical_value(b)); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator == (const Arithmetic& a, const number& b) { using default_ops::eval_eq; @@ -212,7 +212,7 @@ inline typename enable_if_c::canonical_value(a)); } template -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator == (const Arithmetic& a, const detail::expression& b) { typedef typename detail::expression::result_type result_type; @@ -222,7 +222,7 @@ inline typename enable_if_c -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator == (const detail::expression& a, const Arithmetic& b) { typedef typename detail::expression::result_type result_type; @@ -232,7 +232,7 @@ inline typename enable_if_c -inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type +inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type operator == (const detail::expression& a, const detail::expression& b) { using default_ops::eval_eq; @@ -250,7 +250,7 @@ inline bool operator != (const number& a, const nu return !eval_eq(a.backend(), b.backend()); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator != (const number& a, const Arithmetic& b) { using default_ops::eval_eq; @@ -258,7 +258,7 @@ inline typename enable_if_c::canonical_value(b)); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator != (const Arithmetic& a, const number& b) { using default_ops::eval_eq; @@ -266,7 +266,7 @@ inline typename enable_if_c::canonical_value(a)); } template -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator != (const Arithmetic& a, const detail::expression& b) { typedef typename detail::expression::result_type result_type; @@ -276,7 +276,7 @@ inline typename enable_if_c -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator != (const detail::expression& a, const Arithmetic& b) { typedef typename detail::expression::result_type result_type; @@ -286,7 +286,7 @@ inline typename enable_if_c -inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type +inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type operator != (const detail::expression& a, const detail::expression& b) { using default_ops::eval_eq; @@ -304,7 +304,7 @@ inline bool operator < (const number& a, const num return eval_lt(a.backend(), b.backend()); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator < (const number& a, const Arithmetic& b) { using default_ops::eval_lt; @@ -312,7 +312,7 @@ inline typename enable_if_c::canonical_value(b)); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator < (const Arithmetic& a, const number& b) { using default_ops::eval_gt; @@ -320,7 +320,7 @@ inline typename enable_if_c::canonical_value(a)); } template -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator < (const Arithmetic& a, const detail::expression& b) { typedef typename detail::expression::result_type result_type; @@ -330,7 +330,7 @@ inline typename enable_if_c -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator < (const detail::expression& a, const Arithmetic& b) { typedef typename detail::expression::result_type result_type; @@ -340,7 +340,7 @@ inline typename enable_if_c -inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type +inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type operator < (const detail::expression& a, const detail::expression& b) { using default_ops::eval_lt; @@ -358,7 +358,7 @@ inline bool operator > (const number& a, const num return eval_gt(a.backend(), b.backend()); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator > (const number& a, const Arithmetic& b) { using default_ops::eval_gt; @@ -366,7 +366,7 @@ inline typename enable_if_c::canonical_value(b)); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator > (const Arithmetic& a, const number& b) { using default_ops::eval_lt; @@ -374,7 +374,7 @@ inline typename enable_if_c::canonical_value(a)); } template -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator > (const Arithmetic& a, const detail::expression& b) { typedef typename detail::expression::result_type result_type; @@ -384,7 +384,7 @@ inline typename enable_if_c t; } template -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator > (const detail::expression& a, const Arithmetic& b) { typedef typename detail::expression::result_type result_type; @@ -394,7 +394,7 @@ inline typename enable_if_c b; } template -inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type +inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type operator > (const detail::expression& a, const detail::expression& b) { using default_ops::eval_gt; @@ -412,7 +412,7 @@ inline bool operator <= (const number& a, const nu return !eval_gt(a.backend(), b.backend()); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator <= (const number& a, const Arithmetic& b) { using default_ops::eval_gt; @@ -420,7 +420,7 @@ inline typename enable_if_c::canonical_value(b)); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator <= (const Arithmetic& a, const number& b) { using default_ops::eval_lt; @@ -428,7 +428,7 @@ inline typename enable_if_c::canonical_value(a)); } template -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator <= (const Arithmetic& a, const detail::expression& b) { typedef typename detail::expression::result_type result_type; @@ -440,7 +440,7 @@ inline typename enable_if_c -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator <= (const detail::expression& a, const Arithmetic& b) { typedef typename detail::expression::result_type result_type; @@ -450,7 +450,7 @@ inline typename enable_if_c -inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type +inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type operator <= (const detail::expression& a, const detail::expression& b) { using default_ops::eval_gt; @@ -468,7 +468,7 @@ inline bool operator >= (const number& a, const nu return !eval_lt(a.backend(), b.backend()); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator >= (const number& a, const Arithmetic& b) { using default_ops::eval_lt; @@ -476,7 +476,7 @@ inline typename enable_if_c::canonical_value(b)); } template -inline typename enable_if_c, Arithmetic>::value, bool>::type +inline typename enable_if_c, Arithmetic>::value, bool>::type operator >= (const Arithmetic& a, const number& b) { using default_ops::eval_gt; @@ -484,7 +484,7 @@ inline typename enable_if_c::canonical_value(a)); } template -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator >= (const Arithmetic& a, const detail::expression& b) { typedef typename detail::expression::result_type result_type; @@ -494,7 +494,7 @@ inline typename enable_if_c -inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type +inline typename enable_if_c::result_type, Arithmetic>::value, bool>::type operator >= (const detail::expression& a, const Arithmetic& b) { typedef typename detail::expression::result_type result_type; @@ -504,7 +504,7 @@ inline typename enable_if_c -inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type +inline typename enable_if::result_type, typename detail::expression::result_type>, bool>::type operator >= (const detail::expression& a, const detail::expression& b) { using default_ops::eval_lt; -- cgit v1.2.3 From 6f7ff2dcd4e4cc83a76c8e79993682408da0b774 Mon Sep 17 00:00:00 2001 From: liangdzou Date: Thu, 20 Sep 2018 17:41:59 +0800 Subject: fix format issue for source files --- libdevcore/SHA3.cpp | 118 ++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 58 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/SHA3.cpp b/libdevcore/SHA3.cpp index b0e40ccb..e41a5e3b 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/SHA3.cpp @@ -67,22 +67,22 @@ deckeccak(512) /*** Constants. ***/ static const uint8_t rho[24] = \ - { 1, 3, 6, 10, 15, 21, + { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44}; static const uint8_t pi[24] = \ - {10, 7, 11, 17, 18, 3, + {10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, - 15, 23, 19, 13, 12, 2, - 20, 14, 22, 9, 6, 1}; + 15, 23, 19, 13, 12, 2, + 20, 14, 22, 9, 6, 1}; static const uint64_t RC[24] = \ - {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL, - 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL, - 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL, - 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL, - 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL, - 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL}; + {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL, + 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL, + 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL, + 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL, + 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL, + 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL}; /*** Helper macros to unroll the permutation. ***/ #define rol(x, s) (((x) << s) | ((x) >> (64 - s))) @@ -95,36 +95,37 @@ static const uint64_t RC[24] = \ /*** Keccak-f[1600] ***/ static inline void keccakf(void* state) { - uint64_t* a = (uint64_t*)state; - uint64_t b[5] = {0}; - - for (int i = 0; i < 24; i++) { - uint8_t x, y; - // Theta - FOR5(x, 1, - b[x] = 0; - FOR5(y, 5, - b[x] ^= a[x + y]; )) - FOR5(x, 1, - FOR5(y, 5, - a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); )) - // Rho and pi - uint64_t t = a[1]; - x = 0; - REPEAT24(b[0] = a[pi[x]]; - a[pi[x]] = rol(t, rho[x]); - t = b[0]; - x++; ) - // Chi - FOR5(y, - 5, - FOR5(x, 1, - b[x] = a[y + x];) - FOR5(x, 1, - a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); )) - // Iota - a[0] ^= RC[i]; - } + uint64_t* a = (uint64_t*)state; + uint64_t b[5] = {0}; + + for (int i = 0; i < 24; i++) + { + uint8_t x, y; + // Theta + FOR5(x, 1, + b[x] = 0; + FOR5(y, 5, + b[x] ^= a[x + y]; )) + FOR5(x, 1, + FOR5(y, 5, + a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); )) + // Rho and pi + uint64_t t = a[1]; + x = 0; + REPEAT24(b[0] = a[pi[x]]; + a[pi[x]] = rol(t, rho[x]); + t = b[0]; + x++; ) + // Chi + FOR5(y, + 5, + FOR5(x, 1, + b[x] = a[y + x];) + FOR5(x, 1, + a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); )) + // Iota + a[0] ^= RC[i]; + } } /******** The FIPS202-defined functions. ********/ @@ -166,24 +167,25 @@ mkapply_sd(setout, dst[i] = src[i]) // setout static inline int hash(uint8_t* out, size_t outlen, const uint8_t* in, size_t inlen, size_t rate, uint8_t delim) { - if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >= Plen)) { - return -1; - } - uint8_t a[Plen] = {0}; - // Absorb input. - foldP(in, inlen, xorin); - // Xor in the DS and pad frame. - a[inlen] ^= delim; - a[rate - 1] ^= 0x80; - // Xor in the last block. - xorin(a, in, inlen); - // Apply P - P(a); - // Squeeze output. - foldP(out, outlen, setout); - setout(a, out, outlen); - memset(a, 0, 200); - return 0; + if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >= Plen)) + { + return -1; + } + uint8_t a[Plen] = {0}; + // Absorb input. + foldP(in, inlen, xorin); + // Xor in the DS and pad frame. + a[inlen] ^= delim; + a[rate - 1] ^= 0x80; + // Xor in the last block. + xorin(a, in, inlen); + // Apply P + P(a); + // Squeeze output. + foldP(out, outlen, setout); + setout(a, out, outlen); + memset(a, 0, 200); + return 0; } /*** Helper macros to define SHA3 and SHAKE instances. ***/ -- cgit v1.2.3 From 3f216bac5e4ecd5723df815d13cae7ede4ad21dc Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 2 Oct 2018 10:52:53 +0200 Subject: Generic visitor. --- libdevcore/Visitor.h | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 libdevcore/Visitor.h (limited to 'libdevcore') diff --git a/libdevcore/Visitor.h b/libdevcore/Visitor.h new file mode 100644 index 00000000..4030c928 --- /dev/null +++ b/libdevcore/Visitor.h @@ -0,0 +1,128 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** + * Visitor templates. + */ + +#pragma once + +#include +#include + +namespace dev +{ + +/// Generic visitor used as follows: +/// boost::apply_visitor(GenericVisitor( +/// [](Class1& _c) { _c.f(); }, +/// [](Class2& _c) { _c.g(); } +/// ), variant); +/// This one does not have a fallback and will fail at +/// compile-time if you do not specify all variants. + +template +struct GenericVisitor{}; + +template +struct GenericVisitor: public GenericVisitor +{ + using GenericVisitor::operator (); + explicit GenericVisitor( + std::function _visitor, + std::function... _otherVisitors + ): + GenericVisitor(std::move(_otherVisitors)...), + m_visitor(std::move(_visitor)) + {} + + void operator()(Visitable& _v) const { m_visitor(_v); } + + std::function m_visitor; +}; +template <> +struct GenericVisitor<>: public boost::static_visitor<> { + void operator()() const {} +}; + +/// Generic visitor with fallback: +/// boost::apply_visitor(GenericFallbackVisitor( +/// [](Class1& _c) { _c.f(); }, +/// [](Class2& _c) { _c.g(); } +/// ), variant); +/// This one DOES have a fallback and will NOT fail at +/// compile-time if you do not specify all variants. + +template +struct GenericFallbackVisitor{}; + +template +struct GenericFallbackVisitor: public GenericFallbackVisitor +{ + explicit GenericFallbackVisitor( + std::function _visitor, + std::function... _otherVisitors + ): + GenericFallbackVisitor(std::move(_otherVisitors)...), + m_visitor(std::move(_visitor)) + {} + + using GenericFallbackVisitor::operator (); + void operator()(Visitable& _v) const { m_visitor(_v); } + + std::function m_visitor; +}; +template <> +struct GenericFallbackVisitor<>: public boost::static_visitor<> { + template + void operator()(T&) const { } +}; + +/// Generic visitor with fallback that can return a value: +/// boost::apply_visitor(GenericFallbackReturnsVisitor( +/// [](Class1& _c) { return _c.f(); }, +/// [](Class2& _c) { return _c.g(); } +/// ), variant); +/// This one DOES have a fallback and will NOT fail at +/// compile-time if you do not specify all variants. +/// The fallback {}-constructs the return value. + +template +struct GenericFallbackReturnsVisitor{}; + +template +struct GenericFallbackReturnsVisitor: public GenericFallbackReturnsVisitor +{ + explicit GenericFallbackReturnsVisitor( + std::function _visitor, + std::function... _otherVisitors + ): + GenericFallbackReturnsVisitor(std::move(_otherVisitors)...), + m_visitor(std::move(_visitor)) + {} + + using GenericFallbackReturnsVisitor::operator (); + R operator()(Visitable& _v) const { return m_visitor(_v); } + + std::function m_visitor; +}; +template +struct GenericFallbackReturnsVisitor: public boost::static_visitor { + template + R operator()(T&) const { return {}; } +}; + +} -- cgit v1.2.3 From 4d9184ef04a3163a4740b2d179398682c9f5140e Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 25 Sep 2018 16:29:46 +0200 Subject: Expression breaker. --- libdevcore/CommonData.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libdevcore') diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index e410af5c..98136b44 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -25,11 +25,14 @@ #include +#include + #include #include #include #include #include +#include namespace dev { @@ -229,6 +232,36 @@ bool contains(T const& _t, V const& _v) return std::end(_t) != std::find(std::begin(_t), std::end(_t), _v); } + +/// Function that iterates over a vector, calling a function on each of its +/// elements. If that function returns a vector, the element is replaced by +/// the returned vector. During the iteration, the original vector is only valid +/// on the current element and after that. The actual replacement takes +/// place at the end, but already visited elements might be invalidated. +/// If nothing is replaced, no copy is performed. +template +void iterateReplacing(std::vector& _vector, std::function>(T&)> _f) +{ + bool useModified = false; + std::vector modifiedVector; + for (size_t i = 0; i < _vector.size(); ++i) + { + if (boost::optional> r = _f(_vector[i])) + { + if (!useModified) + { + std::move(_vector.begin(), _vector.begin() + i, back_inserter(modifiedVector)); + useModified = true; + } + modifiedVector += std::move(*r); + } + else if (useModified) + modifiedVector.emplace_back(std::move(_vector[i])); + } + if (useModified) + _vector = std::move(modifiedVector); +} + /// @returns true iff @a _str passess the hex address checksum test. /// @param _strict if false, hex strings with only uppercase or only lowercase letters /// are considered valid. -- cgit v1.2.3 From 6c3d12d85bc7977817e8dc1c5bd0af4b29406b58 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 9 Oct 2018 19:06:22 +0100 Subject: Do not require ctype/stdio if not needed --- libdevcore/CommonIO.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'libdevcore') diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 9693d02a..2005d087 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #if defined(_WIN32) #include #else -- cgit v1.2.3 From 56bbfce6d36befbe89256035a333d9b47b360e0d Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 4 Oct 2018 14:55:32 +0200 Subject: Fix directory creation. --- libdevcore/CommonIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdevcore') diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 2005d087..1aa3504c 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -94,7 +94,7 @@ void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDe { // create directory if not existent fs::path p(_file); - if (!fs::exists(p.parent_path())) + if (!p.parent_path().empty() && !fs::exists(p.parent_path())) { fs::create_directories(p.parent_path()); try -- cgit v1.2.3 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') 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 04612936c2ceb41e1c63bfa637eb65f000319c23 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 15 Oct 2018 15:17:20 +0200 Subject: Yul: Introduces a block flattening pass + tests --- libdevcore/CommonData.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index 98136b44..f208c425 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -239,9 +239,10 @@ bool contains(T const& _t, V const& _v) /// on the current element and after that. The actual replacement takes /// place at the end, but already visited elements might be invalidated. /// If nothing is replaced, no copy is performed. -template -void iterateReplacing(std::vector& _vector, std::function>(T&)> _f) +template +void iterateReplacing(std::vector& _vector, const F& _f) { + // Concept: _f must be Callable, must accept param T&, must return optional> bool useModified = false; std::vector modifiedVector; for (size_t i = 0; i < _vector.size(); ++i) -- cgit v1.2.3 From 0690aae09d1591b65d6808e6c6c547b63ddb3ce9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 18 Oct 2018 00:48:07 +0200 Subject: Remove mostly unused writeFile implementation. --- libdevcore/CommonIO.cpp | 39 --------------------------------------- libdevcore/CommonIO.h | 8 -------- 2 files changed, 47 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 1aa3504c..cc730575 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -80,45 +80,6 @@ string dev::readStandardInput() return ret; } -void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename) -{ - namespace fs = boost::filesystem; - if (_writeDeleteRename) - { - fs::path tempPath = fs::unique_path(_file + "-%%%%%%"); - writeFile(tempPath.string(), _data, false); - // will delete _file if it exists - fs::rename(tempPath, _file); - } - else - { - // create directory if not existent - fs::path p(_file); - if (!p.parent_path().empty() && !fs::exists(p.parent_path())) - { - fs::create_directories(p.parent_path()); - try - { - fs::permissions(p.parent_path(), fs::owner_all); - } - catch (...) - { - } - } - - ofstream s(_file, ios::trunc | ios::binary); - s.write(reinterpret_cast(_data.data()), _data.size()); - assertThrow(s, FileError, "Could not write to file: " + _file); - try - { - fs::permissions(_file, fs::owner_read|fs::owner_write); - } - catch (...) - { - } - } -} - #if defined(_WIN32) class DisableConsoleBuffering { diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h index 928b6d15..b9f941ea 100644 --- a/libdevcore/CommonIO.h +++ b/libdevcore/CommonIO.h @@ -41,14 +41,6 @@ std::string readStandardInput(); /// Retrieve and returns a character from standard input (without waiting for EOL). int readStandardInputChar(); -/// Write the given binary data into the given file, replacing the file if it pre-exists. -/// Throws exception on error. -/// @param _writeDeleteRename useful not to lose any data: If set, first writes to another file in -/// the same directory and then moves that file. -void writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename = false); -/// Write the given binary data into the given file, replacing the file if it pre-exists. -inline void writeFile(std::string const& _file, bytes const& _data, bool _writeDeleteRename = false) { writeFile(_file, bytesConstRef(&_data), _writeDeleteRename); } -inline void writeFile(std::string const& _file, std::string const& _data, bool _writeDeleteRename = false) { writeFile(_file, bytesConstRef(_data), _writeDeleteRename); } /// Converts arbitrary value to string representation using std::stringstream. template std::string toString(_T const& _t) -- cgit v1.2.3 From d9e6469811655e7272d4a5cf23f888b8776e4acc Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 18 Oct 2018 00:48:28 +0200 Subject: Simplify sha3. --- libdevcore/SHA3.cpp | 93 +++++++++++------------------------------------------ libdevcore/SHA3.h | 8 +---- 2 files changed, 19 insertions(+), 82 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/SHA3.cpp b/libdevcore/SHA3.cpp index e41a5e3b..6933f255 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/SHA3.cpp @@ -31,7 +31,7 @@ using namespace dev; namespace dev { -namespace keccak +namespace { /** libkeccak-tiny @@ -43,26 +43,6 @@ namespace keccak * but not liability. */ -#define decshake(bits) \ - int shake##bits(uint8_t*, size_t, const uint8_t*, size_t); - -#define decsha3(bits) \ - int sha3_##bits(uint8_t*, size_t, const uint8_t*, size_t); - -#define deckeccak(bits) \ - int keccak##bits(uint8_t*, size_t, const uint8_t*, size_t); - -decshake(128) -decshake(256) -decsha3(224) -decsha3(256) -decsha3(384) -decsha3(512) -deckeccak(224) -deckeccak(256) -deckeccak(384) -deckeccak(512) - /******** The Keccak-f[1600] permutation ********/ /*** Constants. ***/ @@ -164,13 +144,15 @@ mkapply_sd(setout, dst[i] = src[i]) // setout } /** The sponge-based hash construction. **/ -static inline int hash(uint8_t* out, size_t outlen, - const uint8_t* in, size_t inlen, - size_t rate, uint8_t delim) { - if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >= Plen)) - { - return -1; - } +inline void hash( + uint8_t* out, + size_t outlen, + const uint8_t* in, + size_t inlen, + size_t rate, + uint8_t delim +) +{ uint8_t a[Plen] = {0}; // Absorb input. foldP(in, inlen, xorin); @@ -185,58 +167,19 @@ static inline int hash(uint8_t* out, size_t outlen, foldP(out, outlen, setout); setout(a, out, outlen); memset(a, 0, 200); - return 0; } -/*** Helper macros to define SHA3 and SHAKE instances. ***/ -#define defshake(bits) \ - int shake##bits(uint8_t* out, size_t outlen, \ - const uint8_t* in, size_t inlen) { \ - return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x1f); \ - } -#define defsha3(bits) \ - int sha3_##bits(uint8_t* out, size_t outlen, \ - const uint8_t* in, size_t inlen) { \ - if (outlen > (bits/8)) { \ - return -1; \ - } \ - return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x06); \ - } -#define defkeccak(bits) \ - int keccak##bits(uint8_t* out, size_t outlen, \ - const uint8_t* in, size_t inlen) { \ - if (outlen > (bits/8)) { \ - return -1; \ - } \ - return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \ - } - -/*** FIPS202 SHAKE VOFs ***/ -defshake(128) -defshake(256) - -/*** FIPS202 SHA3 FOFs ***/ -defsha3(224) -defsha3(256) -defsha3(384) -defsha3(512) - -/*** KECCAK FOFs ***/ -defkeccak(224) -defkeccak(256) -defkeccak(384) -defkeccak(512) - } -bool keccak256(bytesConstRef _input, bytesRef o_output) +h256 keccak256(bytesConstRef _input) { - // FIXME: What with unaligned memory? - if (o_output.size() != 32) - return false; - keccak::keccak256(o_output.data(), 32, _input.data(), _input.size()); -// keccak::keccak(ret.data(), 32, (uint64_t const*)_input.data(), _input.size()); - return true; + h256 output; + // Parameters used: + // The 0x01 is the specific padding for keccak (sha3 uses 0x06) and + // the way the round size (or window or whatever it was) is calculated. + // 200 - (256 / 4) is the "rate" + hash(output.data(), output.size, _input.data(), _input.size(), 200 - (256 / 4), 0x01); + return output; } } diff --git a/libdevcore/SHA3.h b/libdevcore/SHA3.h index d1e2cc98..0d5f69bb 100644 --- a/libdevcore/SHA3.h +++ b/libdevcore/SHA3.h @@ -30,14 +30,8 @@ namespace dev { -// Keccak-256 convenience routines. - -/// Calculate Keccak-256 hash of the given input and load it into the given output. -/// @returns false if o_output.size() != 32. -bool keccak256(bytesConstRef _input, bytesRef o_output); - /// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash. -inline h256 keccak256(bytesConstRef _input) { h256 ret; keccak256(_input, ret.ref()); return ret; } +h256 keccak256(bytesConstRef _input); /// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash. inline h256 keccak256(bytes const& _input) { return keccak256(bytesConstRef(&_input)); } -- 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 +- libdevcore/Keccak256.cpp | 186 ++++++++++++++++++++++++++++++++++++++++++++++ libdevcore/Keccak256.h | 45 +++++++++++ libdevcore/SHA3.cpp | 185 --------------------------------------------- libdevcore/SHA3.h | 45 ----------- libdevcore/SwarmHash.cpp | 2 +- 6 files changed, 233 insertions(+), 232 deletions(-) create mode 100644 libdevcore/Keccak256.cpp create mode 100644 libdevcore/Keccak256.h delete mode 100644 libdevcore/SHA3.cpp delete mode 100644 libdevcore/SHA3.h (limited to 'libdevcore') 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 diff --git a/libdevcore/Keccak256.cpp b/libdevcore/Keccak256.cpp new file mode 100644 index 00000000..7933fc7e --- /dev/null +++ b/libdevcore/Keccak256.cpp @@ -0,0 +1,186 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** @file SHA3.cpp + * @author Gav Wood + * @date 2014 + */ + +#include + +#include +#include +#include +#include + +using namespace std; +using namespace dev; + +namespace dev +{ + +namespace +{ + +/** libkeccak-tiny + * + * A single-file implementation of SHA-3 and SHAKE. + * + * Implementor: David Leon Gil + * License: CC0, attribution kindly requested. Blame taken too, + * but not liability. + */ + +/******** The Keccak-f[1600] permutation ********/ + +/*** Constants. ***/ +static const uint8_t rho[24] = \ + { 1, 3, 6, 10, 15, 21, + 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, + 62, 18, 39, 61, 20, 44}; +static const uint8_t pi[24] = \ + {10, 7, 11, 17, 18, 3, + 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, + 20, 14, 22, 9, 6, 1}; +static const uint64_t RC[24] = \ + {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL, + 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL, + 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL, + 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL, + 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL, + 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL}; + +/*** Helper macros to unroll the permutation. ***/ +#define rol(x, s) (((x) << s) | ((x) >> (64 - s))) +#define REPEAT6(e) e e e e e e +#define REPEAT24(e) REPEAT6(e e e e) +#define REPEAT5(e) e e e e e +#define FOR5(v, s, e) \ + v = 0; \ + REPEAT5(e; v += s;) + +/*** Keccak-f[1600] ***/ +static inline void keccakf(void* state) { + uint64_t* a = (uint64_t*)state; + uint64_t b[5] = {0}; + + for (int i = 0; i < 24; i++) + { + uint8_t x, y; + // Theta + FOR5(x, 1, + b[x] = 0; + FOR5(y, 5, + b[x] ^= a[x + y]; )) + FOR5(x, 1, + FOR5(y, 5, + a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); )) + // Rho and pi + uint64_t t = a[1]; + x = 0; + REPEAT24(b[0] = a[pi[x]]; + a[pi[x]] = rol(t, rho[x]); + t = b[0]; + x++; ) + // Chi + FOR5(y, + 5, + FOR5(x, 1, + b[x] = a[y + x];) + FOR5(x, 1, + a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); )) + // Iota + a[0] ^= RC[i]; + } +} + +/******** The FIPS202-defined functions. ********/ + +/*** Some helper macros. ***/ + +#define _(S) do { S } while (0) +#define FOR(i, ST, L, S) \ + _(for (size_t i = 0; i < L; i += ST) { S; }) +#define mkapply_ds(NAME, S) \ + static inline void NAME(uint8_t* dst, \ + const uint8_t* src, \ + size_t len) { \ + FOR(i, 1, len, S); \ + } +#define mkapply_sd(NAME, S) \ + static inline void NAME(const uint8_t* src, \ + uint8_t* dst, \ + size_t len) { \ + FOR(i, 1, len, S); \ + } + +mkapply_ds(xorin, dst[i] ^= src[i]) // xorin +mkapply_sd(setout, dst[i] = src[i]) // setout + +#define P keccakf +#define Plen 200 + +// Fold P*F over the full blocks of an input. +#define foldP(I, L, F) \ + while (L >= rate) { \ + F(a, I, rate); \ + P(a); \ + I += rate; \ + L -= rate; \ + } + +/** The sponge-based hash construction. **/ +inline void hash( + uint8_t* out, + size_t outlen, + const uint8_t* in, + size_t inlen, + size_t rate, + uint8_t delim +) +{ + uint8_t a[Plen] = {0}; + // Absorb input. + foldP(in, inlen, xorin); + // Xor in the DS and pad frame. + a[inlen] ^= delim; + a[rate - 1] ^= 0x80; + // Xor in the last block. + xorin(a, in, inlen); + // Apply P + P(a); + // Squeeze output. + foldP(out, outlen, setout); + setout(a, out, outlen); + memset(a, 0, 200); +} + +} + +h256 keccak256(bytesConstRef _input) +{ + h256 output; + // Parameters used: + // The 0x01 is the specific padding for keccak (sha3 uses 0x06) and + // the way the round size (or window or whatever it was) is calculated. + // 200 - (256 / 4) is the "rate" + hash(output.data(), output.size, _input.data(), _input.size(), 200 - (256 / 4), 0x01); + return output; +} + +} diff --git a/libdevcore/Keccak256.h b/libdevcore/Keccak256.h new file mode 100644 index 00000000..0d5f69bb --- /dev/null +++ b/libdevcore/Keccak256.h @@ -0,0 +1,45 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** @file SHA3.h + * @author Gav Wood + * @date 2014 + * + * The FixedHash fixed-size "hash" container type. + */ + +#pragma once + +#include + +#include + +namespace dev +{ + +/// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash. +h256 keccak256(bytesConstRef _input); + +/// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash. +inline h256 keccak256(bytes const& _input) { return keccak256(bytesConstRef(&_input)); } + +/// Calculate Keccak-256 hash of the given input (presented as a binary-filled string), returning as a 256-bit hash. +inline h256 keccak256(std::string const& _input) { return keccak256(bytesConstRef(_input)); } + +/// Calculate Keccak-256 hash of the given input (presented as a FixedHash), returns a 256-bit hash. +template inline h256 keccak256(FixedHash const& _input) { return keccak256(_input.ref()); } + +} diff --git a/libdevcore/SHA3.cpp b/libdevcore/SHA3.cpp deleted file mode 100644 index 6933f255..00000000 --- a/libdevcore/SHA3.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - This file is part of solidity. - - solidity is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - solidity is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with solidity. If not, see . -*/ -/** @file SHA3.cpp - * @author Gav Wood - * @date 2014 - */ - -#include "SHA3.h" -#include -#include -#include -#include - -using namespace std; -using namespace dev; - -namespace dev -{ - -namespace -{ - -/** libkeccak-tiny - * - * A single-file implementation of SHA-3 and SHAKE. - * - * Implementor: David Leon Gil - * License: CC0, attribution kindly requested. Blame taken too, - * but not liability. - */ - -/******** The Keccak-f[1600] permutation ********/ - -/*** Constants. ***/ -static const uint8_t rho[24] = \ - { 1, 3, 6, 10, 15, 21, - 28, 36, 45, 55, 2, 14, - 27, 41, 56, 8, 25, 43, - 62, 18, 39, 61, 20, 44}; -static const uint8_t pi[24] = \ - {10, 7, 11, 17, 18, 3, - 5, 16, 8, 21, 24, 4, - 15, 23, 19, 13, 12, 2, - 20, 14, 22, 9, 6, 1}; -static const uint64_t RC[24] = \ - {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL, - 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL, - 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL, - 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL, - 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL, - 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL}; - -/*** Helper macros to unroll the permutation. ***/ -#define rol(x, s) (((x) << s) | ((x) >> (64 - s))) -#define REPEAT6(e) e e e e e e -#define REPEAT24(e) REPEAT6(e e e e) -#define REPEAT5(e) e e e e e -#define FOR5(v, s, e) \ - v = 0; \ - REPEAT5(e; v += s;) - -/*** Keccak-f[1600] ***/ -static inline void keccakf(void* state) { - uint64_t* a = (uint64_t*)state; - uint64_t b[5] = {0}; - - for (int i = 0; i < 24; i++) - { - uint8_t x, y; - // Theta - FOR5(x, 1, - b[x] = 0; - FOR5(y, 5, - b[x] ^= a[x + y]; )) - FOR5(x, 1, - FOR5(y, 5, - a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); )) - // Rho and pi - uint64_t t = a[1]; - x = 0; - REPEAT24(b[0] = a[pi[x]]; - a[pi[x]] = rol(t, rho[x]); - t = b[0]; - x++; ) - // Chi - FOR5(y, - 5, - FOR5(x, 1, - b[x] = a[y + x];) - FOR5(x, 1, - a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); )) - // Iota - a[0] ^= RC[i]; - } -} - -/******** The FIPS202-defined functions. ********/ - -/*** Some helper macros. ***/ - -#define _(S) do { S } while (0) -#define FOR(i, ST, L, S) \ - _(for (size_t i = 0; i < L; i += ST) { S; }) -#define mkapply_ds(NAME, S) \ - static inline void NAME(uint8_t* dst, \ - const uint8_t* src, \ - size_t len) { \ - FOR(i, 1, len, S); \ - } -#define mkapply_sd(NAME, S) \ - static inline void NAME(const uint8_t* src, \ - uint8_t* dst, \ - size_t len) { \ - FOR(i, 1, len, S); \ - } - -mkapply_ds(xorin, dst[i] ^= src[i]) // xorin -mkapply_sd(setout, dst[i] = src[i]) // setout - -#define P keccakf -#define Plen 200 - -// Fold P*F over the full blocks of an input. -#define foldP(I, L, F) \ - while (L >= rate) { \ - F(a, I, rate); \ - P(a); \ - I += rate; \ - L -= rate; \ - } - -/** The sponge-based hash construction. **/ -inline void hash( - uint8_t* out, - size_t outlen, - const uint8_t* in, - size_t inlen, - size_t rate, - uint8_t delim -) -{ - uint8_t a[Plen] = {0}; - // Absorb input. - foldP(in, inlen, xorin); - // Xor in the DS and pad frame. - a[inlen] ^= delim; - a[rate - 1] ^= 0x80; - // Xor in the last block. - xorin(a, in, inlen); - // Apply P - P(a); - // Squeeze output. - foldP(out, outlen, setout); - setout(a, out, outlen); - memset(a, 0, 200); -} - -} - -h256 keccak256(bytesConstRef _input) -{ - h256 output; - // Parameters used: - // The 0x01 is the specific padding for keccak (sha3 uses 0x06) and - // the way the round size (or window or whatever it was) is calculated. - // 200 - (256 / 4) is the "rate" - hash(output.data(), output.size, _input.data(), _input.size(), 200 - (256 / 4), 0x01); - return output; -} - -} diff --git a/libdevcore/SHA3.h b/libdevcore/SHA3.h deleted file mode 100644 index 0d5f69bb..00000000 --- a/libdevcore/SHA3.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - This file is part of solidity. - - solidity is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - solidity is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with solidity. If not, see . -*/ -/** @file SHA3.h - * @author Gav Wood - * @date 2014 - * - * The FixedHash fixed-size "hash" container type. - */ - -#pragma once - -#include - -#include - -namespace dev -{ - -/// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash. -h256 keccak256(bytesConstRef _input); - -/// Calculate Keccak-256 hash of the given input, returning as a 256-bit hash. -inline h256 keccak256(bytes const& _input) { return keccak256(bytesConstRef(&_input)); } - -/// Calculate Keccak-256 hash of the given input (presented as a binary-filled string), returning as a 256-bit hash. -inline h256 keccak256(std::string const& _input) { return keccak256(bytesConstRef(_input)); } - -/// Calculate Keccak-256 hash of the given input (presented as a FixedHash), returns a 256-bit hash. -template inline h256 keccak256(FixedHash const& _input) { return keccak256(_input.ref()); } - -} diff --git a/libdevcore/SwarmHash.cpp b/libdevcore/SwarmHash.cpp index 1c718200..3b8d2f3e 100644 --- a/libdevcore/SwarmHash.cpp +++ b/libdevcore/SwarmHash.cpp @@ -19,7 +19,7 @@ #include -#include +#include using namespace std; using namespace dev; -- 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 +++++++++++++++++++++++ libdevcore/CommonData.h | 3 +++ 2 files changed, 26 insertions(+) (limited to 'libdevcore') 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; +} diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index f208c425..0782fabc 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -272,4 +272,7 @@ bool passesAddressChecksum(std::string const& _str, bool _strict); /// @param hex strings that look like an address std::string getChecksummedAddress(std::string const& _addr); +bool isValidHex(std::string const& _string); +bool isValidDecimal(std::string const& _string); + } -- 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/Common.h | 8 +++----- libdevcore/CommonData.cpp | 2 +- libdevcore/CommonData.h | 6 +++--- libdevcore/FixedHash.h | 16 ++++++++-------- 4 files changed, 15 insertions(+), 17 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/Common.h b/libdevcore/Common.h index 0363d9a2..6208424e 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -64,15 +64,13 @@ #include #include -using byte = uint8_t; - namespace dev { // Binary data types. -using bytes = std::vector; -using bytesRef = vector_ref; -using bytesConstRef = vector_ref; +using bytes = std::vector; +using bytesRef = vector_ref; +using bytesConstRef = vector_ref; // Numeric types. using bigint = boost::multiprecision::number>; 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 diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index 0782fabc..fedd3af2 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -88,7 +88,7 @@ inline std::string asString(bytesConstRef _b) /// Converts a string to a byte array containing the string's (byte) data. inline bytes asBytes(std::string const& _b) { - return bytes((byte const*)_b.data(), (byte const*)(_b.data() + _b.size())); + return bytes((uint8_t const*)_b.data(), (uint8_t const*)(_b.data() + _b.size())); } // Big-endian to/from host endian conversion functions. @@ -117,7 +117,7 @@ inline T fromBigEndian(_In const& _bytes) { T ret = (T)0; for (auto i: _bytes) - ret = (T)((ret << 8) | (byte)(typename std::make_unsigned::type)i); + ret = (T)((ret << 8) | (uint8_t)(typename std::make_unsigned::type)i); return ret; } inline bytes toBigEndian(u256 _val) { bytes ret(32); toBigEndian(_val, ret); return ret; } @@ -135,7 +135,7 @@ inline bytes toCompactBigEndian(T _val, unsigned _min = 0) toBigEndian(_val, ret); return ret; } -inline bytes toCompactBigEndian(byte _val, unsigned _min = 0) +inline bytes toCompactBigEndian(uint8_t _val, unsigned _min = 0) { return (_min || _val) ? bytes{ _val } : bytes{}; } diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index cd6e1da1..24b89840 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -79,7 +79,7 @@ public: operator Arith() const { return fromBigEndian(m_data); } /// @returns true iff this is the empty hash. - explicit operator bool() const { return std::any_of(m_data.begin(), m_data.end(), [](byte _b) { return _b != 0; }); } + explicit operator bool() const { return std::any_of(m_data.begin(), m_data.end(), [](uint8_t _b) { return _b != 0; }); } // The obvious comparison operators. bool operator==(FixedHash const& _c) const { return m_data == _c.m_data; } @@ -90,9 +90,9 @@ public: FixedHash operator~() const { FixedHash ret; for (unsigned i = 0; i < N; ++i) ret[i] = ~m_data[i]; return ret; } /// @returns a particular byte from the hash. - byte& operator[](unsigned _i) { return m_data[_i]; } + uint8_t& operator[](unsigned _i) { return m_data[_i]; } /// @returns a particular byte from the hash. - byte operator[](unsigned _i) const { return m_data[_i]; } + uint8_t operator[](unsigned _i) const { return m_data[_i]; } /// @returns the hash as a user-readable hex string. std::string hex() const { return toHex(ref()); } @@ -104,19 +104,19 @@ public: bytesConstRef ref() const { return bytesConstRef(m_data.data(), N); } /// @returns a mutable byte pointer to the object's data. - byte* data() { return m_data.data(); } + uint8_t* data() { return m_data.data(); } /// @returns a constant byte pointer to the object's data. - byte const* data() const { return m_data.data(); } + uint8_t const* data() const { return m_data.data(); } /// @returns a copy of the object's data as a byte vector. bytes asBytes() const { return bytes(data(), data() + N); } /// @returns a mutable reference to the object's data as an STL array. - std::array& asArray() { return m_data; } + std::array& asArray() { return m_data; } /// @returns a constant reference to the object's data as an STL array. - std::array const& asArray() const { return m_data; } + std::array const& asArray() const { return m_data; } /// Returns the index of the first bit set to one, or size() * 8 if no bits are set. inline unsigned firstBitSet() const @@ -137,7 +137,7 @@ public: void clear() { m_data.fill(0); } private: - std::array m_data; ///< The binary data. + std::array m_data; ///< The binary data. }; /// Stream I/O for the FixedHash class. -- cgit v1.2.3