diff options
author | Simon Warta <[email protected]> | 2015-07-15 00:13:13 +0200 |
---|---|---|
committer | Simon Warta <[email protected]> | 2015-07-15 13:51:20 +0200 |
commit | 7f3c4b1ab3837e75e890232bd2c3ecb9f6390732 (patch) | |
tree | 485ca6e7e6739693a3dd1cb32b812096cb633b75 /src/tests/catchy | |
parent | bac65bbdd0f28804f0418d41bd63fa39c290c68d (diff) |
Fix round_up
1. src/lib/codec/base64/base64.cpp: :
(round_up<size_t>(input_length, 3) / 3) * 4;
2. src/lib/codec/base64/base64.cpp: :
(round_up<size_t>(input_length, 4) * 3) / 4;
3. src/lib/filters/transform_filter.cpp: return round_up(target_size,
update_granularity);
4. src/lib/math/bigint/bigint.cpp:
m_reg.resize(round_up<size_t>(size, 8));
5. src/lib/math/bigint/bigint.cpp:
m_reg.resize(round_up<size_t>((length / WORD_BYTES) + 1, 8));
6. src/lib/math/numbertheory/mp_numth.cpp: BigInt z(BigInt::Positive,
round_up<size_t>(2*x_sw, 16));
7. src/lib/modes/cbc/cbc.cpp: return round_up(input_length,
cipher().block_size());
8. src/lib/modes/ecb/ecb.cpp: return round_up(input_length,
cipher().block_size());
9. src/lib/modes/xts/xts.cpp: return round_up(input_length,
cipher().block_size());
10. src/lib/pbkdf/pbkdf2/pbkdf2.cpp: const size_t blocks_needed =
round_up(out_len, prf_sz) / prf_sz;
11. src/lib/tls/tls_record.cpp: const size_t buf_size = round_up(
12. src/lib/utils/rounding.h:inline T round_up(T n, T align_to)
1. Reason for change
2. Reason for change
3. first argument cannot be 0 (`target_size = 1024`)
4. Is a bug in the current implementation iff `size = 0`
5. first argument cannot be 0
6. round_up should return 0 if `x_sw = 0`
7. ?
8. ?
9. ?
10. first argument cannot be 0 (`if(out_len == 0) return 0;`)
11. first argument is unlikely to be 0 (`iv_size + msg_length + mac_size
+ (block_size ? 1 : 0)`)
12. Implementation
Diffstat (limited to 'src/tests/catchy')
-rw-r--r-- | src/tests/catchy/test_utils.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/tests/catchy/test_utils.cpp b/src/tests/catchy/test_utils.cpp index 17c35a678..41eef3e45 100644 --- a/src/tests/catchy/test_utils.cpp +++ b/src/tests/catchy/test_utils.cpp @@ -3,5 +3,112 @@ #include "catch.hpp" +#include <botan/calendar.h> +#include <botan/internal/rounding.h> + using namespace Botan; +TEST_CASE("round_up strictly positive", "[utils]") + { + CHECK(( round_up( 1, 10) == 10 )); + CHECK(( round_up( 3, 10) == 10 )); + CHECK(( round_up( 9, 10) == 10 )); + CHECK(( round_up(10, 10) == 10 )); + + CHECK(( round_up( 1, 4) == 4 )); + CHECK(( round_up( 3, 4) == 4 )); + CHECK(( round_up( 4, 4) == 4 )); + CHECK(( round_up( 9, 4) == 12 )); + CHECK(( round_up(10, 4) == 12 )); + } + +/* +This was broken + +TEST_CASE("round_up strictly negative", "[utils]") + { + CHECK(( round_up( -1, 10) == 0 )); + CHECK(( round_up( -3, 10) == 0 )); + CHECK(( round_up( -9, 10) == 0 )); + CHECK(( round_up(-10, 10) == -10 )); + + CHECK(( round_up( -1, 3) == 0 )); + CHECK(( round_up( -3, 3) == -3 )); + CHECK(( round_up( -8, 3) == -3 )); + CHECK(( round_up( -9, 3) == -9 )); + CHECK(( round_up(-10, 3) == -9 )); + } +*/ + +TEST_CASE("round_up zero", "[utils]") + { + CHECK(( round_up(0, 2) == 0 )); + CHECK(( round_up(0, 10) == 0 )); + CHECK(( round_up(0, 1000) == 0 )); + CHECK(( round_up(0, 99999) == 0 )); + CHECK(( round_up(0, 2222222) == 0 )); + } + +TEST_CASE("round_up invalid input", "[utils]") + { + CHECK_THROWS( round_up(3, 0) ); + CHECK_THROWS( round_up(5, 0) ); + } + +TEST_CASE("calendar_point constructor works", "[utils]") + { + auto point1 = calendar_point(1988, 04, 23, 14, 37, 28); + CHECK(( point1.year == 1988 )); + CHECK(( point1.month == 4 )); + CHECK(( point1.day == 23 )); + CHECK(( point1.hour == 14 )); + CHECK(( point1.minutes == 37 )); + CHECK(( point1.seconds == 28 )); + + auto point2 = calendar_point(1800, 01, 01, 0, 0, 0); + CHECK(( point2.year == 1800 )); + CHECK(( point2.month == 1 )); + CHECK(( point2.day == 1 )); + CHECK(( point2.hour == 0 )); + CHECK(( point2.minutes == 0 )); + CHECK(( point2.seconds == 0 )); + + auto point3 = calendar_point(2037, 12, 31, 24, 59, 59); + CHECK(( point3.year == 2037 )); + CHECK(( point3.month == 12 )); + CHECK(( point3.day == 31 )); + CHECK(( point3.hour == 24 )); + CHECK(( point3.minutes == 59 )); + CHECK(( point3.seconds == 59 )); + } + +TEST_CASE("calendar_point to stl timepoint and back", "[utils]") + { + { + auto in = calendar_point(1988, 04, 23, 14, 37, 28); + auto out = calendar_value(in.to_std_timepoint()); + CHECK(( out.year == 1988 )); + CHECK(( out.month == 4 )); + CHECK(( out.day == 23 )); + CHECK(( out.hour == 14 )); + CHECK(( out.minutes == 37 )); + CHECK(( out.seconds == 28 )); + } + + { + auto in = calendar_point(2037, 12, 31, 23, 59, 59); + auto out = calendar_value(in.to_std_timepoint()); + CHECK(( out.year == 2037 )); + CHECK(( out.month == 12 )); + CHECK(( out.day == 31 )); + CHECK(( out.hour == 23 )); + CHECK(( out.minutes == 59 )); + CHECK(( out.seconds == 59 )); + } + + SECTION("year too early") + { + auto in = calendar_point(1800, 01, 01, 0, 0, 0); + CHECK_THROWS( in.to_std_timepoint() ); + } + } |