<commit_before>/*
* (C) 2014,2015 <NAME>
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include "tests.h"

#if defined(BOTAN_HAS_BCRYPT)
  #include <botan/bcrypt.h>
#endif

#if defined(BOTAN_HAS_PASSHASH9)
  #include <botan/passhash9.h>
#endif

namespace Botan_Tests {

namespace {

#if defined(BOTAN_HAS_BCRYPT)
class Bcrypt_Tests : public Text_Based_Test
   {
   public:
      Bcrypt_Tests() : Text_Based_Test("bcrypt.vec", "Password,Passhash") {}

      Test::Result run_one_test(const std::string&, const VarMap& vars) override
         {
         // Encoded as binary so we can test binary inputs
         const std::vector<uint8_t> password_vec = get_req_bin(vars, "Password");
         const std::string password(reinterpret_cast<const char*>(password_vec.data()),
                                    password_vec.size());

         const std::string passhash = get_req_str(vars, "Passhash");

         Test::Result result("bcrypt");
         result.test_eq("correct hash accepted", Botan::check_bcrypt(password, passhash), true);

         const size_t max_level = (Test::run_long_tests() ? 14 : 7);

         for(size_t level = 4; level <= max_level; ++level)
            {
            const std::string gen_hash = generate_bcrypt(password, Test::rng(), level);
            result.test_eq("generated hash accepted", Botan::check_bcrypt(password, gen_hash), true);
            }

         return result;
         }<commit_msg>Avoid long tests for each bcrypt password<commit_after>/*
* (C) 2014,2015 <NAME>
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include "tests.h"

#if defined(BOTAN_HAS_BCRYPT)
  #include <botan/bcrypt.h>
#endif

#if defined(BOTAN_HAS_PASSHASH9)
  #include <botan/passhash9.h>
#endif

namespace Botan_Tests {

namespace {

#if defined(BOTAN_HAS_BCRYPT)
class Bcrypt_Tests : public Text_Based_Test
   {
   public:
      Bcrypt_Tests() : Text_Based_Test("bcrypt.vec", "Password,Passhash") {}

      Test::Result run_one_test(const std::string&, const VarMap& vars) override
         {
         // Encoded as binary so we can test binary inputs
         const std::vector<uint8_t> password_vec = get_req_bin(vars, "Password");
         const std::string password(reinterpret_cast<const char*>(password_vec.data()),
                                    password_vec.size());

         const std::string passhash = get_req_str(vars, "Passhash");

         Test::Result result("bcrypt");
         result.test_eq("correct hash accepted", Botan::check_bcrypt(password, passhash), true);

         // self-test low levels for each test password
         for(size_t level = 4; level <= 6; ++level)
            {
            const std::string gen_hash = generate_bcrypt(password, Test::rng(), level);
            result.test_eq("generated hash accepted", Botan::check_bcrypt(password, gen_hash), true);
            }

         return result;
         }

      std::vector<Test::Result> run_final_tests()
         {
         Test::Result result("bcrypt");

         uint64_t start = Test::timestamp();

         const std::string password = "<PASSWORD>";

         const size_t max_level = (Test::run_long_tests() ? 15 : 10);

         for(size_t level = 4; level <= max_level; ++level)
            {
            const std::string gen_hash = generate_bcrypt(password, Test::rng(), level);
            result.test_eq("generated hash accepted", Botan::check_bcrypt(password, gen_hash), true);
            }

         result.set_ns_consumed(Test::timestamp() - start);

         return {result};
         }
{'fraction_non_alphanumeric': 0.12269938650306748, 'fraction_numerical': 0.009760178471834913, 'mean_word_length': 2.8946796959826275, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5367172', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1089, 'n_words': 254}