Skip to content

Commit a9fd6cb

Browse files
Add move constructor/assignment to BearSSL helpers
Fixes esp8266#8522
1 parent 732db59 commit a9fd6cb

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

libraries/ESP8266WiFi/src/BearSSLHelpers.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ class PublicKey {
5959
// Disable the copy constructor, we're pointer based
6060
PublicKey(const PublicKey& that) = delete;
6161

62+
// Allow moves
63+
PublicKey(PublicKey&& that) {
64+
_key = that._key;
65+
that._key = nullptr;
66+
}
67+
68+
PublicKey& operator=(PublicKey&& that) {
69+
if (this != &that) {
70+
free(_key);
71+
_key = that._key;
72+
that._key = nullptr;
73+
}
74+
return *this;
75+
}
76+
6277
private:
6378
brssl::public_key *_key;
6479
};
@@ -87,6 +102,21 @@ class PrivateKey {
87102
// Disable the copy constructor, we're pointer based
88103
PrivateKey(const PrivateKey& that) = delete;
89104

105+
// Allow moves
106+
PrivateKey(PrivateKey&& that) {
107+
_key = that._key;
108+
that._key = nullptr;
109+
}
110+
111+
PrivateKey& operator=(PrivateKey&& that) {
112+
if (this != &that) {
113+
free(_key);
114+
_key = that._key;
115+
that._key = nullptr;
116+
}
117+
return *this;
118+
}
119+
90120
private:
91121
brssl::private_key *_key;
92122
};
@@ -123,6 +153,30 @@ class X509List {
123153
// Disable the copy constructor, we're pointer based
124154
X509List(const X509List& that) = delete;
125155

156+
// Allow moves
157+
X509List(X509List&& that) {
158+
_count = that._count;
159+
_cert = that._cert;
160+
_ta = that._ta;
161+
that._count = 0;
162+
that._cert = nullptr;
163+
that._ta = nullptr;
164+
}
165+
166+
X509List& operator=(X509List&& that) {
167+
if (this != &that) {
168+
free(_cert);
169+
free(_ta);
170+
_count = that._count;
171+
_cert = that._cert;
172+
_ta = that._ta;
173+
that._count = 0;
174+
that._cert = nullptr;
175+
that._ta = nullptr;
176+
}
177+
return *this;
178+
}
179+
126180
private:
127181
size_t _count;
128182
br_x509_certificate *_cert;
@@ -170,6 +224,32 @@ class ServerSessions {
170224
// Returns the number of sessions the cache can hold.
171225
uint32_t size() { return _size; }
172226

227+
// Disable the copy constructor, we're pointer based
228+
ServerSessions(const ServerSessions& that) = delete;
229+
230+
// Allow moves
231+
ServerSessions(ServerSessions&& that) {
232+
_size = that._size;
233+
_store = that._store;
234+
_isDynamic = that._isDynamic;
235+
_cache = that._cache;
236+
that._size = 0;
237+
that._store = nullptr;
238+
}
239+
240+
ServerSessions& operator=(ServerSessions&& that) {
241+
if (this != &that) {
242+
free(_store);
243+
_size = that._size;
244+
_store = that._store;
245+
_isDynamic = that._isDynamic;
246+
_cache = that._cache;
247+
that._size = 0;
248+
that._store = nullptr;
249+
}
250+
return *this;
251+
}
252+
173253
private:
174254
ServerSessions(ServerSession *sessions, uint32_t size, bool isDynamic);
175255

0 commit comments

Comments
 (0)