From 454ec97d51e2ea0505d414fbb8208733ffb2afdb Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Fri, 21 Nov 2014 12:58:54 -0800 Subject: [PATCH] Replace custom exceptions with std::runtime_error --- Builds/VisualStudio2013/RippleD.vcxproj | 4 -- .../VisualStudio2013/RippleD.vcxproj.filters | 6 --- src/ripple/crypto/CAutoBN_CTX.h | 6 ++- src/ripple/crypto/CKey.h | 53 ------------------- src/ripple/crypto/bignum_error.h | 43 --------------- src/ripple/crypto/impl/CBigNum.cpp | 36 +++++++------ src/ripple/crypto/impl/ECIES.cpp | 1 - src/ripple/protocol/impl/RippleAddress.cpp | 2 +- src/ripple/types/impl/Base58.cpp | 7 ++- src/ripple/unity/sslutil.h | 1 - 10 files changed, 29 insertions(+), 130 deletions(-) delete mode 100644 src/ripple/crypto/CKey.h delete mode 100644 src/ripple/crypto/bignum_error.h diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index d707b6005..3fabd7fdb 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -2247,14 +2247,10 @@ - - - - diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 87862092d..75a92d1b3 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -3216,18 +3216,12 @@ ripple\crypto - - ripple\crypto - ripple\crypto ripple\crypto - - ripple\crypto - ripple\crypto diff --git a/src/ripple/crypto/CAutoBN_CTX.h b/src/ripple/crypto/CAutoBN_CTX.h index ddd335984..70073777c 100644 --- a/src/ripple/crypto/CAutoBN_CTX.h +++ b/src/ripple/crypto/CAutoBN_CTX.h @@ -25,9 +25,11 @@ #ifndef RIPPLE_CRYPTO_CAUTOBN_CTX_H_INCLUDED #define RIPPLE_CRYPTO_CAUTOBN_CTX_H_INCLUDED -#include #include +#include +#include + namespace ripple { class CAutoBN_CTX @@ -41,7 +43,7 @@ public: pctx = BN_CTX_new (); if (pctx == nullptr) - throw bignum_error ("CAutoBN_CTX : BN_CTX_new() returned nullptr"); + throw std::runtime_error ("CAutoBN_CTX : BN_CTX_new() returned nullptr"); } ~CAutoBN_CTX () diff --git a/src/ripple/crypto/CKey.h b/src/ripple/crypto/CKey.h deleted file mode 100644 index db9ce9863..000000000 --- a/src/ripple/crypto/CKey.h +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2011 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. - -#ifndef RIPPLE_CRYPTO_CKEY_H_INCLUDED -#define RIPPLE_CRYPTO_CKEY_H_INCLUDED - -#include -#include -#include -#include -#include - -namespace ripple { - -// secp256k1: -// const unsigned int PRIVATE_KEY_SIZE = 279; -// const unsigned int PUBLIC_KEY_SIZE = 65; // but we don't use full keys -// const unsigned int COMPUB_KEY_SIZE = 33; -// const unsigned int SIGNATURE_SIZE = 72; -// -// see www.keylength.com -// script supports up to 75 for single byte push - -class key_error : public std::runtime_error -{ -public: - explicit key_error (std::string const& str) : std::runtime_error (str) {} -}; - -} // ripple - -#endif diff --git a/src/ripple/crypto/bignum_error.h b/src/ripple/crypto/bignum_error.h deleted file mode 100644 index ec397eb8b..000000000 --- a/src/ripple/crypto/bignum_error.h +++ /dev/null @@ -1,43 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2011 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. - -#ifndef RIPPLE_CRYPTO_BIGNUM_ERROR_H_INCLUDED -#define RIPPLE_CRYPTO_BIGNUM_ERROR_H_INCLUDED - -#include - -namespace ripple { - -class bignum_error : public std::runtime_error -{ -public: - explicit bignum_error (std::string const& str) - : std::runtime_error (str) - { - } -}; - -} - -#endif diff --git a/src/ripple/crypto/impl/CBigNum.cpp b/src/ripple/crypto/impl/CBigNum.cpp index 50f0886c9..47f0d351e 100644 --- a/src/ripple/crypto/impl/CBigNum.cpp +++ b/src/ripple/crypto/impl/CBigNum.cpp @@ -22,10 +22,12 @@ // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. -#include #include #include +#include +#include + namespace ripple { CBigNum::CBigNum () @@ -40,14 +42,14 @@ CBigNum::CBigNum (const CBigNum& b) if (!BN_copy (this, &b)) { BN_clear_free (this); - throw bignum_error ("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); + throw std::runtime_error ("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); } } CBigNum& CBigNum::operator= (const CBigNum& b) { if (!BN_copy (this, &b)) - throw bignum_error ("CBigNum::operator= : BN_copy failed"); + throw std::runtime_error ("CBigNum::operator= : BN_copy failed"); return (*this); } @@ -378,7 +380,7 @@ std::string CBigNum::ToString (int nBase) const while (BN_cmp (&bn, &bn0) > 0) { if (!BN_div (&dv, &rem, &bn, &bnBase, pctx)) - throw bignum_error ("CBigNum::ToString() : BN_div failed"); + throw std::runtime_error ("CBigNum::ToString() : BN_div failed"); bn = dv; unsigned int c = rem.getuint (); @@ -405,7 +407,7 @@ bool CBigNum::operator! () const CBigNum& CBigNum::operator+= (const CBigNum& b) { if (!BN_add (this, this, &b)) - throw bignum_error ("CBigNum::operator+= : BN_add failed"); + throw std::runtime_error ("CBigNum::operator+= : BN_add failed"); return *this; } @@ -421,7 +423,7 @@ CBigNum& CBigNum::operator*= (const CBigNum& b) CAutoBN_CTX pctx; if (!BN_mul (this, this, &b, pctx)) - throw bignum_error ("CBigNum::operator*= : BN_mul failed"); + throw std::runtime_error ("CBigNum::operator*= : BN_mul failed"); return *this; } @@ -441,7 +443,7 @@ CBigNum& CBigNum::operator%= (const CBigNum& b) CBigNum& CBigNum::operator<<= (unsigned int shift) { if (!BN_lshift (this, this, shift)) - throw bignum_error ("CBigNum:operator<<= : BN_lshift failed"); + throw std::runtime_error ("CBigNum:operator<<= : BN_lshift failed"); return *this; } @@ -460,7 +462,7 @@ CBigNum& CBigNum::operator>>= (unsigned int shift) } if (!BN_rshift (this, this, shift)) - throw bignum_error ("CBigNum:operator>>= : BN_rshift failed"); + throw std::runtime_error ("CBigNum:operator>>= : BN_rshift failed"); return *this; } @@ -470,7 +472,7 @@ CBigNum& CBigNum::operator++ () { // prefix operator if (!BN_add (this, this, BN_value_one ())) - throw bignum_error ("CBigNum::operator++ : BN_add failed"); + throw std::runtime_error ("CBigNum::operator++ : BN_add failed"); return *this; } @@ -489,7 +491,7 @@ CBigNum& CBigNum::operator-- () CBigNum r; if (!BN_sub (&r, this, BN_value_one ())) - throw bignum_error ("CBigNum::operator-- : BN_sub failed"); + throw std::runtime_error ("CBigNum::operator-- : BN_sub failed"); *this = r; return *this; @@ -506,7 +508,7 @@ const CBigNum CBigNum::operator-- (int) void CBigNum::setulong (unsigned long n) { if (!BN_set_word (this, n)) - throw bignum_error ("CBigNum conversion from unsigned long : BN_set_word failed"); + throw std::runtime_error ("CBigNum conversion from unsigned long : BN_set_word failed"); } unsigned long CBigNum::getulong () const @@ -519,7 +521,7 @@ const CBigNum operator+ (const CBigNum& a, const CBigNum& b) CBigNum r; if (!BN_add (&r, &a, &b)) - throw bignum_error ("CBigNum::operator+ : BN_add failed"); + throw std::runtime_error ("CBigNum::operator+ : BN_add failed"); return r; } @@ -529,7 +531,7 @@ const CBigNum operator- (const CBigNum& a, const CBigNum& b) CBigNum r; if (!BN_sub (&r, &a, &b)) - throw bignum_error ("CBigNum::operator- : BN_sub failed"); + throw std::runtime_error ("CBigNum::operator- : BN_sub failed"); return r; } @@ -547,7 +549,7 @@ const CBigNum operator* (const CBigNum& a, const CBigNum& b) CBigNum r; if (!BN_mul (&r, &a, &b, pctx)) - throw bignum_error ("CBigNum::operator* : BN_mul failed"); + throw std::runtime_error ("CBigNum::operator* : BN_mul failed"); return r; } @@ -558,7 +560,7 @@ const CBigNum operator/ (const CBigNum& a, const CBigNum& b) CBigNum r; if (!BN_div (&r, nullptr, &a, &b, pctx)) - throw bignum_error ("CBigNum::operator/ : BN_div failed"); + throw std::runtime_error ("CBigNum::operator/ : BN_div failed"); return r; } @@ -569,7 +571,7 @@ const CBigNum operator% (const CBigNum& a, const CBigNum& b) CBigNum r; if (!BN_mod (&r, &a, &b, pctx)) - throw bignum_error ("CBigNum::operator% : BN_div failed"); + throw std::runtime_error ("CBigNum::operator% : BN_div failed"); return r; } @@ -579,7 +581,7 @@ const CBigNum operator<< (const CBigNum& a, unsigned int shift) CBigNum r; if (!BN_lshift (&r, &a, shift)) - throw bignum_error ("CBigNum:operator<< : BN_lshift failed"); + throw std::runtime_error ("CBigNum:operator<< : BN_lshift failed"); return r; } diff --git a/src/ripple/crypto/impl/ECIES.cpp b/src/ripple/crypto/impl/ECIES.cpp index e11d998c7..02784f4ea 100644 --- a/src/ripple/crypto/impl/ECIES.cpp +++ b/src/ripple/crypto/impl/ECIES.cpp @@ -17,7 +17,6 @@ */ //============================================================================== -#include #include #include #include diff --git a/src/ripple/protocol/impl/RippleAddress.cpp b/src/ripple/protocol/impl/RippleAddress.cpp index 56e00d427..bca807888 100644 --- a/src/ripple/protocol/impl/RippleAddress.cpp +++ b/src/ripple/protocol/impl/RippleAddress.cpp @@ -19,9 +19,9 @@ #include #include -#include #include #include +#include #include #include #include diff --git a/src/ripple/types/impl/Base58.cpp b/src/ripple/types/impl/Base58.cpp index cddcfee80..84dd1ca86 100644 --- a/src/ripple/types/impl/Base58.cpp +++ b/src/ripple/types/impl/Base58.cpp @@ -22,6 +22,9 @@ #include #include +#include +#include + // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2011 The Bitcoin Developers // Distributed under the MIT/X11 software license, see the accompanying @@ -86,7 +89,7 @@ std::string Base58::raw_encode ( while (bn > bn0) { if (!BN_div (&dv, &rem, &bn, &bn58, pctx)) - throw bignum_error ("EncodeBase58 : BN_div failed"); + throw std::runtime_error ("EncodeBase58 : BN_div failed"); bn = dv; unsigned int c = rem.getuint (); @@ -196,7 +199,7 @@ bool Base58::decode (const char* psz, Blob& vchRet, Alphabet const& alphabet) bnChar.setuint (p1 - alphabet.chars()); if (!BN_mul (&bn, &bn, &bn58, pctx)) - throw bignum_error ("DecodeBase58 : BN_mul failed"); + throw std::runtime_error ("DecodeBase58 : BN_mul failed"); bn += bnChar; } diff --git a/src/ripple/unity/sslutil.h b/src/ripple/unity/sslutil.h index 7881722e7..194110e81 100644 --- a/src/ripple/unity/sslutil.h +++ b/src/ripple/unity/sslutil.h @@ -27,7 +27,6 @@ #include #include -#include #include #include #include