diff --git a/container/src/root/src/hash.hh b/container/src/root/src/hash.hh index a5ce4ea..5d2e2af 100644 --- a/container/src/root/src/hash.hh +++ b/container/src/root/src/hash.hh @@ -29,8 +29,6 @@ #include "./internal/impl/hash.hh" #include "./internal/type.hh" -namespace type = docker_finance::internal::type; - //! \namespace docker_finance //! \since docker-finance 1.0.0 namespace docker_finance @@ -40,6 +38,9 @@ namespace docker_finance //! \since docker-finance 1.0.0 namespace crypto { + +namespace type = docker_finance::internal::type; + //! \namespace docker_finance::crypto::common //! \brief Common "interface" (specializations) to library-specific implementations //! \warning Not for direct public consumption (use library namespace instead) diff --git a/container/src/root/src/internal/impl/hash.hh b/container/src/root/src/internal/impl/hash.hh index 37bc2e6..54a3682 100644 --- a/container/src/root/src/internal/impl/hash.hh +++ b/container/src/root/src/internal/impl/hash.hh @@ -44,8 +44,6 @@ #include "../generic.hh" #include "../type.hh" -namespace type = docker_finance::internal::type; - //! \namespace docker_finance //! \since docker-finance 1.0.0 namespace docker_finance @@ -60,6 +58,9 @@ namespace crypto //! \since docker-finance 1.0.0 namespace impl { + +namespace type = docker_finance::internal::type; + //! \namespace docker_finance::crypto::impl::common //! \brief Common implementation among all crypto implementations //! \since docker-finance 1.0.0 @@ -428,11 +429,11 @@ class Hash : public common::HashImpl, public type::Hash //! have any effects." Hash() { - if (::sodium_init() < 0) - { - throw std::runtime_error("sodium_init could not be initialized"); - } - }; + THROW_IF( + ::sodium_init() < 0, + type::RuntimeError, + "sodium_init could not be initialized") + } ~Hash() = default; Hash(const Hash&) = default; diff --git a/container/src/root/src/internal/impl/random.hh b/container/src/root/src/internal/impl/random.hh index 24fefb5..8416868 100644 --- a/container/src/root/src/internal/impl/random.hh +++ b/container/src/root/src/internal/impl/random.hh @@ -33,6 +33,7 @@ #include #include "../generic.hh" +#include "../type.hh" //! \namespace docker_finance //! \since docker-finance 1.0.0 @@ -82,6 +83,8 @@ class RandomImpl : public ::docker_finance::internal::Random }; } // namespace common +namespace type = docker_finance::internal::type; + //! \namespace docker_finance::crypto::impl::botan //! \since docker-finance 1.0.0 namespace botan @@ -117,9 +120,7 @@ class Random : public common::RandomImpl static_assert( std::is_same_v, "Random interface has changed"); - if (!m_csprng.is_seeded()) - throw std::runtime_error( - "Botan is not seeded"); // TODO(afiore): use docker-finance's error.hh + THROW_IF(!m_csprng.is_seeded(), type::RuntimeError, "Botan is not seeded") // WARNING: DO *NOT* set_high_bit to true here! // Otherwise, [0..(~2150*10^6)] WILL NOT BE GENERATED! @@ -206,11 +207,11 @@ class Random : public common::RandomImpl //! have any effects." Random() { - if (::sodium_init() < 0) - { - throw std::runtime_error("sodium_init could not be initialized"); - } - }; + THROW_IF( + ::sodium_init() < 0, + type::RuntimeError, + "sodium_init could not be initialized") + } ~Random() = default; Random(const Random&) = default; diff --git a/container/src/root/src/internal/impl/utility.hh b/container/src/root/src/internal/impl/utility.hh index 82c6da4..19c6fe5 100644 --- a/container/src/root/src/internal/impl/utility.hh +++ b/container/src/root/src/internal/impl/utility.hh @@ -31,6 +31,7 @@ // #include // TODO(afiore): file upstream (calc) bug report #include "../../random.hh" #include "../generic.hh" +#include "../type.hh" //! \namespace docker_finance //! \since docker-finance 1.0.0 @@ -46,6 +47,9 @@ namespace utility //! \since docker-finance 1.0.0 namespace impl { + +namespace type = docker_finance::internal::type; + //! \brief Misc tools //! \ingroup cpp_API_impl //! \since docker-finance 1.0.0 @@ -155,8 +159,8 @@ class Tools std::vector random_dist(const t_num min, const t_num max, const uint16_t precision = 8) { - if (min > max) - throw std::runtime_error("minimum given is greater than maximum"); + THROW_IF( + min > max, type::InvalidArgument, "minimum is greater than maximum") // Get first chunk std::vector chunks; @@ -189,8 +193,7 @@ class Tools std::cout.precision(precision); std::cout << "rounded = " << rounded << '\n' << "max = " << max << std::fixed << std::endl; - - throw std::runtime_error("random distribution not fulfilled"); + THROW(type::RuntimeError, "random distribution not fulfilled") } return chunks; diff --git a/container/src/root/src/utility.hh b/container/src/root/src/utility.hh index 7e2bdc7..82c9b55 100644 --- a/container/src/root/src/utility.hh +++ b/container/src/root/src/utility.hh @@ -31,8 +31,7 @@ #include #include "./internal/impl/utility.hh" - -namespace type = docker_finance::internal::type; +#include "./internal/type.hh" //! \namespace docker_finance //! \since docker-finance 1.0.0 @@ -43,6 +42,9 @@ namespace docker_finance //! \since docker-finance 1.0.0 namespace utility { + +namespace type = docker_finance::internal::type; + //! \brief Misc utility tools //! \ingroup cpp_utils //! \since docker-finance 1.0.0 @@ -84,8 +86,8 @@ class Tools final : protected impl::Tools void print_dist(t_num min, t_num max, const size_t precision = 8) { // Specific to this use-case - if (min < 0 || max < 0) - throw std::runtime_error("No negative values allowed"); + THROW_IF( + min < 0 || max < 0, type::InvalidArgument, "no negative values allowed") if (min > max) {