| 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 | #include <openssl/err.h> | 
|---|
| 20 |  | 
|---|
| 21 |  | 
|---|
| 22 | namespace Poco { | 
|---|
| 23 | namespace Crypto { | 
|---|
| 24 |  | 
|---|
| 25 |  | 
|---|
| 26 | POCO_IMPLEMENT_EXCEPTION(CryptoException, Exception, "Crypto Exception") | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | OpenSSLException::OpenSSLException(int otherCode): CryptoException(otherCode) | 
|---|
| 30 | { | 
|---|
| 31 | setExtMessage(); | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | OpenSSLException::OpenSSLException(const std::string& msg, int otherCode): CryptoException(msg, otherCode) | 
|---|
| 36 | { | 
|---|
| 37 | setExtMessage(); | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | OpenSSLException::OpenSSLException(const std::string& msg, const std::string& arg, int otherCode): CryptoException(msg, arg, otherCode) | 
|---|
| 42 | { | 
|---|
| 43 | setExtMessage(); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 |  | 
|---|
| 47 | OpenSSLException::OpenSSLException(const std::string& msg, const Poco::Exception& exc, int otherCode): CryptoException(msg, exc, otherCode) | 
|---|
| 48 | { | 
|---|
| 49 | setExtMessage(); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | OpenSSLException::OpenSSLException(const OpenSSLException& exc): CryptoException(exc) | 
|---|
| 54 | { | 
|---|
| 55 | setExtMessage(); | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 |  | 
|---|
| 59 | OpenSSLException::~OpenSSLException() throw() | 
|---|
| 60 | { | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 |  | 
|---|
| 64 | OpenSSLException& OpenSSLException::operator = (const OpenSSLException& exc) | 
|---|
| 65 | { | 
|---|
| 66 | CryptoException::operator = (exc); | 
|---|
| 67 | return *this; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | const char* OpenSSLException::name() const throw() | 
|---|
| 72 | { | 
|---|
| 73 | return "OpenSSLException"; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 |  | 
|---|
| 77 | const char* OpenSSLException::className() const throw() | 
|---|
| 78 | { | 
|---|
| 79 | return typeid(*this).name(); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 |  | 
|---|
| 83 | Poco::Exception* OpenSSLException::clone() const | 
|---|
| 84 | { | 
|---|
| 85 | return new OpenSSLException(*this); | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 |  | 
|---|
| 89 | void OpenSSLException::setExtMessage() | 
|---|
| 90 | { | 
|---|
| 91 | Poco::UInt64 e = static_cast<Poco::UInt64>(ERR_get_error()); | 
|---|
| 92 | char buf[128] = { 0 }; | 
|---|
| 93 | char* pErr = ERR_error_string(static_cast<unsigned long>(e), buf); | 
|---|
| 94 | std::string err; | 
|---|
| 95 | if (pErr) err = pErr; | 
|---|
| 96 | else err = NumberFormatter::format(e); | 
|---|
| 97 |  | 
|---|
| 98 | extendedMessage(err); | 
|---|
| 99 | } | 
|---|
| 100 |  | 
|---|
| 101 |  | 
|---|
| 102 | void OpenSSLException::rethrow() const | 
|---|
| 103 | { | 
|---|
| 104 | throw *this; | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 |  | 
|---|
| 108 | } } // namespace Poco::Crypto | 
|---|
| 109 |  | 
|---|