aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/prov/tpm/uuid.h6
-rw-r--r--src/tests/test_tpm.cpp29
2 files changed, 32 insertions, 3 deletions
diff --git a/src/lib/prov/tpm/uuid.h b/src/lib/prov/tpm/uuid.h
index 0094f4f83..0cfe6a46f 100644
--- a/src/lib/prov/tpm/uuid.h
+++ b/src/lib/prov/tpm/uuid.h
@@ -86,14 +86,14 @@ class UUID
return h;
}
- const std::vector<uint8_t> binary_value() const { return m_uuid; }
+ const std::vector<uint8_t>& binary_value() const { return m_uuid; }
- bool operator==(const UUID& other)
+ bool operator==(const UUID& other) const
{
return m_uuid == other.m_uuid;
}
- bool operator!=(const UUID& other) { return !(*this == other); }
+ bool operator!=(const UUID& other) const { return !(*this == other); }
bool is_valid() const { return m_uuid.size() == 16; }
diff --git a/src/tests/test_tpm.cpp b/src/tests/test_tpm.cpp
index 039dd2551..267af4e89 100644
--- a/src/tests/test_tpm.cpp
+++ b/src/tests/test_tpm.cpp
@@ -8,6 +8,7 @@
#if defined(BOTAN_HAS_TPM)
#include <botan/tpm.h>
+ #include <botan/uuid.h>
#endif
namespace Botan_Tests {
@@ -80,6 +81,34 @@ class TPM_Tests : public Test
BOTAN_REGISTER_TEST("tpm", TPM_Tests);
+class UUID_Tests : public Test
+ {
+ public:
+ std::vector<Test::Result> run() override
+ {
+ Test::Result result("UUID");
+
+ const Botan::UUID empty_uuid;
+
+ result.test_eq("Uninitialized UUID not valid", empty_uuid.is_valid(), false);
+
+ const Botan::UUID random_uuid(Test::rng());
+ result.test_eq("Random UUID is valid", empty_uuid.is_valid(), false);
+
+ const Botan::UUID binary_copy(random_uuid.binary_value());
+ result.confirm("UUID copied by binary equals original", random_uuid == binary_copy);
+
+ std::string uuid_str = random_uuid.to_string();
+
+ const Botan::UUID string_copy(random_uuid.to_string());
+ result.confirm("UUID copied by string equals original", random_uuid == string_copy);
+
+ return {result};
+ }
+ };
+
+BOTAN_REGISTER_TEST("tpm_uuid", UUID_Tests);
+
#endif
}