• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 21794448852

08 Feb 2026 12:09AM UTC coverage: 90.065% (-0.008%) from 90.073%
21794448852

push

github

web-flow
Merge pull request #5295 from randombit/jack/header-patrol-3

Reduce header dependencies in tests and cli

102230 of 113507 relevant lines covered (90.06%)

11492365.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.29
/src/tests/test_cryptobox.cpp
1
/*
2
* (C) 2014,2015,2018 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_CRYPTO_BOX)
10
   #include "test_rng.h"
11
   #include <botan/cryptobox.h>
12
   #include <botan/exceptn.h>
13
   #include <botan/pem.h>
14
#endif
15

16
namespace Botan_Tests {
17

18
namespace {
19

20
#if defined(BOTAN_HAS_CRYPTO_BOX)
21

22
class Cryptobox_KAT final : public Text_Based_Test {
×
23
   public:
24
      Cryptobox_KAT() : Text_Based_Test("cryptobox.vec", "Input,Passphrase,Salt,Output") {}
2✔
25

26
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) override {
18✔
27
         Test::Result result("Cryptobox");
18✔
28

29
         const std::string password = vars.get_req_str("Passphrase");
18✔
30
         const std::vector<uint8_t> input = vars.get_req_bin("Input");
18✔
31
         const std::vector<uint8_t> salt = vars.get_req_bin("Salt");
18✔
32
         const std::vector<uint8_t> expected = vars.get_req_bin("Output");
18✔
33

34
         const std::string expected_pem = Botan::PEM_Code::encode(expected, "BOTAN CRYPTOBOX MESSAGE");
18✔
35

36
         Fixed_Output_RNG salt_rng(salt);
18✔
37

38
         BOTAN_DIAGNOSTIC_PUSH
18✔
39
         BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
18✔
40

41
         const std::string ciphertext = Botan::CryptoBox::encrypt(input.data(), input.size(), password, salt_rng);
18✔
42

43
         result.test_eq("encryption is expected value", ciphertext, expected_pem);
18✔
44

45
         result.test_eq("decryption works", Botan::CryptoBox::decrypt_bin(ciphertext, password), input);
36✔
46

47
         // Now corrupt a bit and ensure it fails
48
         try {
18✔
49
            const std::vector<uint8_t> corrupted = Test::mutate_vec(expected, this->rng());
18✔
50
            const std::string corrupted_pem = Botan::PEM_Code::encode(corrupted, "BOTAN CRYPTOBOX MESSAGE");
18✔
51

52
            Botan::CryptoBox::decrypt(corrupted_pem, password);
18✔
53
            result.test_failure("Decrypted corrupted cryptobox message", corrupted);
18✔
54
         } catch(Botan::Decoding_Error&) {
36✔
55
            result.test_success("Rejected corrupted cryptobox message");
18✔
56
         } catch(Botan::Invalid_Argument&) {
18✔
57
            result.test_success("Rejected corrupted cryptobox message");
×
58
         }
×
59

60
         BOTAN_DIAGNOSTIC_POP
18✔
61

62
         return result;
18✔
63
      }
72✔
64
};
65

66
BOTAN_REGISTER_TEST("misc", "cryptobox", Cryptobox_KAT);
67

68
#endif
69

70
}  // namespace
71

72
}  // namespace Botan_Tests
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc