ARM Shanghai IoT Team (Internal) / newMiniTLS-GPL

Fork of MiniTLS-GPL by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TLSSocket.h Source File

TLSSocket.h

Go to the documentation of this file.
00001 /*
00002 MiniTLS - A super trimmed down TLS/SSL Library for embedded devices
00003 Author: Donatien Garnier
00004 Copyright (C) 2013-2014 AppNearMe Ltd
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019 *//**
00020  * \file TLSSocket.h
00021  * \copyright Copyright (c) AppNearMe Ltd 2013
00022  * \author Donatien Garnier
00023  */
00024 
00025 #ifndef TLSSOCKET_H_
00026 #define TLSSOCKET_H_
00027 
00028 #include "core/fwk.h"
00029 #include "MiniTLS.h"
00030 
00031 // #include <cstdint> -- new to C++11
00032 #include "inc/minitls_errors.h"
00033 
00034 #include "tls/tls_socket.h"
00035 
00036 #define TLSSOCKET_BUF_SIZE 5420//804
00037 
00038 /** TLS Socket
00039  * \param pMiniTLS pointer to MiniTLS instance
00040  */
00041 class TLSSocket
00042 {
00043 public:
00044   TLSSocket(MiniTLS* pMiniTLS);
00045   ~TLSSocket();
00046 
00047   minitls_err_t init();
00048 
00049   minitls_err_t connect(const char* hostname, uint16_t port, int timeout);
00050 
00051   minitls_err_t read(uint8_t* buf, size_t minLength, size_t maxLength, size_t* readLength, int timeout);
00052   minitls_err_t write(uint8_t* buf, size_t length, size_t* writtenLength, int timeout);
00053   minitls_err_t flush(int timeout);
00054 
00055   minitls_err_t close();
00056 
00057 private:
00058   uint8_t m_writeBuf[500];
00059   uint8_t m_readBuf[TLSSOCKET_BUF_SIZE];
00060 
00061   tls_socket_t m_sock;
00062 
00063   MiniTLS* m_pMiniTLS;
00064 };
00065 
00066 #endif /* TLSSOCKET_H_ */
00067