Enigma 3.2.2
A Simple, Reliable and Efficient Encryption Tool
Loading...
Searching...
No Matches
CryptoPPUtils.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef ENIGMA_CRYPTOPP_UTILS_H
3#define ENIGMA_CRYPTOPP_UTILS_H
4#include <Core/Core.hpp>
5#include <cryptlib.h>
6
8
9class CryptoPPUtils final {
11
12 public:
13 /*
14 * Converts Crypto++ ErrorType into std::string
15 */
16 static const std::string GetErrorString(const enum CryptoPP::Exception::ErrorType error_type) noexcept {
17#define CASE_RETURN(e) \
18 case CryptoPP::Exception::ErrorType::e: \
19 return #e
20
21 switch (error_type) {
23 CASE_RETURN(NOT_IMPLEMENTED);
25 CASE_RETURN(INVALID_ARGUMENT);
27 CASE_RETURN(CANNOT_FLUSH);
29 CASE_RETURN(DATA_INTEGRITY_CHECK_FAILED);
31 CASE_RETURN(INVALID_DATA_FORMAT);
33 CASE_RETURN(IO_ERROR);
35 default:
36 CASE_RETURN(OTHER_ERROR);
37 }
38#undef CASE_RETURN
39 }
40
41 static const std::string GetErrorReason(const enum CryptoPP::Exception::ErrorType error_type) {
42 using ErrorType = CryptoPP::Exception::ErrorType;
43#define CASE_RETURN(c, ret) \
44 case c: \
45 return ret
46
47 switch (error_type) {
48 CASE_RETURN(ErrorType::INVALID_ARGUMENT, "An invalid argument was detected");
49 CASE_RETURN(ErrorType::CANNOT_FLUSH, "BufferedTransformation received a Flush(true) signal but can't flush buffers");
50 CASE_RETURN(ErrorType::DATA_INTEGRITY_CHECK_FAILED, "Data integerity check, such as CRC or MAC, failed");
51 CASE_RETURN(ErrorType::INVALID_DATA_FORMAT, "Input data was received that did not conform to expected format");
52 CASE_RETURN(ErrorType::IO_ERROR, "Error reading from input device or writing to output device");
53 default:
54 return "<unknown crypto++ error>";
55 }
56#undef CASE_RETURN
57 }
58
59 static const std::string GetFullErrorMessage(const CryptoPP::Exception& e) {
60 std::ostringstream oss{};
61 oss << "Error Type: " << GetErrorString(e.GetErrorType()) << '\n'
62 << "Message: " << e.GetWhat() << '\n'
63 << "Reason: " << GetErrorReason(e.GetErrorType());
64 return oss.str();
65 }
66};
67
69#endif // !ENIGMA_CRYPTOPP_UTILS_H
#define CASE_RETURN(e)
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition Macros.hpp:13
#define NS_ENIGMA_END
Definition Macros.hpp:14
#define ENIGMA_STATIC_CLASS(Class)
Makes a class static, which will prevent creating instances from it and only use it as Class::Func()....
Definition Macros.hpp:120
static const std::string GetErrorString(const enum CryptoPP::Exception::ErrorType error_type) noexcept
static const std::string GetFullErrorMessage(const CryptoPP::Exception &e)
static const std::string GetErrorReason(const enum CryptoPP::Exception::ErrorType error_type)