From 507d926da825fbc1d9d74b4517dbab47702c66b9 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 1 Sep 2016 13:40:26 -0400 Subject: Cipher_Mode API improvements The Cipher_Mode::update API is more general than needed to just support ciphers (this is due to it previously being an API of Transform which before 8b85b780515 was Cipher_Mode's base class) Define a less general interface `process` which either processes the blocks in-place, producing exactly as much output as there was input, or (SIV/CCM case) saves the entire message for processing in `finish`. These two uses cover all current or anticipated cipher modes. Leaves `update` for compatability with existing callers; all that is needed is an inline function forwarding to `process`. Removes the return type from `start` - in all cipher implementations, this always returned an empty vector. Adds BOTAN_ARG_CHECK macro; right now BOTAN_ASSERT is being used for argument checking in some places, which is not right at all. --- src/lib/utils/assert.h | 13 +++++++++++++ src/lib/utils/exceptn.h | 10 ++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'src/lib/utils') diff --git a/src/lib/utils/assert.h b/src/lib/utils/assert.h index f80f9b170..c49ae62ee 100644 --- a/src/lib/utils/assert.h +++ b/src/lib/utils/assert.h @@ -34,6 +34,19 @@ BOTAN_NORETURN void BOTAN_DLL assertion_failure(const char* expr_str, __LINE__); \ } while(0) +/** +* Make an assertion +*/ +#define BOTAN_ASSERT_NOMSG(expr) \ + do { \ + if(!(expr)) \ + Botan::assertion_failure(#expr, \ + "", \ + BOTAN_CURRENT_FUNCTION, \ + __FILE__, \ + __LINE__); \ + } while(0) + /** * Assert that value1 == value2 */ diff --git a/src/lib/utils/exceptn.h b/src/lib/utils/exceptn.h index 193d78ce9..a3cb11f81 100644 --- a/src/lib/utils/exceptn.h +++ b/src/lib/utils/exceptn.h @@ -29,14 +29,20 @@ class BOTAN_DLL Exception : public std::exception }; /** -* An invalid argument which caused +* An invalid argument */ class BOTAN_DLL Invalid_Argument : public Exception { public: explicit Invalid_Argument(const std::string& msg) : Exception("Invalid argument", msg) {} - }; + + explicit Invalid_Argument(const std::string& msg, const std::string& where) : + Exception("Invalid argument", msg + " in " + where) {} +}; + +#define BOTAN_ARG_CHECK(expr) \ + do { if(!(expr)) throw Invalid_Argument(#expr, BOTAN_CURRENT_FUNCTION); } while(0) /** * Unsupported_Argument Exception -- cgit v1.2.3