BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
encryption.hpp
1#ifndef BLUETOE_ENCRYPTION_HPP
2#define BLUETOE_ENCRYPTION_HPP
3
5#include <bluetoe/meta_types.hpp>
6
7namespace bluetoe {
8
9 template < typename ... Options >
10 class server;
11
12 template < typename ... Options >
13 class service;
14
15 template < typename ... Options >
16 class characteristic;
17
18 namespace details {
19 struct requires_encryption_meta_type {};
20 struct no_encryption_required_meta_type {};
21 struct may_require_encryption_meta_type {};
22 }
23
77 struct meta_type :
78 details::requires_encryption_meta_type,
79 details::valid_server_option_meta_type,
80 details::valid_service_option_meta_type,
81 details::valid_characteristic_option_meta_type {};
83 };
84
99 struct meta_type :
100 details::no_encryption_required_meta_type,
101 details::valid_server_option_meta_type,
102 details::valid_service_option_meta_type,
103 details::valid_characteristic_option_meta_type {};
105 };
106
125 struct meta_type :
126 details::may_require_encryption_meta_type,
127 details::valid_server_option_meta_type,
128 details::valid_service_option_meta_type,
129 details::valid_characteristic_option_meta_type {};
131 };
132
133 namespace details {
134
135 template < typename Server, bool Default = false >
136 struct requires_encryption_support_t
137 {
138 static bool constexpr value = Default;
139 };
140
141 template < typename ... Options, typename T >
142 struct requires_encryption_support_t< std::tuple< T, Options... >, false >
143 {
144 static bool constexpr value =
145 requires_encryption_support_t< T, false >::value
146 || requires_encryption_support_t< std::tuple< Options... >, false >::value;
147 };
148
149 template < typename ... Options, typename T >
150 struct requires_encryption_support_t< std::tuple< T, Options... >, true >
151 {
152 static bool constexpr value =
153 requires_encryption_support_t< T, true >::value
154 && requires_encryption_support_t< std::tuple< Options... >, true >::value;
155 };
156
157 template < bool Default, typename ... Options >
158 struct encryption_default
159 {
160 static bool constexpr require_encryption =
161 details::has_option< requires_encryption, Options... >::value;
162
163 static bool constexpr may_require =
164 details::has_option< may_require_encryption, Options... >::value;
165
166 static bool constexpr require_not_encryption =
167 details::has_option< no_encryption_required, Options... >::value;
168
169 // require !require default | value
170 // true false false | true
171 // false true false | false
172 // false false false | false
173 // true false true | true
174 // false true true | false
175 // false false true | true
176 static bool constexpr value =
177 ( require_encryption && !require_not_encryption )
178 || ( !require_encryption && !require_not_encryption && Default );
179
180 static bool constexpr maybe = value || may_require;
181 };
182
183 template < typename ... Options, bool Default >
184 struct requires_encryption_support_t< bluetoe::server< Options... >, Default > {
185 static bool constexpr default_val = encryption_default< Default, Options... >::maybe;
186
187 static bool constexpr value =
188 requires_encryption_support_t<
189 typename bluetoe::server< Options... >::services,
190 default_val >::value;
191 };
192
193 template < typename ... Options, bool Default >
194 struct requires_encryption_support_t< bluetoe::service< Options... >, Default > {
195 static bool constexpr default_val = encryption_default< Default, Options... >::maybe;
196
197 static bool constexpr value =
198 requires_encryption_support_t<
199 typename bluetoe::service< Options... >::characteristics,
200 default_val >::value;
201 };
202
203 template < typename ... Options, bool Default >
204 struct requires_encryption_support_t< bluetoe::characteristic< Options... >, Default > {
205 // @TODO the default for a characteristic should always be true
206 static bool constexpr value = encryption_default< Default, Options... >::maybe;
207 };
208
209 template < typename Characteristic, typename Service, typename Server >
210 struct characteristic_requires_encryption;
211
212 template < typename ... CharacteristicOptions, typename ... ServiceOptions, typename ... ServerOptions >
213 struct characteristic_requires_encryption<
214 bluetoe::characteristic< CharacteristicOptions... >,
215 bluetoe::service< ServiceOptions... >,
216 bluetoe::server< ServerOptions... > >
217 {
218 // @TODO the default for a characteristic should always be true
219 static bool constexpr server_requires_encryption = encryption_default< false, ServerOptions... >::value;
220 static bool constexpr service_requires_encryption = encryption_default< server_requires_encryption, ServiceOptions... >::value;
221
222 static bool constexpr value = encryption_default< service_requires_encryption, CharacteristicOptions... >::value;
223 };
224 }
225
226} // namespace bluetoe
227
228#endif
Root of the declaration of a GATT server.
Definition: server.hpp:85
a service with zero or more characteristics
Definition: service.hpp:150
defines that a characteristic may require encyption
Definition: encryption.hpp:123
defines that access to characteristic(s) does not require an encrypted link.
Definition: encryption.hpp:97
defines that access to characteristic(s) require an encrypted link without MITM Protection.
Definition: encryption.hpp:75