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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

95.4
/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

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

23
   return result;
1✔
24
}
1✔
25

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

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

32
   return result;
1✔
33
}
1✔
34

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

38
   auto rand_bytes = Test::rng().random_vec(8);
1✔
39
   Botan::OctetString os(rand_bytes.data(), rand_bytes.size());
1✔
40
   result.test_eq("length is 8 bytes", os.size(), 8);
1✔
41

42
   return result;
1✔
43
}
2✔
44

45
Test::Result test_odd_parity() {
1✔
46
   Test::Result result("OctetString");
1✔
47

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

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

58
   return result;
1✔
59
}
4✔
60

61
Test::Result test_to_string() {
1✔
62
   Test::Result result("OctetString");
1✔
63

64
   Botan::OctetString os("0123456789ABCDEF");
1✔
65
   result.test_eq("OctetString::to_string() returns correct string", os.to_string(), "0123456789ABCDEF");
3✔
66

67
   return result;
1✔
68
}
1✔
69

70
Test::Result test_xor() {
1✔
71
   Test::Result result("OctetString");
1✔
72

73
   Botan::OctetString os1("0000000000000000");
1✔
74
   Botan::OctetString os2("FFFFFFFFFFFFFFFF");
1✔
75

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

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

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

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

91
   return result;
1✔
92
}
5✔
93

94
Test::Result test_equality() {
1✔
95
   Test::Result result("OctetString");
1✔
96

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

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

106
   return result;
1✔
107
}
2✔
108

109
Test::Result test_append() {
1✔
110
   Test::Result result("OctetString");
1✔
111

112
   Botan::OctetString os1("0000");
1✔
113
   Botan::OctetString os2("FFFF");
1✔
114
   Botan::OctetString expected("0000FFFF");
1✔
115

116
   Botan::OctetString append_result = os1 + os2;
1✔
117

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

120
   return result;
1✔
121
}
4✔
122

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

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

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

145
         return results;
1✔
146
      }
1✔
147
};
148

149
BOTAN_REGISTER_TEST("utils", "octetstring", OctetString_Tests);
150

151
}
152

153
}
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