- Added `CryptClient` which is a kind-of `Stream` (from the `river` library)
- Constructor takes in an underlying connection, potentially a socket, but some `RiverStream` that can be used for the Botan client to communicate with
- Added `openCheck()` to be called prior to any code inside the `write`, `writeFully`, `read` and `readFully` methods which calls the `botanClient.isActive()`, if this is false (i.e. the TLS session is not active) then an exception (a `StreamException`) is thrown
This commit is contained in:
Tristan B. Velloza Kildaire 2023-04-29 18:24:05 +02:00
parent 1b8d11c1af
commit 347473df31
1 changed files with 87 additions and 1 deletions

View File

@ -1,3 +1,89 @@
module cryptstream.streams.client;
import botan.tls.client;
import botan.tls.client;
import river.core : RiverStream = Stream, StreamException, StreamError;
// TODO: This should be a kind-of `RiverStream`, but
// ... we defs can take IN a stream to use as the underlying
// ... connection upon which the TLS data will be sent over
public class CryptClient : RiverStream
{
/**
* Underlying stream to use for TLS-encrypted communication
*/
private RiverStream stream;
/**
* Botan TLS client
*/
private TLSClient botanClient;
/**
* Constructs a new TLS-enabled client stream
* Params:
* stream =
*/
this(RiverStream stream)
{
this.stream = stream;
this.botanClient = new TLSClient(&tlsOutputHandler);
// TODO: Insert code to init using botan OVER `stream`
}
private void tlsOutputHandler(in ubyte[] dataOut)
{
}
public override ulong read(byte[] toArray)
{
// TODO: Implement me
return 0;
}
public override ulong readFully(byte[] toArray)
{
// TODO: Implement me
return 0;
}
public override ulong write(byte[] fromArray)
{
/* Ensure the TLS session is active */
openCheck();
// TODO: Implement me
// botanClient.send()
return 0;
}
public override ulong writeFully(byte[] fromArray)
{
// TODO: Implement me
return 0;
}
public override void close()
{
// TODO: Implement me
}
/**
* Ensures that the TLS client is active is open, if not, then throws an
* exception
*/
private void openCheck()
{
if(!botanClient.isActive())
{
throw new StreamException(StreamError.CLOSED);
}
}
}