From 32fa4ac11d3fb9816a6d6da73987ae61fece6524 Mon Sep 17 00:00:00 2001 From: Noah Laptop Date: Tue, 19 Feb 2019 14:29:50 -0800 Subject: [PATCH] restruturing according to arduino library guidlines --- .vscode/c_cpp_properties.json | 22 +++++++++++++ .vscode/settings.json | 25 ++++++++++++++ src/Client.h | 45 ++++++++++++++++++++++++++ src/SSLClient.cpp | 3 +- SSLClient.h => src/SSLClient.h | 15 +++++++-- bearssl.h => src/bearssl.h | 0 bearssl_aead.h => src/bearssl_aead.h | 0 bearssl_block.h => src/bearssl_block.h | 0 bearssl_ec.h => src/bearssl_ec.h | 0 bearssl_hash.h => src/bearssl_hash.h | 0 bearssl_hmac.h => src/bearssl_hmac.h | 0 bearssl_kdf.h => src/bearssl_kdf.h | 0 bearssl_pem.h => src/bearssl_pem.h | 0 bearssl_prf.h => src/bearssl_prf.h | 0 bearssl_rand.h => src/bearssl_rand.h | 0 bearssl_rsa.h => src/bearssl_rsa.h | 0 bearssl_ssl.h => src/bearssl_ssl.h | 0 bearssl_x509.h => src/bearssl_x509.h | 0 config.h => src/config.h | 0 inner.h => src/inner.h | 0 20 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 src/Client.h rename SSLClient.h => src/SSLClient.h (86%) rename bearssl.h => src/bearssl.h (100%) rename bearssl_aead.h => src/bearssl_aead.h (100%) rename bearssl_block.h => src/bearssl_block.h (100%) rename bearssl_ec.h => src/bearssl_ec.h (100%) rename bearssl_hash.h => src/bearssl_hash.h (100%) rename bearssl_hmac.h => src/bearssl_hmac.h (100%) rename bearssl_kdf.h => src/bearssl_kdf.h (100%) rename bearssl_pem.h => src/bearssl_pem.h (100%) rename bearssl_prf.h => src/bearssl_prf.h (100%) rename bearssl_rand.h => src/bearssl_rand.h (100%) rename bearssl_rsa.h => src/bearssl_rsa.h (100%) rename bearssl_ssl.h => src/bearssl_ssl.h (100%) rename bearssl_x509.h => src/bearssl_x509.h (100%) rename config.h => src/config.h (100%) rename inner.h => src/inner.h (100%) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..89064ed --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,22 @@ +{ + "configurations": [ + { + "name": "SAMD", + "includePath": [ + "${workspaceFolder}/**", + "C:/Users/Noah/AppData/Local/Arduino15/packages/adafruit/hardware/samd/1.2.9/cores/arduino/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.17763.0", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f76f1b2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,25 @@ +{ + "files.associations": { + "cmath": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "memory": "cpp", + "new": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "utility": "cpp", + "xmemory": "cpp", + "xmemory0": "cpp", + "xstddef": "cpp", + "xtr1common": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/src/Client.h b/src/Client.h new file mode 100644 index 0000000..b8e5d93 --- /dev/null +++ b/src/Client.h @@ -0,0 +1,45 @@ +/* + Client.h - Base class that provides Client + Copyright (c) 2011 Adrian McEwen. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef client_h +#define client_h +#include "Print.h" +#include "Stream.h" +#include "IPAddress.h" + +class Client : public Stream { + +public: + virtual int connect(IPAddress ip, uint16_t port) =0; + virtual int connect(const char *host, uint16_t port) =0; + virtual size_t write(uint8_t) =0; + virtual size_t write(const uint8_t *buf, size_t size) =0; + virtual int available() = 0; + virtual int read() = 0; + virtual int read(uint8_t *buf, size_t size) = 0; + virtual int peek() = 0; + virtual void flush() = 0; + virtual void stop() = 0; + virtual uint8_t connected() = 0; + virtual operator bool() = 0; +protected: + uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; +}; + +#endif diff --git a/src/SSLClient.cpp b/src/SSLClient.cpp index 42f41bd..85c1e45 100644 --- a/src/SSLClient.cpp +++ b/src/SSLClient.cpp @@ -18,5 +18,4 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "SSLClient.h" - +#include "SSLClient.h" \ No newline at end of file diff --git a/SSLClient.h b/src/SSLClient.h similarity index 86% rename from SSLClient.h rename to src/SSLClient.h index 8711efa..36c6a5f 100644 --- a/SSLClient.h +++ b/src/SSLClient.h @@ -40,7 +40,17 @@ template class SSLClient : public Client { +/** static type checks + * I'm a java developer, so I want to ensure that my inheritance is safe. + * These checks ensure that all the functions we use on class C are + * actually present on class C. It does this by first checking that the + * class inherits from Client, and then that it contains a status() function. + */ +static_assert(std::is_base_of(Client, C)::value, "C must be a Client Class!"); +static_assert(std::is_function(decltype(C::status))::value, "C must have a status() function!"); + public: + /** Ctor * Creates a new dynamically allocated Client object based on the * one passed to client @@ -48,7 +58,6 @@ public: * is going to exists past the inital creation of the SSLClient. * @param client the (Ethernet)client object */ - static_assert(std::is_base_of(Client, C)::value, "C must be a Client Class!"); SSLClient(const C &client): m_client(client) { @@ -61,7 +70,7 @@ public: * Most of them smply pass through */ virtual int availableForWrite(void) const { return m_client.availableForWrite(); }; - virtual operator bool() const { return static_cast(m_client); } + virtual operator bool() const { return m_client.bool(); } virtual bool operator==(const bool value) const { return bool() == value; } virtual bool operator!=(const bool value) const { return bool() != value; } virtual bool operator==(const C& rhs) const { return m_client.operator==(rhs); } @@ -87,6 +96,8 @@ public: virtual void stop(); virtual uint8_t connected(); + /** get the client object */ + C& getClient() { return m_client; } private: // create a copy of the class diff --git a/bearssl.h b/src/bearssl.h similarity index 100% rename from bearssl.h rename to src/bearssl.h diff --git a/bearssl_aead.h b/src/bearssl_aead.h similarity index 100% rename from bearssl_aead.h rename to src/bearssl_aead.h diff --git a/bearssl_block.h b/src/bearssl_block.h similarity index 100% rename from bearssl_block.h rename to src/bearssl_block.h diff --git a/bearssl_ec.h b/src/bearssl_ec.h similarity index 100% rename from bearssl_ec.h rename to src/bearssl_ec.h diff --git a/bearssl_hash.h b/src/bearssl_hash.h similarity index 100% rename from bearssl_hash.h rename to src/bearssl_hash.h diff --git a/bearssl_hmac.h b/src/bearssl_hmac.h similarity index 100% rename from bearssl_hmac.h rename to src/bearssl_hmac.h diff --git a/bearssl_kdf.h b/src/bearssl_kdf.h similarity index 100% rename from bearssl_kdf.h rename to src/bearssl_kdf.h diff --git a/bearssl_pem.h b/src/bearssl_pem.h similarity index 100% rename from bearssl_pem.h rename to src/bearssl_pem.h diff --git a/bearssl_prf.h b/src/bearssl_prf.h similarity index 100% rename from bearssl_prf.h rename to src/bearssl_prf.h diff --git a/bearssl_rand.h b/src/bearssl_rand.h similarity index 100% rename from bearssl_rand.h rename to src/bearssl_rand.h diff --git a/bearssl_rsa.h b/src/bearssl_rsa.h similarity index 100% rename from bearssl_rsa.h rename to src/bearssl_rsa.h diff --git a/bearssl_ssl.h b/src/bearssl_ssl.h similarity index 100% rename from bearssl_ssl.h rename to src/bearssl_ssl.h diff --git a/bearssl_x509.h b/src/bearssl_x509.h similarity index 100% rename from bearssl_x509.h rename to src/bearssl_x509.h diff --git a/config.h b/src/config.h similarity index 100% rename from config.h rename to src/config.h diff --git a/inner.h b/src/inner.h similarity index 100% rename from inner.h rename to src/inner.h