diff options
author | Jack Lloyd <[email protected]> | 2017-12-29 11:52:18 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-12-29 11:52:18 -0500 |
commit | 33eead87d274cc35842389bbe591585a2cb675a3 (patch) | |
tree | 91bf2a13841a5a324832d180ebd97173bf4953ba /src/tests/test_ocsp.cpp | |
parent | 994db72e812421cd1c81f93ce43625d3dcd551e2 (diff) |
Move utils for reading test data files up to Test:: from OCSP
Diffstat (limited to 'src/tests/test_ocsp.cpp')
-rw-r--r-- | src/tests/test_ocsp.cpp | 36 |
1 files changed, 4 insertions, 32 deletions
diff --git a/src/tests/test_ocsp.cpp b/src/tests/test_ocsp.cpp index 2839d9ef5..6a872ae62 100644 --- a/src/tests/test_ocsp.cpp +++ b/src/tests/test_ocsp.cpp @@ -21,34 +21,6 @@ namespace Botan_Tests { class OCSP_Tests final : public Test { private: - std::vector<uint8_t> slurp_data_file(const std::string& path) - { - const std::string fsname = Test::data_file(path); - std::ifstream file(fsname.c_str(), std::ios::binary); - if(!file.good()) - { - throw Test_Error("Error reading from " + fsname); - } - - std::vector<uint8_t> contents; - - while(file.good()) - { - std::vector<uint8_t> buf(4096); - file.read(reinterpret_cast<char*>(buf.data()), buf.size()); - size_t got = file.gcount(); - - if(got == 0 && file.eof()) - { - break; - } - - contents.insert(contents.end(), buf.data(), buf.data() + got); - } - - return contents; - } - std::shared_ptr<const Botan::X509_Certificate> load_test_X509_cert(const std::string& path) { return std::make_shared<const Botan::X509_Certificate>(Test::data_file(path)); @@ -56,7 +28,7 @@ class OCSP_Tests final : public Test std::shared_ptr<const Botan::OCSP::Response> load_test_OCSP_resp(const std::string& path) { - return std::make_shared<const Botan::OCSP::Response>(slurp_data_file(path)); + return std::make_shared<const Botan::OCSP::Response>(Test::read_binary_data_file(path)); } Test::Result test_response_parsing() @@ -75,7 +47,7 @@ class OCSP_Tests final : public Test { try { - Botan::OCSP::Response resp(slurp_data_file(ocsp_input_path)); + Botan::OCSP::Response resp(Test::read_binary_data_file(ocsp_input_path)); result.test_success("Parsed input " + ocsp_input_path); } catch(Botan::Exception& e) @@ -93,7 +65,7 @@ class OCSP_Tests final : public Test try { - Botan::OCSP::Response resp1(slurp_data_file("x509/ocsp/resp1.der")); + Botan::OCSP::Response resp1(Test::read_binary_data_file("x509/ocsp/resp1.der")); const auto &certs1 = resp1.certificates(); if(result.test_eq("Expected count of certificates", certs1.size(), 1)) { @@ -105,7 +77,7 @@ class OCSP_Tests final : public Test result.test_eq("CN matches expected", matches, true); } - Botan::OCSP::Response resp2(slurp_data_file("x509/ocsp/resp2.der")); + Botan::OCSP::Response resp2(Test::read_binary_data_file("x509/ocsp/resp2.der")); const auto &certs2 = resp2.certificates(); result.test_eq("Expect no certificates", certs2.size(), 0); } |