summaryrefslogtreecommitdiffstats
path: root/src/mbedTLS++/BufferedSslContext.h
blob: 467ad36cfaae1b828362da026ee7542e9df1e0e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

// BufferedSslContext.h

// Declares the cBufferedSslContext class representing a SSL context with the SSL peer data backed by a cByteBuffer





#pragma once

#include "SslContext.h"
#include "ErrorCodes.h"





class cBufferedSslContext : public cSslContext
{
	using Super = cSslContext;

  public:
	/** Creates a new context with the buffers of specified size for the encrypted / decrypted data. */
	cBufferedSslContext(size_t a_BufferSize = 64000);

	/** Stores the specified data in the "incoming" buffer, to be process by the SSL decryptor.
	This is the data received from the SSL peer.
	Returns the number of bytes actually stored. If 0 is returned, owner should check the error state. */
	size_t WriteIncoming(const void * a_Data, size_t a_NumBytes);

	/** Retrieves data from the "outgoing" buffer, after being processed by the SSL encryptor.
	This is the data to be sent to the SSL peer.
	Returns the number of bytes actually retrieved. */
	size_t ReadOutgoing(void * a_Data, size_t a_DataMaxSize);

  protected:
	/** Buffer for the data that has been encrypted into the SSL stream and should be sent out. */
	cByteBuffer m_OutgoingData;

	/** Buffer for the data that has come in and needs to be decrypted from the SSL stream. */
	cByteBuffer m_IncomingData;


	// cSslContext overrides:
	virtual int ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) override;
	virtual int SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) override;
};