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

randombit / botan / 20579846577

29 Dec 2025 06:24PM UTC coverage: 90.415% (+0.2%) from 90.243%
20579846577

push

github

web-flow
Merge pull request #5167 from randombit/jack/src-size-reductions

Changes to reduce unnecessary inclusions

101523 of 112285 relevant lines covered (90.42%)

12817276.56 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
#define BOTAN_NO_DEPRECATED_WARNINGS
8

9
#include "tests.h"
10

11
#include <botan/rng.h>
12
#include <botan/symkey.h>
13

14
namespace Botan_Tests {
15

16
namespace {
17

18
Test::Result test_from_rng() {
1✔
19
   Test::Result result("OctetString");
1✔
20

21
   auto rng = Test::new_rng("octet_string_from_rng");
1✔
22

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

26
   return result;
1✔
27
}
2✔
28

29
Test::Result test_from_hex() {
1✔
30
   Test::Result result("OctetString");
1✔
31

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

35
   return result;
1✔
36
}
1✔
37

38
Test::Result test_from_byte() {
1✔
39
   Test::Result result("OctetString");
1✔
40

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

46
   return result;
1✔
47
}
3✔
48

49
Test::Result test_odd_parity() {
1✔
50
   Test::Result result("OctetString");
1✔
51

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

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

62
   return result;
1✔
63
}
4✔
64

65
Test::Result test_to_string() {
1✔
66
   Test::Result result("OctetString");
1✔
67

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

71
   return result;
1✔
72
}
1✔
73

74
Test::Result test_xor() {
1✔
75
   Test::Result result("OctetString");
1✔
76

77
   const Botan::OctetString os1("0000000000000000");
1✔
78
   const Botan::OctetString os2("FFFFFFFFFFFFFFFF");
1✔
79

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

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

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

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

95
   return result;
1✔
96
}
5✔
97

98
Test::Result test_equality() {
1✔
99
   Test::Result result("OctetString");
1✔
100

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

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

110
   return result;
1✔
111
}
2✔
112

113
Test::Result test_append() {
1✔
114
   Test::Result result("OctetString");
1✔
115

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

120
   const Botan::OctetString append_result = os1 + os2;
1✔
121

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

124
   return result;
1✔
125
}
4✔
126

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

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

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

149
         return results;
1✔
150
      }
2✔
151
};
152

153
BOTAN_REGISTER_TEST("utils", "octetstring", OctetString_Tests);
154

155
}  // namespace
156

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