forked from EvergreenCrypto/docker-finance
container: root: refactor using internal throw/exception handler
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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<libsodium::Hash>, 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;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#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<t_impl>
|
||||
};
|
||||
} // 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<botan::Random>
|
||||
static_assert(
|
||||
std::is_same_v<t_random, uint32_t>, "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<libsodium::Random>
|
||||
//! 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;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
// #include <calc/core.h> // 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<t_num>
|
||||
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<t_num> 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;
|
||||
|
||||
@@ -31,8 +31,7 @@
|
||||
#include <vector>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user