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

randombit / botan / 21753596263

06 Feb 2026 02:13PM UTC coverage: 90.063% (-0.01%) from 90.073%
21753596263

Pull #5289

github

web-flow
Merge 587099284 into 8ea0ca252
Pull Request #5289: Further misc header reductions, forward declarations, etc

102237 of 113517 relevant lines covered (90.06%)

11402137.11 hits per line

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

94.29
/src/lib/utils/uuid/uuid.cpp
1
/*
2
* UUID type
3
* (C) 2015,2018 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/uuid.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/hex.h>
12
#include <botan/rng.h>
13
#include <botan/internal/fmt.h>
14
#include <sstream>
15

16
namespace Botan {
17

18
UUID::UUID(RandomNumberGenerator& rng) {
7✔
19
   m_uuid.resize(16);
7✔
20
   rng.randomize(m_uuid.data(), m_uuid.size());
7✔
21

22
   // Mark as a random v4 UUID (RFC 4122 sec 4.4)
23
   m_uuid[6] = 0x40 | (m_uuid[6] & 0x0F);
7✔
24

25
   // Set reserved bits
26
   m_uuid[8] = 0x80 | (m_uuid[8] & 0x3F);
7✔
27
}
7✔
28

29
UUID::UUID(const std::vector<uint8_t>& blob) {
3✔
30
   if(blob.size() != 16) {
3✔
31
      throw Invalid_Argument("Bad UUID blob " + hex_encode(blob));
3✔
32
   }
33

34
   m_uuid = blob;
2✔
35
}
3✔
36

37
UUID::UUID(std::string_view uuid_str) {
2✔
38
   if(uuid_str.size() != 36 || uuid_str[8] != '-' || uuid_str[13] != '-' || uuid_str[18] != '-' ||
2✔
39
      uuid_str[23] != '-') {
2✔
40
      throw Invalid_Argument(fmt("Bad UUID '{}'", uuid_str));
×
41
   }
42

43
   std::string just_hex;
2✔
44
   for(const char c : uuid_str) {
74✔
45
      if(c == '-') {
72✔
46
         continue;
8✔
47
      }
48

49
      just_hex += c;
136✔
50
   }
51

52
   m_uuid = hex_decode(just_hex);
2✔
53

54
   if(m_uuid.size() != 16) {
2✔
55
      throw Invalid_Argument(fmt("Bad UUID '{}'", uuid_str));
×
56
   }
57
}
2✔
58

59
std::string UUID::to_string() const {
9✔
60
   if(!is_valid()) {
9✔
61
      throw Invalid_State("UUID object is empty cannot convert to string");
1✔
62
   }
63

64
   const std::string raw = hex_encode(m_uuid);
8✔
65

66
   std::ostringstream formatted;
8✔
67

68
   for(size_t i = 0; i != raw.size(); ++i) {
264✔
69
      if(i == 8 || i == 12 || i == 16 || i == 20) {
256✔
70
         formatted << "-";
32✔
71
      }
72
      formatted << raw[i];
256✔
73
   }
74

75
   return formatted.str();
8✔
76
}
8✔
77

78
}  // namespace Botan
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

© 2026 Coveralls, Inc