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