From fb4c6c150345c76c73de7cdfcb48caab34c5cab6 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 5 Nov 2019 18:44:16 -0500 Subject: [PATCH] Increase coverage for RC4 testing --- libtests/qtest/rc4.test | 7 ++++++- libtests/rc4.cc | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libtests/qtest/rc4.test b/libtests/qtest/rc4.test index 0207317c..25a5ab45 100644 --- a/libtests/qtest/rc4.test +++ b/libtests/qtest/rc4.test @@ -35,9 +35,14 @@ foreach my $key (@tests) {$td->FILE => "test$n.in"}); } +$td->runtest("other tests", + {$td->COMMAND => "rc4 other"}, + {$td->STRING => "passed\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + cleanup(); -$td->report(4 * scalar(@tests)); +$td->report(1 + (4 * scalar(@tests))); sub cleanup { diff --git a/libtests/rc4.cc b/libtests/rc4.cc index f877666f..d3f1c7fa 100644 --- a/libtests/rc4.cc +++ b/libtests/rc4.cc @@ -7,9 +7,29 @@ #include #include #include +#include + +static void other_tests() +{ + // Test cases not covered by the pipeline: string as key, convert + // in place + RC4 r(reinterpret_cast("quack")); + auto data = std::unique_ptr( + new unsigned char[6], std::default_delete()); + memcpy(data.get(), "potato", 6); + r.process(data.get(), 6); + assert(memcmp(data.get(), "\xa5\x6f\xe7\x27\x2b\x5c", 6) == 0); + std::cout << "passed" << std::endl; +} int main(int argc, char* argv[]) { + if ((argc == 2) && (strcmp(argv[1], "other") == 0)) + { + other_tests(); + return 0; + } + if (argc != 4) { std::cerr << "Usage: rc4 hex-key infile outfile" << std::endl;