aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Crypto/src/CryptoException.cpp
blob: e30940d2294554ba72424fd867f62b8228666e1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// CryptoException.cpp
//
//
// Library: Crypto
// Package: Crypto
// Module:  CryptoException
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#include "Poco/Crypto/CryptoException.h"
#include "Poco/NumberFormatter.h"
#include <typeinfo>
#include <openssl/err.h>


namespace Poco {
namespace Crypto {


POCO_IMPLEMENT_EXCEPTION(CryptoException, Exception, "Crypto Exception")


OpenSSLException::OpenSSLException(int otherCode): CryptoException(otherCode)
{
	setExtMessage();
}


OpenSSLException::OpenSSLException(const std::string& msg, int otherCode): CryptoException(msg, otherCode)
{
	setExtMessage();
}


OpenSSLException::OpenSSLException(const std::string& msg, const std::string& arg, int otherCode): CryptoException(msg, arg, otherCode)
{
	setExtMessage();
}


OpenSSLException::OpenSSLException(const std::string& msg, const Poco::Exception& exc, int otherCode): CryptoException(msg, exc, otherCode)
{
	setExtMessage();
}


OpenSSLException::OpenSSLException(const OpenSSLException& exc): CryptoException(exc)
{
	setExtMessage();
}


OpenSSLException::~OpenSSLException() noexcept
{
}


OpenSSLException& OpenSSLException::operator = (const OpenSSLException& exc)
{
	CryptoException::operator = (exc);
	return *this;
}


const char* OpenSSLException::name() const noexcept
{
	return "OpenSSLException";
}


const char* OpenSSLException::className() const noexcept
{
	return typeid(*this).name();
}


Poco::Exception* OpenSSLException::clone() const
{
	return new OpenSSLException(*this);
}


void OpenSSLException::setExtMessage()
{
	Poco::UInt64 e = static_cast<Poco::UInt64>(ERR_get_error());
	char buf[128] = { 0 };
	char* pErr = ERR_error_string(static_cast<unsigned long>(e), buf);
	std::string err;
	if (pErr) err = pErr;
	else err = NumberFormatter::format(e);

	extendedMessage(err);
}


void OpenSSLException::rethrow() const
{
	throw *this;
}


} } // namespace Poco::Crypto