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

randombit / botan / 5134090420

31 May 2023 03:12PM UTC coverage: 91.721% (-0.3%) from 91.995%
5134090420

push

github

randombit
Merge GH #3565 Disable noisy/pointless pylint warnings

76048 of 82912 relevant lines covered (91.72%)

11755290.1 hits per line

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

53.33
/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) {
×
61
            result.test_failure("TPM problem", e.what());
×
62
         }
×
63

64
         return {result};
×
65
      }
1✔
66
};
67

68
BOTAN_REGISTER_TEST("tpm", "tpm_tests", TPM_Tests);
69

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

75
         const Botan::UUID empty_uuid;
1✔
76

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

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

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

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

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

91
         return {result};
3✔
92
      }
4✔
93
};
94

95
BOTAN_REGISTER_TEST("tpm", "tpm_uuid", UUID_Tests);
96

97
#endif
98

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