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

randombit / botan / 21789150028

08 Feb 2026 12:09AM UTC coverage: 90.068% (-0.005%) from 90.073%
21789150028

push

github

web-flow
Merge pull request #5295 from randombit/jack/header-patrol-3

Reduce header dependencies in tests and cli

102234 of 113507 relevant lines covered (90.07%)

11572088.66 hits per line

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

96.63
/src/tests/test_octetstring.cpp
1
/*
2
* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#include <botan/rng.h>
10
#include <botan/symkey.h>
11

12
namespace Botan_Tests {
13

14
namespace {
15

16
Test::Result test_from_rng() {
1✔
17
   Test::Result result("OctetString");
1✔
18

19
   auto rng = Test::new_rng("octet_string_from_rng");
1✔
20

21
   const Botan::OctetString os(*rng, 32);
1✔
22
   result.test_eq("length is 32 bytes", os.size(), 32);
1✔
23

24
   return result;
1✔
25
}
2✔
26

27
Test::Result test_from_hex() {
1✔
28
   Test::Result result("OctetString");
1✔
29

30
   const Botan::OctetString os("0123456789ABCDEF");
1✔
31
   result.test_eq("length is 8 bytes", os.size(), 8);
1✔
32

33
   return result;
1✔
34
}
1✔
35

36
Test::Result test_from_byte() {
1✔
37
   Test::Result result("OctetString");
1✔
38

39
   auto rng = Test::new_rng("octet_string_from_byte");
1✔
40
   auto rand_bytes = rng->random_vec(8);
1✔
41
   const Botan::OctetString os(rand_bytes.data(), rand_bytes.size());
1✔
42
   result.test_eq("length is 8 bytes", os.size(), 8);
1✔
43

44
   return result;
1✔
45
}
3✔
46

47
Test::Result test_odd_parity() {
1✔
48
   Test::Result result("OctetString");
1✔
49

50
   Botan::OctetString os("FFFFFFFFFFFFFFFF");
1✔
51
   os.set_odd_parity();
1✔
52
   const Botan::OctetString expected("FEFEFEFEFEFEFEFE");
1✔
53
   result.test_eq("odd parity set correctly", os, expected);
1✔
54

55
   Botan::OctetString os2("EFCBDA4FAA997F63");
1✔
56
   os2.set_odd_parity();
1✔
57
   const Botan::OctetString expected2("EFCBDA4FAB987F62");
1✔
58
   result.test_eq("odd parity set correctly", os2, expected2);
1✔
59

60
   return result;
1✔
61
}
4✔
62

63
Test::Result test_to_string() {
1✔
64
   Test::Result result("OctetString");
1✔
65

66
   const Botan::OctetString os("0123456789ABCDEF");
1✔
67
   result.test_eq("OctetString::to_string() returns correct string", os.to_string(), "0123456789ABCDEF");
2✔
68

69
   return result;
1✔
70
}
1✔
71

72
Test::Result test_xor() {
1✔
73
   Test::Result result("OctetString");
1✔
74

75
   const Botan::OctetString os1("0000000000000000");
1✔
76
   const Botan::OctetString os2("FFFFFFFFFFFFFFFF");
1✔
77

78
   Botan::OctetString xor_result = os1 ^ os2;
1✔
79
   result.test_eq("OctetString XOR operations works as expected", xor_result, os2);
1✔
80

81
   xor_result = os1;
1✔
82
   xor_result ^= os2;
1✔
83
   result.test_eq("OctetString XOR operations works as expected", xor_result, os2);
1✔
84

85
   xor_result = os2 ^ os2;  // NOLINT(*-redundant-expression)
2✔
86
   result.test_eq("OctetString XOR operations works as expected", xor_result, os1);
1✔
87

88
   const Botan::OctetString os3("0123456789ABCDEF");
1✔
89
   xor_result = os3 ^ os2;
2✔
90
   const Botan::OctetString expected("FEDCBA9876543210");
1✔
91
   result.test_eq("OctetString XOR operations works as expected", xor_result, expected);
1✔
92

93
   return result;
1✔
94
}
5✔
95

96
Test::Result test_equality() {
1✔
97
   Test::Result result("OctetString");
1✔
98

99
   const Botan::OctetString os1("0000000000000000");
1✔
100
   const Botan::OctetString& os1_copy = os1;
1✔
101
   const Botan::OctetString os2("FFFFFFFFFFFFFFFF");
1✔
102
   const Botan::OctetString& os2_copy = os2;
1✔
103

104
   result.confirm("OctetString equality operations works as expected", os1 == os1_copy);
2✔
105
   result.confirm("OctetString equality operations works as expected", os2 == os2_copy);
2✔
106
   result.confirm("OctetString equality operations works as expected", os1 != os2);
2✔
107

108
   return result;
1✔
109
}
2✔
110

111
Test::Result test_append() {
1✔
112
   Test::Result result("OctetString");
1✔
113

114
   const Botan::OctetString os1("0000");
1✔
115
   const Botan::OctetString os2("FFFF");
1✔
116
   const Botan::OctetString expected("0000FFFF");
1✔
117

118
   const Botan::OctetString append_result = os1 + os2;
1✔
119

120
   result.test_eq("OctetString append operations works as expected", append_result, expected);
1✔
121

122
   return result;
1✔
123
}
4✔
124

125
class OctetString_Tests final : public Test {
1✔
126
   public:
127
      std::vector<Test::Result> run() override {
1✔
128
         std::vector<Test::Result> results;
1✔
129

130
         std::vector<std::function<Test::Result()>> fns = {test_from_rng,
1✔
131
                                                           test_from_hex,
132
                                                           test_from_byte,
133
                                                           test_odd_parity,
134
                                                           test_to_string,
135
                                                           test_xor,
136
                                                           test_equality,
137
                                                           test_append};
9✔
138

139
         for(size_t i = 0; i != fns.size(); ++i) {
9✔
140
            try {
8✔
141
               results.push_back(fns[i]());
16✔
142
            } catch(std::exception& e) {
×
143
               results.push_back(Test::Result::Failure("OctetString tests " + std::to_string(i), e.what()));
×
144
            }
×
145
         }
146

147
         return results;
1✔
148
      }
2✔
149
};
150

151
BOTAN_REGISTER_TEST("utils", "octetstring", OctetString_Tests);
152

153
}  // namespace
154

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

© 2026 Coveralls, Inc