add all
This commit is contained in:
329
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/CipherStream.cs
vendored
Normal file
329
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/CipherStream.cs
vendored
Normal file
@@ -0,0 +1,329 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
#if NETCOREAPP1_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
using System.Buffers;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO
|
||||
{
|
||||
public sealed class CipherStream
|
||||
: Stream
|
||||
{
|
||||
private readonly Stream m_stream;
|
||||
private readonly IBufferedCipher m_readCipher, m_writeCipher;
|
||||
|
||||
private byte[] m_readBuf;
|
||||
private int m_readBufPos;
|
||||
private bool m_readEnded;
|
||||
|
||||
public CipherStream(Stream stream, IBufferedCipher readCipher, IBufferedCipher writeCipher)
|
||||
{
|
||||
m_stream = stream;
|
||||
|
||||
if (readCipher != null)
|
||||
{
|
||||
m_readCipher = readCipher;
|
||||
m_readBuf = null;
|
||||
}
|
||||
|
||||
if (writeCipher != null)
|
||||
{
|
||||
m_writeCipher = writeCipher;
|
||||
}
|
||||
}
|
||||
|
||||
public IBufferedCipher ReadCipher => m_readCipher;
|
||||
|
||||
public IBufferedCipher WriteCipher => m_writeCipher;
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return m_stream.CanRead; }
|
||||
}
|
||||
|
||||
public sealed override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return m_stream.CanWrite; }
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER || (UNITY_2021_2_OR_NEWER && (NET_STANDARD_2_0 || NET_STANDARD_2_1))
|
||||
public override void CopyTo(Stream destination, int bufferSize)
|
||||
{
|
||||
if (m_readCipher == null)
|
||||
{
|
||||
m_stream.CopyTo(destination, bufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.CopyTo(destination, bufferSize);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
m_stream.Flush();
|
||||
}
|
||||
|
||||
public sealed override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public sealed override long Position
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (m_readCipher == null)
|
||||
return m_stream.Read(buffer, offset, count);
|
||||
|
||||
Streams.ValidateBufferArguments(buffer, offset, count);
|
||||
|
||||
int num = 0;
|
||||
while (num < count)
|
||||
{
|
||||
if (m_readBuf == null || m_readBufPos >= m_readBuf.Length)
|
||||
{
|
||||
if (!FillInBuf())
|
||||
break;
|
||||
}
|
||||
|
||||
int numToCopy = System.Math.Min(count - num, m_readBuf.Length - m_readBufPos);
|
||||
Array.Copy(m_readBuf, m_readBufPos, buffer, offset + num, numToCopy);
|
||||
m_readBufPos += numToCopy;
|
||||
num += numToCopy;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override int Read(Span<byte> buffer)
|
||||
{
|
||||
if (buffer.IsEmpty)
|
||||
return 0;
|
||||
|
||||
if (m_readCipher == null)
|
||||
return m_stream.Read(buffer);
|
||||
|
||||
int num = 0;
|
||||
while (num < buffer.Length)
|
||||
{
|
||||
if (m_readBuf == null || m_readBufPos >= m_readBuf.Length)
|
||||
{
|
||||
if (!FillInBuf())
|
||||
break;
|
||||
}
|
||||
|
||||
int numToCopy = System.Math.Min(buffer.Length - num, m_readBuf.Length - m_readBufPos);
|
||||
m_readBuf.AsSpan(m_readBufPos, numToCopy).CopyTo(buffer[num..]);
|
||||
|
||||
m_readBufPos += numToCopy;
|
||||
num += numToCopy;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
if (m_readCipher == null)
|
||||
return m_stream.ReadByte();
|
||||
|
||||
if (m_readBuf == null || m_readBufPos >= m_readBuf.Length)
|
||||
{
|
||||
if (!FillInBuf())
|
||||
return -1;
|
||||
}
|
||||
|
||||
return m_readBuf[m_readBufPos++];
|
||||
}
|
||||
|
||||
public sealed override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public sealed override void SetLength(long length)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (m_writeCipher == null)
|
||||
{
|
||||
m_stream.Write(buffer, offset, count);
|
||||
return;
|
||||
}
|
||||
|
||||
Streams.ValidateBufferArguments(buffer, offset, count);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
#if NETCOREAPP1_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
int outputSize = m_writeCipher.GetUpdateOutputSize(count);
|
||||
byte[] output = outputSize > 0 ? ArrayPool<byte>.Shared.Rent(outputSize) : null;
|
||||
try
|
||||
{
|
||||
int length = m_writeCipher.ProcessBytes(buffer, offset, count, output, 0);
|
||||
if (length > 0)
|
||||
{
|
||||
m_stream.Write(output, 0, length);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (output != null)
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(output);
|
||||
}
|
||||
}
|
||||
#else
|
||||
byte[] output = m_writeCipher.ProcessBytes(buffer, offset, count);
|
||||
if (output != null)
|
||||
{
|
||||
m_stream.Write(output, 0, output.Length);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
if (buffer.IsEmpty)
|
||||
return;
|
||||
|
||||
if (m_writeCipher == null)
|
||||
{
|
||||
m_stream.Write(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
int outputSize = m_writeCipher.GetUpdateOutputSize(buffer.Length);
|
||||
byte[] output = outputSize > 0 ? ArrayPool<byte>.Shared.Rent(outputSize) : null;
|
||||
try
|
||||
{
|
||||
int length = m_writeCipher.ProcessBytes(buffer, Spans.FromNullable(output));
|
||||
if (length > 0)
|
||||
{
|
||||
m_stream.Write(output[..length]);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (output != null)
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
if (m_writeCipher == null)
|
||||
{
|
||||
m_stream.WriteByte(value);
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] data = m_writeCipher.ProcessByte(value);
|
||||
if (data != null)
|
||||
{
|
||||
m_stream.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (m_writeCipher != null)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
int outputSize = m_writeCipher.GetOutputSize(0);
|
||||
Span<byte> output = outputSize <= 256
|
||||
? stackalloc byte[outputSize]
|
||||
: new byte[outputSize];
|
||||
int len = m_writeCipher.DoFinal(output);
|
||||
m_stream.Write(output[..len]);
|
||||
#else
|
||||
byte[] data = m_writeCipher.DoFinal();
|
||||
m_stream.Write(data, 0, data.Length);
|
||||
#endif
|
||||
}
|
||||
m_stream.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool FillInBuf()
|
||||
{
|
||||
if (m_readEnded)
|
||||
return false;
|
||||
|
||||
m_readBufPos = 0;
|
||||
|
||||
do
|
||||
{
|
||||
m_readBuf = ReadAndProcessBlock();
|
||||
}
|
||||
while (!m_readEnded && m_readBuf == null);
|
||||
|
||||
return m_readBuf != null;
|
||||
}
|
||||
|
||||
private byte[] ReadAndProcessBlock()
|
||||
{
|
||||
int blockSize = m_readCipher.GetBlockSize();
|
||||
int readSize = blockSize == 0 ? 256 : blockSize;
|
||||
|
||||
byte[] block = new byte[readSize];
|
||||
int numRead = 0;
|
||||
do
|
||||
{
|
||||
int count = m_stream.Read(block, numRead, block.Length - numRead);
|
||||
if (count < 1)
|
||||
{
|
||||
m_readEnded = true;
|
||||
break;
|
||||
}
|
||||
numRead += count;
|
||||
}
|
||||
while (numRead < block.Length);
|
||||
|
||||
Debug.Assert(m_readEnded || numRead == block.Length);
|
||||
|
||||
byte[] bytes = m_readEnded
|
||||
? m_readCipher.DoFinal(block, 0, numRead)
|
||||
: m_readCipher.ProcessBytes(block);
|
||||
|
||||
if (bytes != null && bytes.Length == 0)
|
||||
{
|
||||
bytes = null;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/CipherStream.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/CipherStream.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 363771abfdeee354d896e6e401cadc64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/DigestSink.cs
vendored
Normal file
48
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/DigestSink.cs
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO
|
||||
{
|
||||
public sealed class DigestSink
|
||||
: BaseOutputStream
|
||||
{
|
||||
private readonly IDigest m_digest;
|
||||
|
||||
public DigestSink(IDigest digest)
|
||||
{
|
||||
m_digest = digest;
|
||||
}
|
||||
|
||||
public IDigest Digest => m_digest;
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
Streams.ValidateBufferArguments(buffer, offset, count);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
m_digest.BlockUpdate(buffer, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
if (!buffer.IsEmpty)
|
||||
{
|
||||
m_digest.BlockUpdate(buffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
m_digest.Update(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/DigestSink.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/DigestSink.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f48e10bd08f18a34ebfdb18f16c9225c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
164
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/DigestStream.cs
vendored
Normal file
164
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/DigestStream.cs
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO
|
||||
{
|
||||
public sealed class DigestStream
|
||||
: Stream
|
||||
{
|
||||
private readonly Stream m_stream;
|
||||
private readonly IDigest m_readDigest;
|
||||
private readonly IDigest m_writeDigest;
|
||||
|
||||
public DigestStream(Stream stream, IDigest readDigest, IDigest writeDigest)
|
||||
{
|
||||
m_stream = stream;
|
||||
m_readDigest = readDigest;
|
||||
m_writeDigest = writeDigest;
|
||||
}
|
||||
|
||||
public IDigest ReadDigest => m_readDigest;
|
||||
|
||||
public IDigest WriteDigest => m_writeDigest;
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return m_stream.CanRead; }
|
||||
}
|
||||
|
||||
public sealed override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return m_stream.CanWrite; }
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER || (UNITY_2021_2_OR_NEWER && (NET_STANDARD_2_0 || NET_STANDARD_2_1))
|
||||
public override void CopyTo(Stream destination, int bufferSize)
|
||||
{
|
||||
if (m_readDigest == null)
|
||||
{
|
||||
m_stream.CopyTo(destination, bufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.CopyTo(destination, bufferSize);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
m_stream.Flush();
|
||||
}
|
||||
|
||||
public sealed override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public sealed override long Position
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int n = m_stream.Read(buffer, offset, count);
|
||||
|
||||
if (m_readDigest != null && n > 0)
|
||||
{
|
||||
m_readDigest.BlockUpdate(buffer, offset, n);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override int Read(Span<byte> buffer)
|
||||
{
|
||||
int n = m_stream.Read(buffer);
|
||||
|
||||
if (m_readDigest != null && n > 0)
|
||||
{
|
||||
m_readDigest.BlockUpdate(buffer[..n]);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
int b = m_stream.ReadByte();
|
||||
|
||||
if (m_readDigest != null && b >= 0)
|
||||
{
|
||||
m_readDigest.Update((byte)b);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public sealed override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public sealed override void SetLength(long length)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
m_stream.Write(buffer, offset, count);
|
||||
|
||||
if (m_writeDigest != null && count > 0)
|
||||
{
|
||||
m_writeDigest.BlockUpdate(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_stream.Write(buffer);
|
||||
|
||||
if (m_writeDigest != null && !buffer.IsEmpty)
|
||||
{
|
||||
m_writeDigest.BlockUpdate(buffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
m_stream.WriteByte(value);
|
||||
|
||||
if (m_writeDigest != null)
|
||||
{
|
||||
m_writeDigest.Update(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
m_stream.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/DigestStream.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/DigestStream.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45d9c6fd7124af04c96034082dd6b9de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/MacSink.cs
vendored
Normal file
48
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/MacSink.cs
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO
|
||||
{
|
||||
public sealed class MacSink
|
||||
: BaseOutputStream
|
||||
{
|
||||
private readonly IMac m_mac;
|
||||
|
||||
public MacSink(IMac mac)
|
||||
{
|
||||
m_mac = mac;
|
||||
}
|
||||
|
||||
public IMac Mac => m_mac;
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
Streams.ValidateBufferArguments(buffer, offset, count);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
m_mac.BlockUpdate(buffer, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
if (!buffer.IsEmpty)
|
||||
{
|
||||
m_mac.BlockUpdate(buffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
m_mac.Update(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/MacSink.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/MacSink.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72a51315443a8e343b34f8bf21998b70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
164
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/MacStream.cs
vendored
Normal file
164
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/MacStream.cs
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO
|
||||
{
|
||||
public sealed class MacStream
|
||||
: Stream
|
||||
{
|
||||
private readonly Stream m_stream;
|
||||
private readonly IMac m_readMac;
|
||||
private readonly IMac m_writeMac;
|
||||
|
||||
public MacStream(Stream stream, IMac readMac, IMac writeMac)
|
||||
{
|
||||
m_stream = stream;
|
||||
m_readMac = readMac;
|
||||
m_writeMac = writeMac;
|
||||
}
|
||||
|
||||
public IMac ReadMac => m_readMac;
|
||||
|
||||
public IMac WriteMac => m_writeMac;
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return m_stream.CanRead; }
|
||||
}
|
||||
|
||||
public sealed override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return m_stream.CanWrite; }
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER || (UNITY_2021_2_OR_NEWER && (NET_STANDARD_2_0 || NET_STANDARD_2_1))
|
||||
public override void CopyTo(Stream destination, int bufferSize)
|
||||
{
|
||||
if (m_readMac == null)
|
||||
{
|
||||
m_stream.CopyTo(destination, bufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.CopyTo(destination, bufferSize);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
m_stream.Flush();
|
||||
}
|
||||
|
||||
public sealed override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public sealed override long Position
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int n = m_stream.Read(buffer, offset, count);
|
||||
|
||||
if (m_readMac != null && n > 0)
|
||||
{
|
||||
m_readMac.BlockUpdate(buffer, offset, n);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override int Read(Span<byte> buffer)
|
||||
{
|
||||
int n = m_stream.Read(buffer);
|
||||
|
||||
if (m_readMac != null && n > 0)
|
||||
{
|
||||
m_readMac.BlockUpdate(buffer[..n]);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
int b = m_stream.ReadByte();
|
||||
|
||||
if (m_readMac != null && b >= 0)
|
||||
{
|
||||
m_readMac.Update((byte)b);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public sealed override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public sealed override void SetLength(long length)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
m_stream.Write(buffer, offset, count);
|
||||
|
||||
if (m_writeMac != null && count > 0)
|
||||
{
|
||||
m_writeMac.BlockUpdate(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_stream.Write(buffer);
|
||||
|
||||
if (m_writeMac != null && !buffer.IsEmpty)
|
||||
{
|
||||
m_writeMac.BlockUpdate(buffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
m_stream.WriteByte(value);
|
||||
|
||||
if (m_writeMac != null)
|
||||
{
|
||||
m_writeMac.Update(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
m_stream.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/MacStream.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/MacStream.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d0c074d8940c48459ba755661880b01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/SignerSink.cs
vendored
Normal file
48
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/SignerSink.cs
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO
|
||||
{
|
||||
public sealed class SignerSink
|
||||
: BaseOutputStream
|
||||
{
|
||||
private readonly ISigner m_signer;
|
||||
|
||||
public SignerSink(ISigner signer)
|
||||
{
|
||||
m_signer = signer;
|
||||
}
|
||||
|
||||
public ISigner Signer => m_signer;
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
Streams.ValidateBufferArguments(buffer, offset, count);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
m_signer.BlockUpdate(buffer, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
if (!buffer.IsEmpty)
|
||||
{
|
||||
m_signer.BlockUpdate(buffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
m_signer.Update(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/SignerSink.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/SignerSink.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51f8063ec36701c489b27c93b03f7beb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
164
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/SignerStream.cs
vendored
Normal file
164
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/SignerStream.cs
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO
|
||||
{
|
||||
public sealed class SignerStream
|
||||
: Stream
|
||||
{
|
||||
private readonly Stream stream;
|
||||
private readonly ISigner inSigner;
|
||||
private readonly ISigner outSigner;
|
||||
|
||||
public SignerStream(Stream stream, ISigner readSigner, ISigner writeSigner)
|
||||
{
|
||||
this.stream = stream;
|
||||
this.inSigner = readSigner;
|
||||
this.outSigner = writeSigner;
|
||||
}
|
||||
|
||||
public ISigner ReadSigner => inSigner;
|
||||
|
||||
public ISigner WriteSigner => outSigner;
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return stream.CanRead; }
|
||||
}
|
||||
|
||||
public sealed override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return stream.CanWrite; }
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER || (UNITY_2021_2_OR_NEWER && (NET_STANDARD_2_0 || NET_STANDARD_2_1))
|
||||
public override void CopyTo(Stream destination, int bufferSize)
|
||||
{
|
||||
if (inSigner == null)
|
||||
{
|
||||
stream.CopyTo(destination, bufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.CopyTo(destination, bufferSize);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
stream.Flush();
|
||||
}
|
||||
|
||||
public sealed override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public sealed override long Position
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int n = stream.Read(buffer, offset, count);
|
||||
|
||||
if (inSigner != null && n > 0)
|
||||
{
|
||||
inSigner.BlockUpdate(buffer, offset, n);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override int Read(Span<byte> buffer)
|
||||
{
|
||||
int n = stream.Read(buffer);
|
||||
|
||||
if (inSigner != null && n > 0)
|
||||
{
|
||||
inSigner.BlockUpdate(buffer[..n]);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
int b = stream.ReadByte();
|
||||
|
||||
if (inSigner != null && b >= 0)
|
||||
{
|
||||
inSigner.Update((byte)b);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public sealed override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public sealed override void SetLength(long length)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
stream.Write(buffer, offset, count);
|
||||
|
||||
if (outSigner != null && count > 0)
|
||||
{
|
||||
outSigner.BlockUpdate(buffer, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
stream.Write(buffer);
|
||||
|
||||
if (outSigner != null && !buffer.IsEmpty)
|
||||
{
|
||||
outSigner.BlockUpdate(buffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
stream.WriteByte(value);
|
||||
|
||||
if (outSigner != null)
|
||||
{
|
||||
outSigner.Update(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
stream.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/SignerStream.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/io/SignerStream.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72d1fff68451d4042be44c5d24c1b086
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user