123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using System.IO;
- namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls
- {
- internal class TlsStream
- : Stream
- {
- private readonly TlsProtocol m_handler;
- public TlsProtocol Protocol { get => this.m_handler; }
- byte[] oneByteBuf = new byte[1];
- internal TlsStream(TlsProtocol handler)
- {
- m_handler = handler;
- }
- public override bool CanRead
- {
- get { return true; }
- }
- public override bool CanSeek
- {
- get { return false; }
- }
- public override bool CanWrite
- {
- get { return true; }
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- m_handler.Close();
- }
- base.Dispose(disposing);
- }
- public override void Flush()
- {
- m_handler.Flush();
- }
- public override long Length
- {
- get { throw new NotSupportedException(); }
- }
- public override long Position
- {
- get { throw new NotSupportedException(); }
- set { throw new NotSupportedException(); }
- }
- public override int Read(byte[] buffer, int offset, int count)
- {
- return m_handler.ReadApplicationData(buffer, offset, count);
- }
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- public override int Read(Span<byte> buffer)
- {
- return m_handler.ReadApplicationData(buffer);
- }
- #endif
- public override int ReadByte()
- {
- int ret = m_handler.ReadApplicationData(oneByteBuf, 0, 1);
- return ret <= 0 ? -1 : oneByteBuf[0];
- }
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotSupportedException();
- }
- public override void SetLength(long value)
- {
- throw new NotSupportedException();
- }
- public override void Write(byte[] buffer, int offset, int count)
- {
- m_handler.WriteApplicationData(buffer, offset, count);
- }
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- public override void Write(ReadOnlySpan<byte> buffer)
- {
- m_handler.WriteApplicationData(buffer);
- }
- #endif
- public override void WriteByte(byte value)
- {
- oneByteBuf[0] = value;
- Write(oneByteBuf, 0, 1);
- }
- }
- }
- #pragma warning restore
- #endif
|