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

randombit / botan / 6436313551

06 Oct 2023 08:45PM UTC coverage: 91.704% (+0.002%) from 91.702%
6436313551

push

github

web-flow
Merge pull request #3730 from randombit/jack/update-xlc

Update XLC build configuration

79958 of 87191 relevant lines covered (91.7%)

8500255.31 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
#define BOTAN_NO_DEPRECATED_WARNINGS
8

9
#include "test_rng.h"
10
#include "tests.h"
11

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

17
namespace Botan_Tests {
18

19
namespace {
20

21
#if defined(BOTAN_HAS_CRYPTO_BOX)
22

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

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

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

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

37
         Fixed_Output_RNG salt_rng(salt);
18✔
38

39
         BOTAN_DIAGNOSTIC_PUSH
18✔
40
         BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
18✔
41

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

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

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

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

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

61
         BOTAN_DIAGNOSTIC_POP
18✔
62

63
         return result;
18✔
64
      }
90✔
65
};
66

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

69
#endif
70

71
}  // namespace
72

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