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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

55.81
/src/tests/test_tpm.cpp
1
/*
2
* (C) 2016 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_TPM)
10
   #include <botan/tpm.h>
11
   #include <botan/uuid.h>
12
#endif
13

14
namespace Botan_Tests {
15

16
#if defined(BOTAN_HAS_TPM)
17

18
class TPM_Tests final : public Test {
×
19
   public:
20
      static std::string pin_cb(const std::string&) { return "123456"; }
×
21

22
      std::vector<Test::Result> run() override {
1✔
23
         Test::Result result("TPM");
1✔
24

25
         std::unique_ptr<Botan::TPM_Context> ctx;
1✔
26

27
         try {
1✔
28
            ctx.reset(new Botan::TPM_Context(pin_cb, nullptr));
2✔
29
            result.test_success("Created TPM context");
×
30
         } catch(Botan::TPM_Error& e) {
1✔
31
            result.test_success("Error conecting to TPM, skipping tests");
1✔
32
            return {result};
2✔
33
         }
1✔
34

35
         try {
×
36
            result.test_note("TPM counter is " + std::to_string(ctx->current_counter()));
×
37

38
            Botan::TPM_RNG rng(*ctx);
×
39
            Botan::secure_vector<uint8_t> output = rng.random_vec(16);
×
40

41
            result.test_ne("TPM RNG output not all zeros", output, std::vector<uint8_t>(16));
×
42

43
            Botan::TPM_PrivateKey key(*ctx, 1024, nullptr);
×
44
            result.test_success("Created TPM RSA key");
×
45

46
            std::vector<uint8_t> blob = key.export_blob();
×
47

48
            // Has to be at least as large as the key
49
            result.test_gte("Blob size is reasonable", blob.size(), 1024 / 8);
×
50

51
            std::vector<std::string> registered_keys = Botan::TPM_PrivateKey::registered_keys(*ctx);
×
52

53
            for(auto url : registered_keys) {
×
54
               result.test_note("TPM registered key " + url);
×
55
            }
×
56

57
            // TODO export public key
58
            // TODO generate a signature, verify it
59
            // TODO test key registration mechanisms
60
         } catch(Botan::Exception& e) { result.test_failure("TPM problem", e.what()); }
×
61

62
         return {result};
×
63
      }
1✔
64
};
65

66
BOTAN_REGISTER_TEST("tpm", "tpm_tests", TPM_Tests);
67

68
class UUID_Tests final : public Test {
×
69
   public:
70
      std::vector<Test::Result> run() override {
1✔
71
         Test::Result result("UUID");
1✔
72

73
         const Botan::UUID empty_uuid;
1✔
74

75
         result.test_eq("Uninitialized UUID not valid", empty_uuid.is_valid(), false);
1✔
76

77
         const Botan::UUID random_uuid(Test::rng());
1✔
78
         result.test_eq("Random UUID is valid", empty_uuid.is_valid(), false);
1✔
79

80
         const Botan::UUID binary_copy(random_uuid.binary_value());
1✔
81
         result.confirm("UUID copied by binary equals original", random_uuid == binary_copy);
2✔
82

83
         std::string uuid_str = random_uuid.to_string();
1✔
84
         result.test_eq("UUID string in expected format", uuid_str.size(), 36);
1✔
85

86
         const Botan::UUID string_copy(random_uuid.to_string());
1✔
87
         result.confirm("UUID copied by string equals original", random_uuid == string_copy);
2✔
88

89
         return {result};
3✔
90
      }
4✔
91
};
92

93
BOTAN_REGISTER_TEST("tpm", "tpm_uuid", UUID_Tests);
94

95
#endif
96

97
}
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