wrapper of the mbed port of Cyassl. It's based of the work of Ashley Mills

Dependencies:   cyassl-lib

Dependents:   TLS_cyassl-Example TLS_cyassl-Example2 HTTPSClientExample2

Fork of TLS_cyassl by Francois Berder

Import programTLS_cyassl-Example

This program shows how to use TLS_cyassl to connect to mbed.org

Import programTLS_cyassl-Example2

This example show how to create a small TLS server using the TLS_cyassl library.

Committer:
feb11
Date:
Mon Sep 16 09:54:45 2013 +0000
Revision:
2:63ad554f6ca4
Parent:
0:815067fd66c9
Child:
4:86a5029194b4
removed debug information

Who changed what in which revision?

UserRevisionLine numberNew contents of line
feb11 0:815067fd66c9 1 #ifndef TLSCONNECTION_H
feb11 0:815067fd66c9 2 #define TLSCONNECTION_H
feb11 0:815067fd66c9 3
feb11 0:815067fd66c9 4 #include "Socket.h"
feb11 0:815067fd66c9 5 #include "Endpoint.h"
feb11 2:63ad554f6ca4 6 #include "bsd_socket.h"
feb11 2:63ad554f6ca4 7 #include "cyassl/ssl.h"
feb11 0:815067fd66c9 8
feb11 0:815067fd66c9 9 /** This class provides a user-friendly interface for the
feb11 0:815067fd66c9 10 axTLS library.
feb11 0:815067fd66c9 11 */
feb11 0:815067fd66c9 12 class TLSConnection : public Socket, public Endpoint
feb11 0:815067fd66c9 13 {
feb11 0:815067fd66c9 14 public :
feb11 0:815067fd66c9 15
feb11 0:815067fd66c9 16 TLSConnection();
feb11 0:815067fd66c9 17
feb11 0:815067fd66c9 18 /** This function tries to establish a TLS connection
feb11 0:815067fd66c9 19 with the given host.
feb11 0:815067fd66c9 20 It will first try to establish a TCP connection on
feb11 0:815067fd66c9 21 port 443 with the host. Then, it runs the TLS
feb11 0:815067fd66c9 22 handshake protocol.
feb11 0:815067fd66c9 23
feb11 0:815067fd66c9 24 \param host A valid hostname (e.g. "mbed.org")
feb11 0:815067fd66c9 25 \return True if it managed to establish a connection
feb11 0:815067fd66c9 26 with the host. False otherwise.
feb11 0:815067fd66c9 27 */
feb11 0:815067fd66c9 28 bool connect(const char *host);
feb11 0:815067fd66c9 29
feb11 0:815067fd66c9 30 /** Indicates whether a connection is established or not.
feb11 0:815067fd66c9 31
feb11 0:815067fd66c9 32 \return true if a connection is established, otherwise
feb11 0:815067fd66c9 33 returns false.
feb11 0:815067fd66c9 34 */
feb11 0:815067fd66c9 35 bool is_connected(void);
feb11 0:815067fd66c9 36
feb11 0:815067fd66c9 37 /** Sends some data to the host. This method does not return
feb11 0:815067fd66c9 38 until length bytes have been sent.
feb11 0:815067fd66c9 39
feb11 0:815067fd66c9 40 \param data A pointer to some data
feb11 0:815067fd66c9 41 \param length Number of bytes to send
feb11 0:815067fd66c9 42 \return Number of bytes sent, or -1 if an error occured.
feb11 0:815067fd66c9 43 */
feb11 0:815067fd66c9 44 int send_all(char *data, int length);
feb11 0:815067fd66c9 45
feb11 0:815067fd66c9 46 /** Receive some data from the host.
feb11 0:815067fd66c9 47
feb11 0:815067fd66c9 48 \param data
feb11 0:815067fd66c9 49 \param length Maximum number of bytes to receive
feb11 0:815067fd66c9 50 \return Number of bytes read in range 0..length, or -1
feb11 0:815067fd66c9 51 if an error occured.
feb11 0:815067fd66c9 52 */
feb11 0:815067fd66c9 53 int receive(char *data, int length);
feb11 0:815067fd66c9 54
feb11 0:815067fd66c9 55 /** Close the connection.
feb11 0:815067fd66c9 56
feb11 0:815067fd66c9 57 \param shutdown
feb11 0:815067fd66c9 58 \return True if the connection was closed with success,
feb11 0:815067fd66c9 59 false otherwise. If no connection was established,
feb11 0:815067fd66c9 60 returns true immediately.
feb11 0:815067fd66c9 61 */
feb11 0:815067fd66c9 62 bool close(bool shutdown = true);
feb11 0:815067fd66c9 63
feb11 0:815067fd66c9 64 private :
feb11 0:815067fd66c9 65
feb11 0:815067fd66c9 66 bool _is_connected;
feb11 0:815067fd66c9 67
feb11 0:815067fd66c9 68 CYASSL_CTX *_ssl_ctx;
feb11 0:815067fd66c9 69 CYASSL *_ssl;
feb11 0:815067fd66c9 70 };
feb11 0:815067fd66c9 71
feb11 0:815067fd66c9 72 #endif
feb11 0:815067fd66c9 73
feb11 0:815067fd66c9 74