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
21namespace Poco {
22namespace Crypto {
23
24
25POCO_IMPLEMENT_EXCEPTION(CryptoException, Exception, "Crypto Exception")
26
27
28OpenSSLException::OpenSSLException(int otherCode): CryptoException(otherCode)
29{
30 setExtMessage();
31}
32
33
34OpenSSLException::OpenSSLException(const std::string& msg, int otherCode): CryptoException(msg, otherCode)
35{
36 setExtMessage();
37}
38
39
40OpenSSLException::OpenSSLException(const std::string& msg, const std::string& arg, int otherCode): CryptoException(msg, arg, otherCode)
41{
42 setExtMessage();
43}
44
45
46OpenSSLException::OpenSSLException(const std::string& msg, const Poco::Exception& exc, int otherCode): CryptoException(msg, exc, otherCode)
47{
48 setExtMessage();
49}
50
51
52OpenSSLException::OpenSSLException(const OpenSSLException& exc): CryptoException(exc)
53{
54 setExtMessage();
55}
56
57
58OpenSSLException::~OpenSSLException() throw()
59{
60}
61
62
63OpenSSLException& OpenSSLException::operator = (const OpenSSLException& exc)
64{
65 CryptoException::operator = (exc);
66 return *this;
67}
68
69
70const char* OpenSSLException::name() const throw()
71{
72 return "OpenSSLException";
73}
74
75
76const char* OpenSSLException::className() const throw()
77{
78 return typeid(*this).name();
79}
80
81
82Poco::Exception* OpenSSLException::clone() const
83{
84 return new OpenSSLException(*this);
85}
86
87
88void 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
101void OpenSSLException::rethrow() const
102{
103 throw *this;
104}
105
106
107} } // namespace Poco::Crypto
108