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

randombit / botan / 5133556677

31 May 2023 02:11PM UTC coverage: 91.735% (-0.3%) from 92.012%
5133556677

Pull #3568

github

web-flow
Merge de48a2eb6 into 1cbeffafb
Pull Request #3568: Change clang-format AllowShortBlocksOnASingleLine from true to Empty

76059 of 82912 relevant lines covered (91.73%)

12004312.75 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 "test_rng.h"
8
#include "tests.h"
9

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

15
namespace Botan_Tests {
16

17
namespace {
18

19
#if defined(BOTAN_HAS_CRYPTO_BOX)
20

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

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

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

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

35
         Fixed_Output_RNG salt_rng(salt);
18✔
36

37
         BOTAN_DIAGNOSTIC_PUSH
18✔
38
         BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
18✔
39

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

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

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

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

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

59
         BOTAN_DIAGNOSTIC_POP
18✔
60

61
         return result;
18✔
62
      }
90✔
63
};
64

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

67
#endif
68

69
}  // namespace
70

71
}  // 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

© 2025 Coveralls, Inc