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