Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add move constructor/assignment to BearSSL helpers #8524

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions libraries/ESP8266WiFi/src/BearSSLHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ class PublicKey {
// Disable the copy constructor, we're pointer based
PublicKey(const PublicKey& that) = delete;

// Allow moves
PublicKey(PublicKey&& that) {
_key = that._key;
that._key = nullptr;
}

PublicKey& operator=(PublicKey&& that) {
if (this != &that) {
free(_key);
_key = that._key;
that._key = nullptr;
}
return *this;
}

private:
brssl::public_key *_key;
};
Expand Down Expand Up @@ -87,6 +102,21 @@ class PrivateKey {
// Disable the copy constructor, we're pointer based
PrivateKey(const PrivateKey& that) = delete;

// Allow moves
PrivateKey(PrivateKey&& that) {
_key = that._key;
that._key = nullptr;
}

PrivateKey& operator=(PrivateKey&& that) {
if (this != &that) {
free(_key);
_key = that._key;
that._key = nullptr;
}
return *this;
}

private:
brssl::private_key *_key;
};
Expand Down Expand Up @@ -123,6 +153,30 @@ class X509List {
// Disable the copy constructor, we're pointer based
X509List(const X509List& that) = delete;

// Allow moves
X509List(X509List&& that) {
_count = that._count;
_cert = that._cert;
_ta = that._ta;
that._count = 0;
that._cert = nullptr;
that._ta = nullptr;
earlephilhower marked this conversation as resolved.
Show resolved Hide resolved
}

X509List& operator=(X509List&& that) {
if (this != &that) {
free(_cert);
free(_ta);
_count = that._count;
_cert = that._cert;
_ta = that._ta;
that._count = 0;
that._cert = nullptr;
that._ta = nullptr;
}
return *this;
}

private:
size_t _count;
br_x509_certificate *_cert;
Expand Down Expand Up @@ -170,6 +224,32 @@ class ServerSessions {
// Returns the number of sessions the cache can hold.
uint32_t size() { return _size; }

// Disable the copy constructor, we're pointer based
ServerSessions(const ServerSessions& that) = delete;

// Allow moves
ServerSessions(ServerSessions&& that) {
_size = that._size;
_store = that._store;
_isDynamic = that._isDynamic;
_cache = that._cache;
that._size = 0;
that._store = nullptr;
}

ServerSessions& operator=(ServerSessions&& that) {
if (this != &that) {
free(_store);
_size = that._size;
_store = that._store;
_isDynamic = that._isDynamic;
_cache = that._cache;
that._size = 0;
that._store = nullptr;
}
return *this;
}

private:
ServerSessions(ServerSession *sessions, uint32_t size, bool isDynamic);

Expand Down Expand Up @@ -211,6 +291,24 @@ class SigningVerifier : public UpdaterVerifyClass {
SigningVerifier(PublicKey *pubKey) { _pubKey = pubKey; stack_thunk_add_ref(); }
~SigningVerifier() { stack_thunk_del_ref(); }

// Disable the copy constructor, we're pointer based
SigningVerifier(const SigningVerifier& that) = delete;

// Allow moves
SigningVerifier(SigningVerifier&& that) {
_pubKey = that._pubKey;
that._pubKey = nullptr;
}

SigningVerifier& operator=(SigningVerifier&& that) {
if (this != &that) {
free(_pubKey);
_pubKey = that._pubKey;
that._pubKey = nullptr;
}
return *this;
}

private:
PublicKey *_pubKey;
};
Expand Down