TLSInputStream
open class TLSInputStream : InputStream, InputStreamDelegate
An input stream which is encrypted using the TLS/SSL protocol.
The input stream uses an underlying input stream to read the encrypted data, which is then decrypted.
The decrypted data can then be read from this stream.
-
Creates a TLS/SSL session for the provided streams.
This currently works for server side only.
The provided Certificates are used for encryption.
When creating an encrypted stream pair, a handshake will automatically be performed. If the handshake fails, a TLSError will be thrown.
Throws
A TLSError indicating that the TLS/SSL session could not be created.
Declaration
Swift
open class func CreateStreamPair(fromInputStream inputStream: InputStream, outputStream: OutputStream, certificates: [Certificate]) throws -> (inputStream: TLSInputStream, outputStream: TLSOutputStream)
Parameters
inputStream
Input stream which should be used as an underlying stream to the TLS/SSL input stream. Reads the encrypted data.
outputStream
Output stream which should be used as an underlying stream to the TLS/SSL output stream. The encrypted data will be written to it.
certificates
Array of certificates for encryption. The first certificate has to contain a private key used for decryption. A private key will automatically be included if the certificate is loaded from a PKCS12-file.
Return Value
An encrypted input and output stream.
-
Underlying stream of the encrypted stream.
Reads data from a source which was TLS/SSL encrypted. The data read from this stream will be decrypted and can be read from the TLSInputStream.
Declaration
Swift
open let underlyingStream: InputStream
-
The delegate of this stream will be notified if new data is available or the stream was closed.
Declaration
Swift
open var delegate: InputStreamDelegate?
-
Specifies, if this stream is open and data can be read from it.
If the stream is closed and a read operation is initiated, an IOError will be thrown.
Declaration
Swift
open var open: Bool
-
Reads encrypted data and decrypts it.
The number of elements in the returned array is equal to or less than the minumum of maxByteCount and bufferSize.
If the operation fails, an IOError is thrown.
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the read operation has to be repeated.
For this reason, a delegate can be used, which will be notified, if new data becomes available.
After the delegate is notified, a call of this function will most likely not throw these errors.
If an .Interrupted error is thrown, the operation has to be tried again.
If an .EndOfFile error is thrown, the end of the data has been reached and no more data will be available. Subsequent calls to this function will fail. The stream will automatically be closed.
Throws
An IOError indicating that the read operation failed.
Declaration
Swift
open func read(_ maxByteCount: Int) throws -> [CChar]
Parameters
maxByteCount
Maximum number of bytes to read.
Return Value
An array of chars containing the data which was read.
-
Closes the stream manually and shuts down the underlying stream so no more read calls are possible.
Subsequent calls to the read-function function will fail.
The delegate will be notified of this operation.
This operation also closes the underlying stream.
Declaration
Swift
open func close()
-
Delegate methods for the underlying stream
Notifies the stream about new data which is available in the underlying stream.
Warning: This method should not be called manually, it will automatically be called by the underlying stream.
If another stream than the underlying stream is passed to this method, the call will be ignored.
Declaration
Swift
open func canRead(from inputStream: InputStream)
Parameters
inputStream
The input stream which has new data available.
-
Delegate methods for the underlying stream
Notifies the stream that the underlying stream was closed.
Warning: This method should not be called manually, it will automatically be called by the underlying stream.
If another stream than the underlying stream is passed to this method, the call will be ignored.
Declaration
Swift
open func didClose(_ inputStream: InputStream)
Parameters
inputStream
The input stream which has new data available.