| 1 | // |
| 2 | // CryptoException.cpp |
| 3 | // |
| 4 | // |
| 5 | // Library: Crypto |
| 6 | // Package: Crypto |
| 7 | // Module: CryptoException |
| 8 | // |
| 9 | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. |
| 10 | // and Contributors. |
| 11 | // |
| 12 | // SPDX-License-Identifier: BSL-1.0 |
| 13 | // |
| 14 | |
| 15 | |
| 16 | #include "Poco/Crypto/CryptoException.h" |
| 17 | #include "Poco/NumberFormatter.h" |
| 18 | #include <typeinfo> |
| 19 | |
| 20 | |
| 21 | namespace Poco { |
| 22 | namespace Crypto { |
| 23 | |
| 24 | |
| 25 | POCO_IMPLEMENT_EXCEPTION(CryptoException, Exception, "Crypto Exception" ) |
| 26 | |
| 27 | |
| 28 | OpenSSLException::OpenSSLException(int otherCode): CryptoException(otherCode) |
| 29 | { |
| 30 | setExtMessage(); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | OpenSSLException::OpenSSLException(const std::string& msg, int otherCode): CryptoException(msg, otherCode) |
| 35 | { |
| 36 | setExtMessage(); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | OpenSSLException::OpenSSLException(const std::string& msg, const std::string& arg, int otherCode): CryptoException(msg, arg, otherCode) |
| 41 | { |
| 42 | setExtMessage(); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | OpenSSLException::OpenSSLException(const std::string& msg, const Poco::Exception& exc, int otherCode): CryptoException(msg, exc, otherCode) |
| 47 | { |
| 48 | setExtMessage(); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | OpenSSLException::OpenSSLException(const OpenSSLException& exc): CryptoException(exc) |
| 53 | { |
| 54 | setExtMessage(); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | OpenSSLException::~OpenSSLException() throw() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | |
| 63 | OpenSSLException& OpenSSLException::operator = (const OpenSSLException& exc) |
| 64 | { |
| 65 | CryptoException::operator = (exc); |
| 66 | return *this; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | const char* OpenSSLException::name() const throw() |
| 71 | { |
| 72 | return "OpenSSLException" ; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | const char* OpenSSLException::className() const throw() |
| 77 | { |
| 78 | return typeid(*this).name(); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | Poco::Exception* OpenSSLException::clone() const |
| 83 | { |
| 84 | return new OpenSSLException(*this); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | void OpenSSLException::setExtMessage() |
| 89 | { |
| 90 | Poco::UInt64 e = static_cast<Poco::UInt64>(ERR_get_error()); |
| 91 | char buf[128] = { 0 }; |
| 92 | char* pErr = ERR_error_string(e, buf); |
| 93 | std::string err; |
| 94 | if (pErr) err = pErr; |
| 95 | else err = NumberFormatter::format(e); |
| 96 | |
| 97 | extendedMessage(err); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void OpenSSLException::rethrow() const |
| 102 | { |
| 103 | throw *this; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | } } // namespace Poco::Crypto |
| 108 | |