diff options
author | Jack Lloyd <[email protected]> | 2018-11-17 16:23:51 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-11-23 11:15:25 -0500 |
commit | b909778857b3e0b7eb86ac26c818e5f25baaddbd (patch) | |
tree | f8a5c9cbec26310bbfc9077563892b04db158a48 /src/lib/prov/commoncrypto/commoncrypto.h | |
parent | c20a428ca2f7c1ef96e642f55bb898010444c499 (diff) |
Make exceptions easier to translate to error codes
Avoid throwing base Botan::Exception type, as it is difficult to
determine what the error is in that case.
Add Exception::error_code and Exception::error_type which allows
(for error code) more information about the error and (for error type)
allows knowing the error type without requiring a sequence of catches.
See GH #1742
Diffstat (limited to 'src/lib/prov/commoncrypto/commoncrypto.h')
-rw-r--r-- | src/lib/prov/commoncrypto/commoncrypto.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/lib/prov/commoncrypto/commoncrypto.h b/src/lib/prov/commoncrypto/commoncrypto.h index 958cbab7d..31fa110fc 100644 --- a/src/lib/prov/commoncrypto/commoncrypto.h +++ b/src/lib/prov/commoncrypto/commoncrypto.h @@ -24,14 +24,23 @@ typedef int32_t CCCryptorStatus; class BOTAN_PUBLIC_API(2, 0) CommonCrypto_Error final : public Exception { - std::string ccryptorstatus_to_string(CCCryptorStatus status); - public: CommonCrypto_Error(const std::string& what) : - Exception(what + " failed.") {} + Exception(what + " failed."), + m_rc(0) {} CommonCrypto_Error(const std::string& what, int32_t status) : - Exception(what + std::string(" failed. Status: ") + ccryptorstatus_to_string(status)) {} + Exception(what + std::string(" failed. Status: ") + ccryptorstatus_to_string(status)), + m_rc(status) {} + + ErrorType error_type() const noexcept override { return ErrorType::CommonCryptoError; } + + int error_code() const noexcept override { return m_rc; } + + private: + std::string ccryptorstatus_to_string(CCCryptorStatus status); + + int32_t m_rc; }; /* Cipher Modes */ |