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

randombit / botan / 11844561993

14 Nov 2024 07:58PM UTC coverage: 91.178% (+0.1%) from 91.072%
11844561993

Pull #4435

github

web-flow
Merge 81dcb29da into e430f157a
Pull Request #4435: Test duration values ​​are now presented in seconds with six digits of precision. Tests without time measurements have been edited.

91856 of 100744 relevant lines covered (91.18%)

9311006.71 hits per line

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

96.19
/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/symkey.h>
12

13
namespace Botan_Tests {
14

15
namespace {
16

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

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

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

26
   result.end_timer();
1✔
27
   return result;
1✔
28
}
2✔
29

30
Test::Result test_from_hex() {
1✔
31
   Test::Result result("OctetString");
1✔
32
   result.start_timer();
1✔
33

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

37
   result.end_timer();
1✔
38
   return result;
1✔
39
}
1✔
40

41
Test::Result test_from_byte() {
1✔
42
   Test::Result result("OctetString");
1✔
43
   result.start_timer();
1✔
44

45
   auto rng = Test::new_rng("octet_string_from_byte");
1✔
46
   auto rand_bytes = rng->random_vec(8);
1✔
47
   Botan::OctetString os(rand_bytes.data(), rand_bytes.size());
1✔
48
   result.test_eq("length is 8 bytes", os.size(), 8);
1✔
49

50
   result.end_timer();
1✔
51
   return result;
1✔
52
}
3✔
53

54
Test::Result test_odd_parity() {
1✔
55
   Test::Result result("OctetString");
1✔
56
   result.start_timer();
1✔
57

58
   Botan::OctetString os("FFFFFFFFFFFFFFFF");
1✔
59
   os.set_odd_parity();
1✔
60
   Botan::OctetString expected("FEFEFEFEFEFEFEFE");
1✔
61
   result.test_eq("odd parity set correctly", os, expected);
1✔
62

63
   Botan::OctetString os2("EFCBDA4FAA997F63");
1✔
64
   os2.set_odd_parity();
1✔
65
   Botan::OctetString expected2("EFCBDA4FAB987F62");
1✔
66
   result.test_eq("odd parity set correctly", os2, expected2);
1✔
67

68
   result.end_timer();
1✔
69
   return result;
1✔
70
}
4✔
71

72
Test::Result test_to_string() {
1✔
73
   Test::Result result("OctetString");
1✔
74
   result.start_timer();
1✔
75

76
   Botan::OctetString os("0123456789ABCDEF");
1✔
77
   result.test_eq("OctetString::to_string() returns correct string", os.to_string(), "0123456789ABCDEF");
2✔
78

79
   result.end_timer();
1✔
80
   return result;
1✔
81
}
1✔
82

83
Test::Result test_xor() {
1✔
84
   Test::Result result("OctetString");
1✔
85
   result.start_timer();
1✔
86

87
   Botan::OctetString os1("0000000000000000");
1✔
88
   Botan::OctetString os2("FFFFFFFFFFFFFFFF");
1✔
89

90
   Botan::OctetString xor_result = os1 ^ os2;
1✔
91
   result.test_eq("OctetString XOR operations works as expected", xor_result, os2);
1✔
92

93
   xor_result = os1;
1✔
94
   xor_result ^= os2;
1✔
95
   result.test_eq("OctetString XOR operations works as expected", xor_result, os2);
1✔
96

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

100
   Botan::OctetString os3("0123456789ABCDEF");
1✔
101
   xor_result = os3 ^ os2;
2✔
102
   Botan::OctetString expected("FEDCBA9876543210");
1✔
103
   result.test_eq("OctetString XOR operations works as expected", xor_result, expected);
1✔
104

105
   result.end_timer();
1✔
106
   return result;
1✔
107
}
5✔
108

109
Test::Result test_equality() {
1✔
110
   Test::Result result("OctetString");
1✔
111
   result.start_timer();
1✔
112

113
   const Botan::OctetString os1("0000000000000000");
1✔
114
   const Botan::OctetString& os1_copy = os1;
1✔
115
   const Botan::OctetString os2("FFFFFFFFFFFFFFFF");
1✔
116
   const Botan::OctetString& os2_copy = os2;
1✔
117

118
   result.confirm("OctetString equality operations works as expected", os1 == os1_copy);
2✔
119
   result.confirm("OctetString equality operations works as expected", os2 == os2_copy);
2✔
120
   result.confirm("OctetString equality operations works as expected", os1 != os2);
2✔
121

122
   result.end_timer();
1✔
123
   return result;
1✔
124
}
2✔
125

126
Test::Result test_append() {
1✔
127
   Test::Result result("OctetString");
1✔
128
   result.start_timer();
1✔
129

130
   Botan::OctetString os1("0000");
1✔
131
   Botan::OctetString os2("FFFF");
1✔
132
   Botan::OctetString expected("0000FFFF");
1✔
133

134
   Botan::OctetString append_result = os1 + os2;
1✔
135

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

138
   result.end_timer();
1✔
139
   return result;
1✔
140
}
4✔
141

142
class OctetString_Tests final : public Test {
×
143
   public:
144
      std::vector<Test::Result> run() override {
1✔
145
         std::vector<Test::Result> results;
1✔
146

147
         std::vector<std::function<Test::Result()>> fns = {test_from_rng,
1✔
148
                                                           test_from_hex,
149
                                                           test_from_byte,
150
                                                           test_odd_parity,
151
                                                           test_to_string,
152
                                                           test_xor,
153
                                                           test_equality,
154
                                                           test_append};
9✔
155

156
         for(size_t i = 0; i != fns.size(); ++i) {
9✔
157
            try {
8✔
158
               results.push_back(fns[i]());
16✔
159
            } catch(std::exception& e) {
×
160
               results.push_back(Test::Result::Failure("OctetString tests " + std::to_string(i), e.what()));
×
161
            }
×
162
         }
163

164
         return results;
1✔
165
      }
2✔
166
};
167

168
BOTAN_REGISTER_TEST("utils", "octetstring", OctetString_Tests);
169

170
}  // namespace
171

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