提交Unity 联机Pro

This commit is contained in:
PC-20230316NUNE\Administrator
2024-08-17 14:27:18 +08:00
parent f00193b000
commit 894100ae37
7448 changed files with 854473 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ba8c42c46160a54db30a3ddfae9ed76
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,255 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.Raw;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
/**
* BigInteger utilities.
*/
public static class BigIntegers
{
public static readonly BigInteger Zero = BigInteger.Zero;
public static readonly BigInteger One = BigInteger.One;
private const int MaxIterations = 1000;
/**
* Return the passed in value as an unsigned byte array.
*
* @param value the value to be converted.
* @return a byte array without a leading zero byte if present in the signed encoding.
*/
public static byte[] AsUnsignedByteArray(BigInteger n)
{
return n.ToByteArrayUnsigned();
}
/**
* Return the passed in value as an unsigned byte array of the specified length, padded with
* leading zeros as necessary.
* @param length the fixed length of the result.
* @param n the value to be converted.
* @return a byte array padded to a fixed length with leading zeros.
*/
public static byte[] AsUnsignedByteArray(int length, BigInteger n)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
int bytesLength = n.GetLengthofByteArrayUnsigned();
if (bytesLength > length)
throw new ArgumentException("standard length exceeded", nameof(n));
byte[] bytes = new byte[length];
n.ToByteArrayUnsigned(bytes.AsSpan(length - bytesLength));
return bytes;
#else
byte[] bytes = n.ToByteArrayUnsigned();
int bytesLength = bytes.Length;
if (bytesLength == length)
return bytes;
if (bytesLength > length)
throw new ArgumentException("standard length exceeded", nameof(n));
byte[] tmp = new byte[length];
Array.Copy(bytes, 0, tmp, length - bytesLength, bytesLength);
return tmp;
#endif
}
/**
* Write the passed in value as unsigned bytes to the specified buffer range, padded with
* leading zeros as necessary.
*
* @param n
* the value to be converted.
* @param buf
* the buffer to which the value is written.
* @param off
* the start offset in array <code>buf</code> at which the data is written.
* @param len
* the fixed length of data written (possibly padded with leading zeros).
*/
public static void AsUnsignedByteArray(BigInteger n, byte[] buf, int off, int len)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
AsUnsignedByteArray(n, buf.AsSpan(off, len));
#else
byte[] bytes = n.ToByteArrayUnsigned();
int bytesLength = bytes.Length;
if (bytesLength > len)
throw new ArgumentException("standard length exceeded", nameof(n));
int padLen = len - bytesLength;
Arrays.Fill(buf, off, off + padLen, 0);
Array.Copy(bytes, 0, buf, off + padLen, bytesLength);
#endif
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public static void AsUnsignedByteArray(BigInteger n, Span<byte> buf)
{
int bytesLength = n.GetLengthofByteArrayUnsigned();
if (bytesLength > buf.Length)
throw new ArgumentException("standard length exceeded", nameof(n));
buf[..^bytesLength].Fill(0x00);
n.ToByteArrayUnsigned(buf[^bytesLength..]);
}
#endif
/// <summary>
/// Creates a Random BigInteger from the secure random of a given bit length.
/// </summary>
/// <param name="bitLength"></param>
/// <param name="secureRandom"></param>
/// <returns></returns>
public static BigInteger CreateRandomBigInteger(int bitLength, SecureRandom secureRandom)
{
return new BigInteger(bitLength, secureRandom);
}
/**
* Return a random BigInteger not less than 'min' and not greater than 'max'
*
* @param min the least value that may be generated
* @param max the greatest value that may be generated
* @param random the source of randomness
* @return a random BigInteger value in the range [min,max]
*/
public static BigInteger CreateRandomInRange(
BigInteger min,
BigInteger max,
// TODO Should have been just Random class
SecureRandom random)
{
int cmp = min.CompareTo(max);
if (cmp >= 0)
{
if (cmp > 0)
throw new ArgumentException("'min' may not be greater than 'max'");
return min;
}
if (min.BitLength > max.BitLength / 2)
{
return CreateRandomInRange(BigInteger.Zero, max.Subtract(min), random).Add(min);
}
for (int i = 0; i < MaxIterations; ++i)
{
BigInteger x = new BigInteger(max.BitLength, random);
if (x.CompareTo(min) >= 0 && x.CompareTo(max) <= 0)
{
return x;
}
}
// fall back to a faster (restricted) method
return new BigInteger(max.Subtract(min).BitLength - 1, random).Add(min);
}
public static BigInteger ModOddInverse(BigInteger M, BigInteger X)
{
if (!M.TestBit(0))
throw new ArgumentException("must be odd", "M");
if (M.SignValue != 1)
throw new ArithmeticException("BigInteger: modulus not positive");
if (X.SignValue < 0 || X.CompareTo(M) >= 0)
{
X = X.Mod(M);
}
int bits = M.BitLength;
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
if (bits <= 2048)
{
int len = Nat.GetLengthForBits(bits);
Span<uint> m = stackalloc uint[len];
Span<uint> x = stackalloc uint[len];
Span<uint> z = stackalloc uint[len];
Nat.FromBigInteger(bits, M, m);
Nat.FromBigInteger(bits, X, x);
if (0 == Mod.ModOddInverse(m, x, z))
throw new ArithmeticException("BigInteger not invertible");
return Nat.ToBigInteger(len, z);
}
else
#endif
{
uint[] m = Nat.FromBigInteger(bits, M);
uint[] x = Nat.FromBigInteger(bits, X);
int len = m.Length;
uint[] z = Nat.Create(len);
if (0 == Mod.ModOddInverse(m, x, z))
throw new ArithmeticException("BigInteger not invertible");
return Nat.ToBigInteger(len, z);
}
}
public static BigInteger ModOddInverseVar(BigInteger M, BigInteger X)
{
if (!M.TestBit(0))
throw new ArgumentException("must be odd", "M");
if (M.SignValue != 1)
throw new ArithmeticException("BigInteger: modulus not positive");
if (M.Equals(One))
return Zero;
if (X.SignValue < 0 || X.CompareTo(M) >= 0)
{
X = X.Mod(M);
}
if (X.Equals(One))
return One;
int bits = M.BitLength;
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
if (bits <= 2048)
{
int len = Nat.GetLengthForBits(bits);
Span<uint> m = stackalloc uint[len];
Span<uint> x = stackalloc uint[len];
Span<uint> z = stackalloc uint[len];
Nat.FromBigInteger(bits, M, m);
Nat.FromBigInteger(bits, X, x);
if (!Mod.ModOddInverseVar(m, x, z))
throw new ArithmeticException("BigInteger not invertible");
return Nat.ToBigInteger(len, z);
}
else
#endif
{
uint[] m = Nat.FromBigInteger(bits, M);
uint[] x = Nat.FromBigInteger(bits, X);
int len = m.Length;
uint[] z = Nat.Create(len);
if (!Mod.ModOddInverseVar(m, x, z))
throw new ArithmeticException("BigInteger not invertible");
return Nat.ToBigInteger(len, z);
}
}
public static int GetByteLength(BigInteger n)
{
return n.GetLengthofByteArray();
}
public static int GetUnsignedByteLength(BigInteger n)
{
return n.GetLengthofByteArrayUnsigned();
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ebdb832f8f30d6c44a1a40e88b4f3b17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
public static class Bytes
{
public const int NumBits = 8;
public const int NumBytes = 1;
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b97fb38c4abab044aa82f618c5a2bca4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
internal static class Enums
{
internal static TEnum GetEnumValue<TEnum>(string s)
where TEnum : struct, Enum
{
// We only want to parse single named constants
if (s.Length > 0 && char.IsLetter(s[0]) && s.IndexOf(',') < 0)
{
s = s.Replace('-', '_');
s = s.Replace('/', '_');
#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
return Enum.Parse<TEnum>(s, false);
#else
return (TEnum)Enum.Parse(typeof(TEnum), s, false);
#endif
}
throw new ArgumentException();
}
internal static TEnum[] GetEnumValues<TEnum>()
where TEnum : struct, Enum
{
#if NET5_0_OR_GREATER
return Enum.GetValues<TEnum>();
#else
return (TEnum[])Enum.GetValues(typeof(TEnum));
#endif
}
internal static TEnum GetArbitraryValue<TEnum>()
where TEnum : struct, Enum
{
TEnum[] values = GetEnumValues<TEnum>();
int pos = (int)(DateTimeUtilities.CurrentUnixMs() & int.MaxValue) % values.Length;
return values[pos];
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5bc960ec18e889148ae2e52c6be70ec4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
public interface IEncodable
{
/// <summary>Return a byte array representing the implementing object.</summary>
/// <returns>An encoding of this object as a byte array.</returns>
/// <exception cref="IOException"/>
byte[] GetEncoded();
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 361d48ffae4de8140b1af6bbeb70bb80
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
public interface IMemoable
{
/// <summary>
/// Produce a copy of this object with its configuration and in its current state.
/// </summary>
/// <remarks>
/// The returned object may be used simply to store the state, or may be used as a similar object
/// starting from the copied state.
/// </remarks>
IMemoable Copy();
/// <summary>
/// Restore a copied object state into this object.
/// </summary>
/// <remarks>
/// Implementations of this method <em>should</em> try to avoid or minimise memory allocation to perform the reset.
/// </remarks>
/// <param name="other">an object originally {@link #copy() copied} from an object of the same type as this instance.</param>
/// <exception cref="InvalidCastException">if the provided object is not of the correct type.</exception>
/// <exception cref="MemoableResetException">if the <b>other</b> parameter is in some other way invalid.</exception>
void Reset(IMemoable other);
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5094da18f6285e498789845689aac6f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,162 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
using System.Buffers.Binary;
#endif
#if NETCOREAPP3_0_OR_GREATER
using System.Numerics;
using System.Runtime.Intrinsics.X86;
#endif
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.Raw;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
public static class Integers
{
public const int NumBits = 32;
public const int NumBytes = 4;
private static readonly byte[] DeBruijnTZ = {
0x1F, 0x00, 0x1B, 0x01, 0x1C, 0x0D, 0x17, 0x02, 0x1D, 0x15, 0x13, 0x0E, 0x18, 0x10, 0x03, 0x07,
0x1E, 0x1A, 0x0C, 0x16, 0x14, 0x12, 0x0F, 0x06, 0x19, 0x0B, 0x11, 0x05, 0x0A, 0x04, 0x09, 0x08 };
public static int HighestOneBit(int i)
{
return (int)HighestOneBit((uint)i);
}
[CLSCompliant(false)]
public static uint HighestOneBit(uint i)
{
i |= i >> 1;
i |= i >> 2;
i |= i >> 4;
i |= i >> 8;
i |= i >> 16;
return i - (i >> 1);
}
public static int LowestOneBit(int i)
{
return i & -i;
}
[CLSCompliant(false)]
public static uint LowestOneBit(uint i)
{
return (uint)LowestOneBit((int)i);
}
public static int NumberOfLeadingZeros(int i)
{
#if NETCOREAPP3_0_OR_GREATER
if (Lzcnt.IsSupported)
{
return (int)Lzcnt.LeadingZeroCount((uint)i);
}
#endif
if (i <= 0)
return (~i >> (31 - 5)) & (1 << 5);
uint u = (uint)i;
int n = 1;
if (0 == (u >> 16)) { n += 16; u <<= 16; }
if (0 == (u >> 24)) { n += 8; u <<= 8; }
if (0 == (u >> 28)) { n += 4; u <<= 4; }
if (0 == (u >> 30)) { n += 2; u <<= 2; }
n -= (int)(u >> 31);
return n;
}
public static int NumberOfTrailingZeros(int i)
{
#if NETCOREAPP3_0_OR_GREATER
if (Bmi1.IsSupported)
{
return (int)Bmi1.TrailingZeroCount((uint)i);
}
#endif
int n = DeBruijnTZ[(uint)((i & -i) * 0x0EF96A62) >> 27];
int m = (((i & 0xFFFF) | (int)((uint)i >> 16)) - 1) >> 31;
return n - m;
}
public static int Reverse(int i)
{
return (int)Reverse((uint)i);
}
[CLSCompliant(false)]
public static uint Reverse(uint i)
{
i = Bits.BitPermuteStepSimple(i, 0x55555555U, 1);
i = Bits.BitPermuteStepSimple(i, 0x33333333U, 2);
i = Bits.BitPermuteStepSimple(i, 0x0F0F0F0FU, 4);
return ReverseBytes(i);
}
public static int ReverseBytes(int i)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return BinaryPrimitives.ReverseEndianness(i);
#else
return (int)ReverseBytes((uint)i);
#endif
}
[CLSCompliant(false)]
public static uint ReverseBytes(uint i)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return BinaryPrimitives.ReverseEndianness(i);
#else
return RotateLeft(i & 0xFF00FF00U, 8) |
RotateLeft(i & 0x00FF00FFU, 24);
#endif
}
public static int RotateLeft(int i, int distance)
{
#if NETCOREAPP3_0_OR_GREATER
return (int)BitOperations.RotateLeft((uint)i, distance);
#else
return (i << distance) | (int)((uint)i >> -distance);
#endif
}
[CLSCompliant(false)]
public static uint RotateLeft(uint i, int distance)
{
#if NETCOREAPP3_0_OR_GREATER
return BitOperations.RotateLeft(i, distance);
#else
return (i << distance) | (i >> -distance);
#endif
}
public static int RotateRight(int i, int distance)
{
#if NETCOREAPP3_0_OR_GREATER
return (int)BitOperations.RotateRight((uint)i, distance);
#else
return (int)((uint)i >> distance) | (i << -distance);
#endif
}
[CLSCompliant(false)]
public static uint RotateRight(uint i, int distance)
{
#if NETCOREAPP3_0_OR_GREATER
return BitOperations.RotateRight(i, distance);
#else
return (i >> distance) | (i << -distance);
#endif
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3188e9987cc8be145a324b947c7e7475
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,163 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
using System.Buffers.Binary;
#endif
#if NETCOREAPP3_0_OR_GREATER
using System.Numerics;
using System.Runtime.Intrinsics.X86;
#endif
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.Raw;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
public static class Longs
{
public const int NumBits = 64;
public const int NumBytes = 8;
private static readonly byte[] DeBruijnTZ = {
0x3F, 0x00, 0x01, 0x34, 0x02, 0x06, 0x35, 0x1A, 0x03, 0x25, 0x28, 0x07, 0x21, 0x36, 0x2F, 0x1B,
0x3D, 0x04, 0x26, 0x2D, 0x2B, 0x29, 0x15, 0x08, 0x17, 0x22, 0x3A, 0x37, 0x30, 0x11, 0x1C, 0x0A,
0x3E, 0x33, 0x05, 0x19, 0x24, 0x27, 0x20, 0x2E, 0x3C, 0x2C, 0x2A, 0x14, 0x16, 0x39, 0x10, 0x09,
0x32, 0x18, 0x23, 0x1F, 0x3B, 0x13, 0x38, 0x0F, 0x31, 0x1E, 0x12, 0x0E, 0x1D, 0x0D, 0x0C, 0x0B };
public static long HighestOneBit(long i)
{
return (long)HighestOneBit((ulong)i);
}
[CLSCompliant(false)]
public static ulong HighestOneBit(ulong i)
{
i |= i >> 1;
i |= i >> 2;
i |= i >> 4;
i |= i >> 8;
i |= i >> 16;
i |= i >> 32;
return i - (i >> 1);
}
public static long LowestOneBit(long i)
{
return i & -i;
}
[CLSCompliant(false)]
public static ulong LowestOneBit(ulong i)
{
return (ulong)LowestOneBit((long)i);
}
public static int NumberOfLeadingZeros(long i)
{
#if NETCOREAPP3_0_OR_GREATER
if (Lzcnt.X64.IsSupported)
{
return (int)Lzcnt.X64.LeadingZeroCount((ulong)i);
}
#endif
int x = (int)(i >> 32), n = 0;
if (x == 0)
{
n = 32;
x = (int)i;
}
return n + Integers.NumberOfLeadingZeros(x);
}
public static int NumberOfTrailingZeros(long i)
{
#if NETCOREAPP3_0_OR_GREATER
if (Bmi1.X64.IsSupported)
{
return (int)Bmi1.X64.TrailingZeroCount((ulong)i);
}
#endif
int n = DeBruijnTZ[(uint)((ulong)((i & -i) * 0x045FBAC7992A70DAL) >> 58)];
long m = (((i & 0xFFFFFFFFL) | (long)((ulong)i >> 32)) - 1L) >> 63;
return n - (int)m;
}
public static long Reverse(long i)
{
return (long)Reverse((ulong)i);
}
[CLSCompliant(false)]
public static ulong Reverse(ulong i)
{
i = Bits.BitPermuteStepSimple(i, 0x5555555555555555UL, 1);
i = Bits.BitPermuteStepSimple(i, 0x3333333333333333UL, 2);
i = Bits.BitPermuteStepSimple(i, 0x0F0F0F0F0F0F0F0FUL, 4);
return ReverseBytes(i);
}
public static long ReverseBytes(long i)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return BinaryPrimitives.ReverseEndianness(i);
#else
return (long)ReverseBytes((ulong)i);
#endif
}
[CLSCompliant(false)]
public static ulong ReverseBytes(ulong i)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return BinaryPrimitives.ReverseEndianness(i);
#else
return RotateLeft(i & 0xFF000000FF000000UL, 8) |
RotateLeft(i & 0x00FF000000FF0000UL, 24) |
RotateLeft(i & 0x0000FF000000FF00UL, 40) |
RotateLeft(i & 0x000000FF000000FFUL, 56);
#endif
}
public static long RotateLeft(long i, int distance)
{
#if NETCOREAPP3_0_OR_GREATER
return (long)BitOperations.RotateLeft((ulong)i, distance);
#else
return (i << distance) | (long)((ulong)i >> -distance);
#endif
}
[CLSCompliant(false)]
public static ulong RotateLeft(ulong i, int distance)
{
#if NETCOREAPP3_0_OR_GREATER
return BitOperations.RotateLeft(i, distance);
#else
return (i << distance) | (i >> -distance);
#endif
}
public static long RotateRight(long i, int distance)
{
#if NETCOREAPP3_0_OR_GREATER
return (long)BitOperations.RotateRight((ulong)i, distance);
#else
return (long)((ulong)i >> distance) | (i << -distance);
#endif
}
[CLSCompliant(false)]
public static ulong RotateRight(ulong i, int distance)
{
#if NETCOREAPP3_0_OR_GREATER
return BitOperations.RotateRight(i, distance);
#else
return (i >> distance) | (i << -distance);
#endif
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3caeabba050d9394fa0dd0457df4fb0d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Runtime.Serialization;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
/**
* Exception to be thrown on a failure to reset an object implementing Memoable.
* <p>
* The exception extends InvalidCastException to enable users to have a single handling case,
* only introducing specific handling of this one if required.
* </p>
*/
[Serializable]
public class MemoableResetException
: InvalidCastException
{
public MemoableResetException()
: base()
{
}
public MemoableResetException(string message)
: base(message)
{
}
public MemoableResetException(string message, Exception innerException)
: base(message, innerException)
{
}
protected MemoableResetException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20a8024aade27594aacfebde1c7c76f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
public static class Objects
{
public static int GetHashCode(object obj)
{
return null == obj ? 0 : obj.GetHashCode();
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 81337102137f3814c94821e995ceb992
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Globalization;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
internal static class Platform
{
private static readonly CompareInfo InvariantCompareInfo = CultureInfo.InvariantCulture.CompareInfo;
internal static bool EqualsIgnoreCase(string a, string b)
{
return string.Equals(a, b, StringComparison.OrdinalIgnoreCase);
}
internal static string GetEnvironmentVariable(string variable)
{
try
{
return Environment.GetEnvironmentVariable(variable);
}
catch (System.Security.SecurityException)
{
// We don't have the required permission to read this environment variable,
// which is fine, just act as if it's not set
return null;
}
}
internal static int IndexOf(string source, char value)
{
return InvariantCompareInfo.IndexOf(source, value, CompareOptions.Ordinal);
}
internal static int IndexOf(string source, string value)
{
return InvariantCompareInfo.IndexOf(source, value, CompareOptions.Ordinal);
}
internal static int IndexOf(string source, char value, int startIndex)
{
return InvariantCompareInfo.IndexOf(source, value, startIndex, CompareOptions.Ordinal);
}
internal static int IndexOf(string source, string value, int startIndex)
{
return InvariantCompareInfo.IndexOf(source, value, startIndex, CompareOptions.Ordinal);
}
internal static int LastIndexOf(string source, string value)
{
return InvariantCompareInfo.LastIndexOf(source, value, CompareOptions.Ordinal);
}
internal static bool StartsWith(string source, string prefix)
{
return InvariantCompareInfo.IsPrefix(source, prefix, CompareOptions.Ordinal);
}
internal static bool EndsWith(string source, string suffix)
{
return InvariantCompareInfo.IsSuffix(source, suffix, CompareOptions.Ordinal);
}
internal static string GetTypeName(object obj)
{
return obj.GetType().FullName;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 34ac2529ba9563b4b95ceece9c95095a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
using System.Buffers.Binary;
#endif
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
public static class Shorts
{
public const int NumBits = 16;
public const int NumBytes = 2;
public static short ReverseBytes(short i)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return BinaryPrimitives.ReverseEndianness(i);
#else
return RotateLeft(i, 8);
#endif
}
[CLSCompliant(false)]
public static ushort ReverseBytes(ushort i)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return BinaryPrimitives.ReverseEndianness(i);
#else
return RotateLeft(i, 8);
#endif
}
public static short RotateLeft(short i, int distance)
{
return (short)RotateLeft((ushort)i, distance);
}
[CLSCompliant(false)]
public static ushort RotateLeft(ushort i, int distance)
{
return (ushort)((i << distance) | (i >> (16 - distance)));
}
public static short RotateRight(short i, int distance)
{
return (short)RotateRight((ushort)i, distance);
}
[CLSCompliant(false)]
public static ushort RotateRight(ushort i, int distance)
{
return (ushort)((i >> distance) | (i << (16 - distance)));
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 64f79d897b653fb48a890b7df96822bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
using System;
using System.Runtime.CompilerServices;
//#nullable enable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
internal static class Spans
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void CopyFrom<T>(this Span<T> output, ReadOnlySpan<T> input)
{
input[..output.Length].CopyTo(output);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Span<T> FromNullable<T>(T[]? array)
{
return array == null ? Span<T>.Empty : array.AsSpan();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Span<T> FromNullable<T>(T[]? array, int start)
{
return array == null ? Span<T>.Empty : array.AsSpan(start);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ReadOnlySpan<T> FromNullableReadOnly<T>(T[]? array)
{
return array == null ? Span<T>.Empty : array.AsSpan();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ReadOnlySpan<T> FromNullableReadOnly<T>(T[]? array, int start)
{
return array == null ? Span<T>.Empty : array.AsSpan(start);
}
}
}
#endif
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1011a1c49304df47bc72fae41c46624
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Text;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities
{
/// <summary> General string utilities.</summary>
public static class Strings
{
internal static bool IsOneOf(string s, params string[] candidates)
{
foreach (string candidate in candidates)
{
if (s == candidate)
return true;
}
return false;
}
public static string FromByteArray(byte[] bs)
{
char[] cs = new char[bs.Length];
for (int i = 0; i < cs.Length; ++i)
{
cs[i] = Convert.ToChar(bs[i]);
}
return new string(cs);
}
public static byte[] ToByteArray(char[] cs)
{
byte[] bs = new byte[cs.Length];
for (int i = 0; i < bs.Length; ++i)
{
bs[i] = Convert.ToByte(cs[i]);
}
return bs;
}
public static byte[] ToByteArray(string s)
{
byte[] bs = new byte[s.Length];
for (int i = 0; i < bs.Length; ++i)
{
bs[i] = Convert.ToByte(s[i]);
}
return bs;
}
public static string FromAsciiByteArray(byte[] bytes)
{
return Encoding.ASCII.GetString(bytes);
}
public static byte[] ToAsciiByteArray(char[] cs)
{
return Encoding.ASCII.GetBytes(cs);
}
public static byte[] ToAsciiByteArray(string s)
{
return Encoding.ASCII.GetBytes(s);
}
public static string FromUtf8ByteArray(byte[] bytes)
{
return Encoding.UTF8.GetString(bytes);
}
public static byte[] ToUtf8ByteArray(char[] cs)
{
return Encoding.UTF8.GetBytes(cs);
}
public static byte[] ToUtf8ByteArray(string s)
{
return Encoding.UTF8.GetBytes(s);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1102d66cf36a07545b4ef549eb96e85e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 71a439503264c6c4ba4e2d3ebdd0fc1e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* This package is based on the work done by Keiron Liddle, Aftex Software
* <keiron@aftexsw.com> to whom the Ant project is very grateful for his
* great code.
*/
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Bzip2
{
/**
* Base class for both the compress and decompress classes.
* Holds common arrays, and static data.
*
* @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
*/
public class BZip2Constants
{
public const int baseBlockSize = 100000;
public const int MAX_ALPHA_SIZE = 258;
public const int MAX_CODE_LEN = 20;
public const int MAX_CODE_LEN_GEN = 17;
public const int RUNA = 0;
public const int RUNB = 1;
public const int N_GROUPS = 6;
public const int G_SIZE = 50;
public const int N_ITERS = 4;
public const int MAX_SELECTORS = 2 + (900000 / G_SIZE);
public const int NUM_OVERSHOOT_BYTES = 20;
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 51385589e08abc14c881532858ab77aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,813 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* This package is based on the work done by Keiron Liddle, Aftex Software
* <keiron@aftexsw.com> to whom the Ant project is very grateful for his
* great code.
*/
using System;
using System.Diagnostics;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Bzip2
{
/**
* An input stream that decompresses from the BZip2 format (with the file
* header chars) to be read as any other stream.
*
* @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
*
* <b>NB:</b> note this class has been modified to read the leading BZ from the
* start of the BZIP2 stream to make it compatible with other PGP programs.
*/
public class CBZip2InputStream
: BaseInputStream
{
/*
index of the last char in the block, so
the block size == last + 1.
*/
private int last;
/*
index in zptr[] of original string after sorting.
*/
private int origPtr;
/*
always: in the range 0 .. 9.
The current block size is 100000 * this number.
*/
private int blockSize100k;
private int bsBuff;
private int bsLive;
private readonly CRC m_blockCrc = new CRC();
private int nInUse;
private byte[] seqToUnseq = new byte[256];
private byte[] m_selectors = new byte[BZip2Constants.MAX_SELECTORS];
private int[] tt;
private byte[] ll8;
/*
freq table collected to save a pass over the data
during decompression.
*/
private int[] unzftab = new int[256];
private int[][] limit = CreateIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_CODE_LEN + 1);
private int[][] basev = CreateIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_CODE_LEN + 1);
private int[][] perm = CreateIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
private int[] minLens = new int[BZip2Constants.N_GROUPS];
private Stream bsStream;
private bool streamEnd = false;
private int currentByte = -1;
private const int RAND_PART_B_STATE = 1;
private const int RAND_PART_C_STATE = 2;
private const int NO_RAND_PART_B_STATE = 3;
private const int NO_RAND_PART_C_STATE = 4;
private int currentState = 0;
private int m_expectedBlockCrc, m_expectedStreamCrc, m_streamCrc;
int i2, count, chPrev, ch2;
int i, tPos;
int rNToGo = 0;
int rTPos = 0;
int j2;
int z;
public CBZip2InputStream(Stream zStream)
{
ll8 = null;
tt = null;
bsStream = zStream;
bsLive = 0;
bsBuff = 0;
int magic1 = bsStream.ReadByte();
int magic2 = bsStream.ReadByte();
int version = bsStream.ReadByte();
int level = bsStream.ReadByte();
if (level < 0)
throw new EndOfStreamException();
if (magic1 != 'B' | magic2 != 'Z' | version != 'h' | level < '1' | level > '9')
throw new IOException("Invalid stream header");
blockSize100k = level - '0';
int n = BZip2Constants.baseBlockSize * blockSize100k;
ll8 = new byte[n];
tt = new int[n];
m_streamCrc = 0;
BeginBlock();
}
public override int Read(byte[] buffer, int offset, int count)
{
Streams.ValidateBufferArguments(buffer, offset, count);
/*
* TODO The base class implementation allows to return partial data if/when ReadByte throws. That would be
* be preferable here too (so don't override), but it would require that exceptions cause this instance to
* permanently fail, and that needs review.
*/
int pos = 0;
while (pos < count)
{
int b = ReadByte();
if (b < 0)
break;
buffer[offset + pos++] = (byte)b;
}
return pos;
}
public override int ReadByte()
{
if (streamEnd)
return -1;
int result = currentByte;
switch (currentState)
{
case RAND_PART_B_STATE:
SetupRandPartB();
break;
case RAND_PART_C_STATE:
SetupRandPartC();
break;
case NO_RAND_PART_B_STATE:
SetupNoRandPartB();
break;
case NO_RAND_PART_C_STATE:
SetupNoRandPartC();
break;
default:
throw new InvalidOperationException();
}
return result;
}
private void BeginBlock()
{
long magic48 = BsGetLong48();
if (magic48 != 0x314159265359L)
{
if (magic48 != 0x177245385090L)
throw new IOException("Block header error");
m_expectedStreamCrc = BsGetInt32();
if (m_expectedStreamCrc != m_streamCrc)
throw new IOException("Stream CRC error");
BsFinishedWithStream();
streamEnd = true;
return;
}
m_expectedBlockCrc = BsGetInt32();
bool blockRandomised = BsGetBit() == 1;
GetAndMoveToFrontDecode();
m_blockCrc.Initialise();
int[] cftab = new int[257];
{
int accum = 0;
cftab[0] = 0;
for (i = 0; i < 256; ++i)
{
accum += unzftab[i];
cftab[i + 1] = accum;
}
if (accum != (last + 1))
throw new InvalidOperationException();
}
for (i = 0; i <= last; i++)
{
byte ch = ll8[i];
tt[cftab[ch]++] = i;
}
tPos = tt[origPtr];
count = 0;
i2 = 0;
ch2 = 256; /* not a char and not EOF */
if (blockRandomised)
{
rNToGo = 0;
rTPos = 0;
SetupRandPartA();
}
else
{
SetupNoRandPartA();
}
}
private void EndBlock()
{
int blockFinalCrc = m_blockCrc.GetFinal();
if (m_expectedBlockCrc != blockFinalCrc)
throw new IOException("Block CRC error");
m_streamCrc = Integers.RotateLeft(m_streamCrc, 1) ^ blockFinalCrc;
}
private void BsFinishedWithStream()
{
try
{
if (this.bsStream != null)
{
this.bsStream.Dispose();
this.bsStream = null;
}
}
catch
{
//ignore
}
}
private int BsGetBit()
{
if (bsLive == 0)
{
bsBuff = RequireByte();
bsLive = 7;
return (int)((uint)bsBuff >> 7);
}
--bsLive;
return (bsBuff >> bsLive) & 1;
}
private int BsGetBits(int n)
{
Debug.Assert(1 <= n && n <= 24);
while (bsLive < n)
{
bsBuff = (bsBuff << 8) | RequireByte();
bsLive += 8;
}
bsLive -= n;
return (bsBuff >> bsLive) & ((1 << n) - 1);
}
private int BsGetBitsSmall(int n)
{
Debug.Assert(1 <= n && n <= 8);
if (bsLive < n)
{
bsBuff = (bsBuff << 8) | RequireByte();
bsLive += 8;
}
bsLive -= n;
return (bsBuff >> bsLive) & ((1 << n) - 1);
}
private int BsGetInt32()
{
int u = BsGetBits(16) << 16;
return u | BsGetBits(16);
}
private long BsGetLong48()
{
long u = (long)BsGetBits(24) << 24;
return u | (long)BsGetBits(24);
}
private void HbCreateDecodeTables(int[] limit, int[] basev, int[] perm, byte[] length, int minLen, int maxLen,
int alphaSize)
{
Array.Clear(basev, 0, basev.Length);
Array.Clear(limit, 0, limit.Length);
int pp = 0, baseVal = 0;
for (int i = minLen; i <= maxLen; i++)
{
for (int j = 0; j < alphaSize; j++)
{
if (length[j] == i)
{
perm[pp++] = j;
}
}
basev[i] = baseVal;
limit[i] = baseVal + pp;
baseVal += baseVal + pp;
}
}
private int RecvDecodingTables()
{
int i, j;
nInUse = 0;
/* Receive the mapping table */
int inUse16 = BsGetBits(16);
for (i = 0; i < 16; ++i)
{
if ((inUse16 & (0x8000 >> i)) != 0)
{
int inUse = BsGetBits(16);
int i16 = i * 16;
for (j = 0; j < 16; ++j)
{
if ((inUse & (0x8000 >> j)) != 0)
{
seqToUnseq[nInUse++] = (byte)(i16 + j);
}
}
}
}
if (nInUse < 1)
throw new InvalidOperationException();
int alphaSize = nInUse + 2;
/* Now the selectors */
int nGroups = BsGetBitsSmall(3);
if (nGroups < 2 || nGroups > BZip2Constants.N_GROUPS)
throw new InvalidOperationException();
int nSelectors = BsGetBits(15);
if (nSelectors < 1)
throw new InvalidOperationException();
uint mtfGroups = 0x00543210U;
for (i = 0; i < nSelectors; i++)
{
int mtfSelector = 0;
while (BsGetBit() == 1)
{
if (++mtfSelector >= nGroups)
throw new InvalidOperationException();
}
// Ignore declared selectors in excess of the maximum usable number
if (i >= BZip2Constants.MAX_SELECTORS)
continue;
// Undo the MTF value for the selector.
switch (mtfSelector)
{
case 0:
break;
case 1:
mtfGroups = (mtfGroups >> 4) & 0x00000FU | (mtfGroups << 4) & 0x0000F0U | mtfGroups & 0xFFFF00U;
break;
case 2:
mtfGroups = (mtfGroups >> 8) & 0x00000FU | (mtfGroups << 4) & 0x000FF0U | mtfGroups & 0xFFF000U;
break;
case 3:
mtfGroups = (mtfGroups >> 12) & 0x00000FU | (mtfGroups << 4) & 0x00FFF0U | mtfGroups & 0xFF0000U;
break;
case 4:
mtfGroups = (mtfGroups >> 16) & 0x00000FU | (mtfGroups << 4) & 0x0FFFF0U | mtfGroups & 0xF00000U;
break;
case 5:
mtfGroups = (mtfGroups >> 20) & 0x00000FU | (mtfGroups << 4) & 0xFFFFF0U;
break;
default:
throw new InvalidOperationException();
}
m_selectors[i] = (byte)(mtfGroups & 0xF);
}
byte[] len_t = new byte[alphaSize];
/* Now the coding tables */
for (int t = 0; t < nGroups; t++)
{
int maxLen = 0, minLen = 32;
int curr = BsGetBitsSmall(5);
if ((curr < 1) | (curr > BZip2Constants.MAX_CODE_LEN))
throw new InvalidOperationException();
for (i = 0; i < alphaSize; i++)
{
int markerBit = BsGetBit();
while (markerBit != 0)
{
int nextTwoBits = BsGetBitsSmall(2);
curr += 1 - (nextTwoBits & 2);
if ((curr < 1) | (curr > BZip2Constants.MAX_CODE_LEN))
throw new InvalidOperationException();
markerBit = nextTwoBits & 1;
}
len_t[i] = (byte)curr;
maxLen = System.Math.Max(maxLen, curr);
minLen = System.Math.Min(minLen, curr);
}
/* Create the Huffman decoding tables */
HbCreateDecodeTables(limit[t], basev[t], perm[t], len_t, minLen, maxLen, alphaSize);
minLens[t] = minLen;
}
return nSelectors;
}
private void GetAndMoveToFrontDecode()
{
int i, j, nextSym;
int limitLast = BZip2Constants.baseBlockSize * blockSize100k;
origPtr = BsGetBits(24);
if (origPtr > 10 + limitLast)
throw new InvalidOperationException();
int nSelectors = RecvDecodingTables();
int alphaSize = nInUse + 2;
int EOB = nInUse + 1;
/*
Setting up the unzftab entries here is not strictly
necessary, but it does save having to do it later
in a separate pass, and so saves a block's worth of
cache misses.
*/
Array.Clear(unzftab, 0, unzftab.Length);
byte[] yy = new byte[nInUse];
for (i = 0; i < nInUse; ++i)
{
yy[i] = seqToUnseq[i];
}
last = -1;
int groupNo = 0;
int groupPos = BZip2Constants.G_SIZE - 1;
int groupSel = m_selectors[groupNo];
int groupMinLen = minLens[groupSel];
int[] groupLimits = limit[groupSel];
int[] groupPerm = perm[groupSel];
int[] groupBase = basev[groupSel];
{
int zn = groupMinLen;
int zvec = BsGetBits(groupMinLen);
while (zvec >= groupLimits[zn])
{
if (++zn > BZip2Constants.MAX_CODE_LEN)
throw new InvalidOperationException();
zvec = (zvec << 1) | BsGetBit();
}
int permIndex = zvec - groupBase[zn];
if (permIndex >= alphaSize)
throw new InvalidOperationException();
nextSym = groupPerm[permIndex];
}
while (nextSym != EOB)
{
//if (nextSym == BZip2Constants.RUNA || nextSym == BZip2Constants.RUNB)
if (nextSym <= BZip2Constants.RUNB)
{
int n = 1, s = 0;
do
{
if (n > 1024 * 1024)
throw new InvalidOperationException();
s += n << nextSym;
n <<= 1;
{
if (groupPos == 0)
{
if (++groupNo >= nSelectors)
throw new InvalidOperationException();
groupPos = BZip2Constants.G_SIZE;
groupSel = m_selectors[groupNo];
groupMinLen = minLens[groupSel];
groupLimits = limit[groupSel];
groupPerm = perm[groupSel];
groupBase = basev[groupSel];
}
groupPos--;
int zn = groupMinLen;
int zvec = BsGetBits(groupMinLen);
while (zvec >= groupLimits[zn])
{
if (++zn > BZip2Constants.MAX_CODE_LEN)
throw new InvalidOperationException();
zvec = (zvec << 1) | BsGetBit();
}
int permIndex = zvec - groupBase[zn];
if (permIndex >= alphaSize)
throw new InvalidOperationException();
nextSym = groupPerm[permIndex];
}
}
//while (nextSym == BZip2Constants.RUNA || nextSym == BZip2Constants.RUNB);
while (nextSym <= BZip2Constants.RUNB);
byte ch = yy[0];
unzftab[ch] += s;
if (last >= limitLast - s)
throw new InvalidOperationException("Block overrun");
while (--s >= 0)
{
ll8[++last] = ch;
}
continue;
}
else
{
if (++last >= limitLast)
throw new InvalidOperationException("Block overrun");
byte tmp = yy[nextSym - 1];
unzftab[tmp]++;
ll8[last] = tmp;
/*
* This loop is hammered during decompression, hence avoid
* native method call overhead of Array.Copy for very
* small ranges to copy.
*/
if (nextSym <= 16)
{
for (j = nextSym - 1; j > 0; --j)
{
yy[j] = yy[j - 1];
}
}
else
{
Array.Copy(yy, 0, yy, 1, nextSym - 1);
}
yy[0] = tmp;
{
if (groupPos == 0)
{
if (++groupNo >= nSelectors)
throw new InvalidOperationException();
groupPos = BZip2Constants.G_SIZE;
groupSel = m_selectors[groupNo];
groupMinLen = minLens[groupSel];
groupLimits = limit[groupSel];
groupPerm = perm[groupSel];
groupBase = basev[groupSel];
}
groupPos--;
int zn = groupMinLen;
int zvec = BsGetBits(groupMinLen);
while (zvec >= groupLimits[zn])
{
if (++zn > BZip2Constants.MAX_CODE_LEN)
throw new InvalidOperationException();
zvec = (zvec << 1) | BsGetBit();
}
int permIndex = zvec - groupBase[zn];
if (permIndex >= alphaSize)
throw new InvalidOperationException();
nextSym = groupPerm[permIndex];
}
continue;
}
}
if (origPtr > last)
throw new InvalidOperationException();
// Check unzftab entries are in range.
{
int nblock = last + 1;
int check = 0;
for (i = 0; i <= 255; i++)
{
int t = unzftab[i];
check |= t;
check |= nblock - t;
}
if (check < 0)
throw new InvalidOperationException();
}
}
private int RequireByte()
{
int b = bsStream.ReadByte();
if (b < 0)
throw new EndOfStreamException();
return b & 0xFF;
}
private void SetupRandPartA()
{
if (i2 <= last)
{
chPrev = ch2;
ch2 = ll8[tPos];
tPos = tt[tPos];
if (rNToGo == 0)
{
rNToGo = CBZip2OutputStream.RNums[rTPos++];
rTPos &= 0x1FF;
}
rNToGo--;
ch2 ^= rNToGo == 1 ? 1 : 0;
i2++;
currentByte = ch2;
currentState = RAND_PART_B_STATE;
m_blockCrc.Update((byte)ch2);
}
else
{
EndBlock();
BeginBlock();
}
}
private void SetupNoRandPartA()
{
if (i2 <= last)
{
chPrev = ch2;
ch2 = ll8[tPos];
tPos = tt[tPos];
i2++;
currentByte = ch2;
currentState = NO_RAND_PART_B_STATE;
m_blockCrc.Update((byte)ch2);
}
else
{
EndBlock();
BeginBlock();
}
}
private void SetupRandPartB()
{
if (ch2 != chPrev)
{
count = 1;
SetupRandPartA();
}
else if (++count < 4)
{
SetupRandPartA();
}
else
{
z = ll8[tPos];
tPos = tt[tPos];
if (rNToGo == 0)
{
rNToGo = CBZip2OutputStream.RNums[rTPos++];
rTPos &= 0x1FF;
}
rNToGo--;
z ^= rNToGo == 1 ? 1 : 0;
j2 = 0;
currentState = RAND_PART_C_STATE;
SetupRandPartC();
}
}
private void SetupNoRandPartB()
{
if (ch2 != chPrev)
{
count = 1;
SetupNoRandPartA();
}
else if (++count < 4)
{
SetupNoRandPartA();
}
else
{
z = ll8[tPos];
tPos = tt[tPos];
currentState = NO_RAND_PART_C_STATE;
j2 = 0;
SetupNoRandPartC();
}
}
private void SetupRandPartC()
{
if (j2 < z)
{
currentByte = ch2;
m_blockCrc.Update((byte)ch2);
j2++;
}
else
{
i2++;
count = 0;
SetupRandPartA();
}
}
private void SetupNoRandPartC()
{
if (j2 < z)
{
currentByte = ch2;
m_blockCrc.Update((byte)ch2);
j2++;
}
else
{
i2++;
count = 0;
SetupNoRandPartA();
}
}
internal static int[][] CreateIntArray(int n1, int n2)
{
int[][] a = new int[n1][];
for (int k = 0; k < n1; ++k)
{
a[k] = new int[n2];
}
return a;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a4666f98f6a8d540ae1d0d2f61b9262
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf3dffeb38ff3b74983e5d723d21417c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,162 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* This package is based on the work done by Keiron Liddle), Aftex Software
* <keiron@aftexsw.com> to whom the Ant project is very grateful for his
* great code.
*/
using System.Diagnostics;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Bzip2
{
/**
* A simple class the hold and calculate the CRC for sanity checking
* of the data.
*
* @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
*/
internal class CRC
{
// Values are byte-reversed
private static readonly uint[] Crc32Table = {
0x00000000, 0xB71DC104, 0x6E3B8209, 0xD926430D,
0xDC760413, 0x6B6BC517, 0xB24D861A, 0x0550471E,
0xB8ED0826, 0x0FF0C922, 0xD6D68A2F, 0x61CB4B2B,
0x649B0C35, 0xD386CD31, 0x0AA08E3C, 0xBDBD4F38,
0x70DB114C, 0xC7C6D048, 0x1EE09345, 0xA9FD5241,
0xACAD155F, 0x1BB0D45B, 0xC2969756, 0x758B5652,
0xC836196A, 0x7F2BD86E, 0xA60D9B63, 0x11105A67,
0x14401D79, 0xA35DDC7D, 0x7A7B9F70, 0xCD665E74,
0xE0B62398, 0x57ABE29C, 0x8E8DA191, 0x39906095,
0x3CC0278B, 0x8BDDE68F, 0x52FBA582, 0xE5E66486,
0x585B2BBE, 0xEF46EABA, 0x3660A9B7, 0x817D68B3,
0x842D2FAD, 0x3330EEA9, 0xEA16ADA4, 0x5D0B6CA0,
0x906D32D4, 0x2770F3D0, 0xFE56B0DD, 0x494B71D9,
0x4C1B36C7, 0xFB06F7C3, 0x2220B4CE, 0x953D75CA,
0x28803AF2, 0x9F9DFBF6, 0x46BBB8FB, 0xF1A679FF,
0xF4F63EE1, 0x43EBFFE5, 0x9ACDBCE8, 0x2DD07DEC,
0x77708634, 0xC06D4730, 0x194B043D, 0xAE56C539,
0xAB068227, 0x1C1B4323, 0xC53D002E, 0x7220C12A,
0xCF9D8E12, 0x78804F16, 0xA1A60C1B, 0x16BBCD1F,
0x13EB8A01, 0xA4F64B05, 0x7DD00808, 0xCACDC90C,
0x07AB9778, 0xB0B6567C, 0x69901571, 0xDE8DD475,
0xDBDD936B, 0x6CC0526F, 0xB5E61162, 0x02FBD066,
0xBF469F5E, 0x085B5E5A, 0xD17D1D57, 0x6660DC53,
0x63309B4D, 0xD42D5A49, 0x0D0B1944, 0xBA16D840,
0x97C6A5AC, 0x20DB64A8, 0xF9FD27A5, 0x4EE0E6A1,
0x4BB0A1BF, 0xFCAD60BB, 0x258B23B6, 0x9296E2B2,
0x2F2BAD8A, 0x98366C8E, 0x41102F83, 0xF60DEE87,
0xF35DA999, 0x4440689D, 0x9D662B90, 0x2A7BEA94,
0xE71DB4E0, 0x500075E4, 0x892636E9, 0x3E3BF7ED,
0x3B6BB0F3, 0x8C7671F7, 0x555032FA, 0xE24DF3FE,
0x5FF0BCC6, 0xE8ED7DC2, 0x31CB3ECF, 0x86D6FFCB,
0x8386B8D5, 0x349B79D1, 0xEDBD3ADC, 0x5AA0FBD8,
0xEEE00C69, 0x59FDCD6D, 0x80DB8E60, 0x37C64F64,
0x3296087A, 0x858BC97E, 0x5CAD8A73, 0xEBB04B77,
0x560D044F, 0xE110C54B, 0x38368646, 0x8F2B4742,
0x8A7B005C, 0x3D66C158, 0xE4408255, 0x535D4351,
0x9E3B1D25, 0x2926DC21, 0xF0009F2C, 0x471D5E28,
0x424D1936, 0xF550D832, 0x2C769B3F, 0x9B6B5A3B,
0x26D61503, 0x91CBD407, 0x48ED970A, 0xFFF0560E,
0xFAA01110, 0x4DBDD014, 0x949B9319, 0x2386521D,
0x0E562FF1, 0xB94BEEF5, 0x606DADF8, 0xD7706CFC,
0xD2202BE2, 0x653DEAE6, 0xBC1BA9EB, 0x0B0668EF,
0xB6BB27D7, 0x01A6E6D3, 0xD880A5DE, 0x6F9D64DA,
0x6ACD23C4, 0xDDD0E2C0, 0x04F6A1CD, 0xB3EB60C9,
0x7E8D3EBD, 0xC990FFB9, 0x10B6BCB4, 0xA7AB7DB0,
0xA2FB3AAE, 0x15E6FBAA, 0xCCC0B8A7, 0x7BDD79A3,
0xC660369B, 0x717DF79F, 0xA85BB492, 0x1F467596,
0x1A163288, 0xAD0BF38C, 0x742DB081, 0xC3307185,
0x99908A5D, 0x2E8D4B59, 0xF7AB0854, 0x40B6C950,
0x45E68E4E, 0xF2FB4F4A, 0x2BDD0C47, 0x9CC0CD43,
0x217D827B, 0x9660437F, 0x4F460072, 0xF85BC176,
0xFD0B8668, 0x4A16476C, 0x93300461, 0x242DC565,
0xE94B9B11, 0x5E565A15, 0x87701918, 0x306DD81C,
0x353D9F02, 0x82205E06, 0x5B061D0B, 0xEC1BDC0F,
0x51A69337, 0xE6BB5233, 0x3F9D113E, 0x8880D03A,
0x8DD09724, 0x3ACD5620, 0xE3EB152D, 0x54F6D429,
0x7926A9C5, 0xCE3B68C1, 0x171D2BCC, 0xA000EAC8,
0xA550ADD6, 0x124D6CD2, 0xCB6B2FDF, 0x7C76EEDB,
0xC1CBA1E3, 0x76D660E7, 0xAFF023EA, 0x18EDE2EE,
0x1DBDA5F0, 0xAAA064F4, 0x738627F9, 0xC49BE6FD,
0x09FDB889, 0xBEE0798D, 0x67C63A80, 0xD0DBFB84,
0xD58BBC9A, 0x62967D9E, 0xBBB03E93, 0x0CADFF97,
0xB110B0AF, 0x060D71AB, 0xDF2B32A6, 0x6836F3A2,
0x6D66B4BC, 0xDA7B75B8, 0x035D36B5, 0xB440F7B1,
};
private uint m_value = 0U;
internal void Initialise()
{
m_value = 0xFFFFFFFF;
}
internal int GetFinal()
{
return (int)~Integers.ReverseBytes(m_value);
}
internal void Update(byte inCh)
{
m_value = (m_value >> 8) ^ Crc32Table[(byte)(m_value ^ inCh)];
}
internal void UpdateRun(byte inCh, int runLength)
{
Debug.Assert(runLength >= 4);
uint inCh2 = (uint)inCh << 8 | inCh;
uint inCh4 = inCh2 << 16 | inCh2;
do
{
m_value ^= inCh4;
m_value = (m_value >> 8) ^ Crc32Table[(byte)m_value];
m_value = (m_value >> 8) ^ Crc32Table[(byte)m_value];
m_value = (m_value >> 8) ^ Crc32Table[(byte)m_value];
m_value = (m_value >> 8) ^ Crc32Table[(byte)m_value];
}
while ((runLength -= 4) >= 4);
switch (runLength & 3)
{
case 0:
break;
case 1:
Update(inCh);
break;
case 2:
Update(inCh);
Update(inCh);
break;
case 3:
Update(inCh);
Update(inCh);
Update(inCh);
break;
}
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ef54f297138cd845a76621ec767e6a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0b0797c2616cd4f4bbc6332490d85557
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,108 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
using System.Text;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
public abstract class CollectionUtilities
{
public static void CollectMatches<T>(ICollection<T> matches, ISelector<T> selector,
IEnumerable<IStore<T>> stores)
{
if (matches == null)
throw new ArgumentNullException(nameof(matches));
if (stores == null)
return;
foreach (var store in stores)
{
if (store == null)
continue;
foreach (T match in store.EnumerateMatches(selector))
{
matches.Add(match);
}
}
}
public static IStore<T> CreateStore<T>(IEnumerable<T> contents)
{
return new StoreImpl<T>(contents);
}
public static T GetValueOrKey<T>(IDictionary<T, T> d, T k)
{
return d.TryGetValue(k, out var v) ? v : k;
}
public static V GetValueOrNull<K, V>(IDictionary<K, V> d, K k)
where V : class
{
return d.TryGetValue(k, out var v) ? v : null;
}
public static IEnumerable<T> Proxy<T>(IEnumerable<T> e)
{
return new EnumerableProxy<T>(e);
}
public static ICollection<T> ReadOnly<T>(ICollection<T> c)
{
return new ReadOnlyCollectionProxy<T>(c);
}
public static IDictionary<K, V> ReadOnly<K, V>(IDictionary<K, V> d)
{
return new ReadOnlyDictionaryProxy<K, V>(d);
}
public static IList<T> ReadOnly<T>(IList<T> l)
{
return new ReadOnlyListProxy<T>(l);
}
public static ISet<T> ReadOnly<T>(ISet<T> s)
{
return new ReadOnlySetProxy<T>(s);
}
public static bool Remove<K, V>(IDictionary<K, V> d, K k, out V v)
{
if (!d.TryGetValue(k, out v))
return false;
d.Remove(k);
return true;
}
public static T RequireNext<T>(IEnumerator<T> e)
{
if (!e.MoveNext())
throw new InvalidOperationException();
return e.Current;
}
public static string ToString<T>(IEnumerable<T> c)
{
IEnumerator<T> e = c.GetEnumerator();
if (!e.MoveNext())
return "[]";
StringBuilder sb = new StringBuilder("[");
sb.Append(e.Current);
while (e.MoveNext())
{
sb.Append(", ");
sb.Append(e.Current);
}
sb.Append(']');
return sb.ToString();
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d30cc7795a67b547845658234e4bed0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
internal sealed class EnumerableProxy<T>
: IEnumerable<T>
{
private readonly IEnumerable<T> m_target;
internal EnumerableProxy(IEnumerable<T> target)
{
if (target == null)
throw new ArgumentNullException(nameof(target));
m_target = target;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return m_target.GetEnumerator();
}
public IEnumerator<T> GetEnumerator()
{
return m_target.GetEnumerator();
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7473b1e62cdb7be449f354cbedddd3b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be205234b98d61744b11c4318e87ac85
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
/// <summary>Interface for matching objects in an <see cref="IStore{T}"/>.</summary>
/// <typeparam name="T">The contravariant type of selectable objects.</typeparam>
public interface ISelector<in T>
: ICloneable
{
/// <summary>Match the passed in object, returning true if it would be selected by this selector, false
/// otherwise.</summary>
/// <param name="candidate">The object to be matched.</param>
/// <returns><code>true</code> if the objects is matched by this selector, false otherwise.</returns>
bool Match(T candidate);
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ac9912de47b494548bad468a96736ce4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
/// <summary>A generic interface describing a simple store of objects.</summary>
/// <typeparam name="T">The covariant type of stored objects.</typeparam>
public interface IStore<out T>
{
/// <summary>Enumerate the (possibly empty) collection of objects matched by the given selector.</summary>
/// <param name="selector">The <see cref="ISelector{T}"/> used to select matching objects.</param>
/// <returns>An <see cref="IEnumerable{T}"/> of the matching objects.</returns>
IEnumerable<T> EnumerateMatches(ISelector<T> selector);
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d42fa3793a9494946985bb14484c7dcf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5f1de8474468a840953808b84fc6f96
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
internal abstract class ReadOnlyCollection<T>
: ICollection<T>
{
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool IsReadOnly => true;
public void Add(T item) => throw new NotSupportedException();
public void Clear() => throw new NotSupportedException();
public bool Remove(T item) => throw new NotSupportedException();
public abstract bool Contains(T item);
public abstract int Count { get; }
public abstract void CopyTo(T[] array, int arrayIndex);
public abstract IEnumerator<T> GetEnumerator();
}
internal class ReadOnlyCollectionProxy<T>
: ReadOnlyCollection<T>
{
private readonly ICollection<T> m_target;
internal ReadOnlyCollectionProxy(ICollection<T> target)
{
if (target == null)
throw new ArgumentNullException(nameof(target));
m_target = target;
}
public override bool Contains(T item) => m_target.Contains(item);
public override int Count => m_target.Count;
public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
public override IEnumerator<T> GetEnumerator() => m_target.GetEnumerator();
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a48902e1e6ee3a0448224787f2a690c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
internal abstract class ReadOnlyDictionary<K, V>
: IDictionary<K, V>
{
public V this[K key]
{
get { return Lookup(key); }
set { throw new NotSupportedException(); }
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool IsReadOnly => true;
public void Add(K key, V value) => throw new NotSupportedException();
public void Add(KeyValuePair<K, V> item) => throw new NotSupportedException();
public void Clear() => throw new NotSupportedException();
public bool Remove(K key) => throw new NotSupportedException();
public bool Remove(KeyValuePair<K, V> item) => throw new NotSupportedException();
public abstract bool Contains(KeyValuePair<K, V> item);
public abstract bool ContainsKey(K key);
public abstract void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex);
public abstract int Count { get; }
public abstract IEnumerator<KeyValuePair<K, V>> GetEnumerator();
public abstract ICollection<K> Keys { get; }
public abstract bool TryGetValue(K key, out V value);
public abstract ICollection<V> Values { get; }
protected abstract V Lookup(K key);
}
internal class ReadOnlyDictionaryProxy<K, V>
: ReadOnlyDictionary<K, V>
{
private readonly IDictionary<K, V> m_target;
internal ReadOnlyDictionaryProxy(IDictionary<K, V> target)
{
if (target == null)
throw new ArgumentNullException(nameof(target));
m_target = target;
}
public override bool Contains(KeyValuePair<K, V> item) => m_target.Contains(item);
public override bool ContainsKey(K key) => m_target.ContainsKey(key);
public override void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
public override int Count => m_target.Count;
public override IEnumerator<KeyValuePair<K, V>> GetEnumerator() => m_target.GetEnumerator();
public override ICollection<K> Keys => new ReadOnlyCollectionProxy<K>(m_target.Keys);
public override bool TryGetValue(K key, out V value) => m_target.TryGetValue(key, out value);
public override ICollection<V> Values => new ReadOnlyCollectionProxy<V>(m_target.Values);
protected override V Lookup(K key) => m_target[key];
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a4f69721ea2e274f8e93b1fdaf45141
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,63 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
internal abstract class ReadOnlyList<T>
: IList<T>
{
public T this[int index]
{
get { return Lookup(index); }
set { throw new NotSupportedException(); }
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool IsReadOnly => true;
public void Add(T item) => throw new NotSupportedException();
public void Clear() => throw new NotSupportedException();
public void Insert(int index, T item) => throw new NotSupportedException();
public bool Remove(T item) => throw new NotSupportedException();
public void RemoveAt(int index) => throw new NotSupportedException();
public abstract bool Contains(T item);
public abstract void CopyTo(T[] array, int arrayIndex);
public abstract int Count { get; }
public abstract IEnumerator<T> GetEnumerator();
public abstract int IndexOf(T item);
protected abstract T Lookup(int index);
}
internal class ReadOnlyListProxy<T>
: ReadOnlyList<T>
{
private readonly IList<T> m_target;
internal ReadOnlyListProxy(IList<T> target)
{
if (target == null)
throw new ArgumentNullException(nameof(target));
m_target = target;
}
public override int Count => m_target.Count;
public override bool Contains(T item) => m_target.Contains(item);
public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
public override IEnumerator<T> GetEnumerator() => m_target.GetEnumerator();
public override int IndexOf(T item) => m_target.IndexOf(item);
protected override T Lookup(int index) => m_target[index];
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7fb52e360eebb940b519bf3dab83424
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
internal abstract class ReadOnlySet<T>
: ISet<T>
{
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool IsReadOnly => true;
void ICollection<T>.Add(T item) => throw new NotSupportedException();
public bool Add(T item) => throw new NotSupportedException();
public void Clear() => throw new NotSupportedException();
public void ExceptWith(IEnumerable<T> other) => throw new NotSupportedException();
public void IntersectWith(IEnumerable<T> other) => throw new NotSupportedException();
public bool Remove(T item) => throw new NotSupportedException();
public bool SetEquals(IEnumerable<T> other) => throw new NotSupportedException();
public void SymmetricExceptWith(IEnumerable<T> other) => throw new NotSupportedException();
public void UnionWith(IEnumerable<T> other) => throw new NotSupportedException();
public abstract bool Contains(T item);
public abstract void CopyTo(T[] array, int arrayIndex);
public abstract int Count { get; }
public abstract IEnumerator<T> GetEnumerator();
public abstract bool IsProperSubsetOf(IEnumerable<T> other);
public abstract bool IsProperSupersetOf(IEnumerable<T> other);
public abstract bool IsSubsetOf(IEnumerable<T> other);
public abstract bool IsSupersetOf(IEnumerable<T> other);
public abstract bool Overlaps(IEnumerable<T> other);
}
internal class ReadOnlySetProxy<T>
: ReadOnlySet<T>
{
private readonly ISet<T> m_target;
internal ReadOnlySetProxy(ISet<T> target)
{
if (target == null)
throw new ArgumentNullException(nameof(target));
m_target = target;
}
public override bool Contains(T item) => m_target.Contains(item);
public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
public override int Count => m_target.Count;
public override IEnumerator<T> GetEnumerator() => m_target.GetEnumerator();
public override bool IsProperSubsetOf(IEnumerable<T> other) => m_target.IsProperSubsetOf(other);
public override bool IsProperSupersetOf(IEnumerable<T> other) => m_target.IsProperSupersetOf(other);
public override bool IsSubsetOf(IEnumerable<T> other) => m_target.IsSubsetOf(other);
public override bool IsSupersetOf(IEnumerable<T> other) => m_target.IsSupersetOf(other);
public override bool Overlaps(IEnumerable<T> other) => m_target.Overlaps(other);
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 24bbf770e59530f4cb957c11b0b50001
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
{
internal sealed class StoreImpl<T>
: IStore<T>
{
private readonly List<T> m_contents;
internal StoreImpl(IEnumerable<T> e)
{
m_contents = new List<T>(e);
}
IEnumerable<T> IStore<T>.EnumerateMatches(ISelector<T> selector)
{
foreach (T candidate in m_contents)
{
if (selector == null || selector.Match(candidate))
yield return candidate;
}
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 72bf42ed5d4da8a47915e3c158f0305b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 519a28f7f784fe741926e76c222b9da5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,87 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date
{
public static class DateTimeUtilities
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public static readonly DateTime UnixEpoch = DateTime.UnixEpoch;
#else
public static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
#endif
public static readonly long MaxUnixMs =
(DateTime.MaxValue.Ticks - UnixEpoch.Ticks) / TimeSpan.TicksPerMillisecond;
public static readonly long MinUnixMs = 0L;
/// <summary>
/// Return the number of milliseconds since the Unix epoch (1 Jan., 1970 UTC) for a given DateTime value.
/// </summary>
/// <remarks>The DateTime value will be converted to UTC (using <see cref="DateTime.ToUniversalTime"/> before
/// conversion.</remarks>
/// <param name="dateTime">A DateTime value not before the epoch.</param>
/// <returns>Number of whole milliseconds after epoch.</returns>
/// <exception cref="ArgumentOutOfRangeException">'dateTime' is before the epoch.</exception>
public static long DateTimeToUnixMs(DateTime dateTime)
{
DateTime utc = dateTime.ToUniversalTime();
if (utc.CompareTo(UnixEpoch) < 0)
throw new ArgumentOutOfRangeException(nameof(dateTime), "DateTime value may not be before the epoch");
return (utc.Ticks - UnixEpoch.Ticks) / TimeSpan.TicksPerMillisecond;
}
/// <summary>
/// Create a UTC DateTime value from the number of milliseconds since the Unix epoch (1 Jan., 1970 UTC).
/// </summary>
/// <param name="unixMs">Number of milliseconds since the epoch.</param>
/// <returns>A UTC DateTime value</returns>
/// <exception cref="ArgumentOutOfRangeException">'unixMs' is before 'MinUnixMs' or after 'MaxUnixMs'.
/// </exception>
public static DateTime UnixMsToDateTime(long unixMs)
{
if (unixMs < MinUnixMs || unixMs > MaxUnixMs)
throw new ArgumentOutOfRangeException(nameof(unixMs));
return new DateTime(unixMs * TimeSpan.TicksPerMillisecond + UnixEpoch.Ticks, DateTimeKind.Utc);
}
/// <summary>
/// Return the current number of milliseconds since the Unix epoch (1 Jan., 1970 UTC).
/// </summary>
public static long CurrentUnixMs()
{
return DateTimeToUnixMs(DateTime.UtcNow);
}
public static DateTime WithPrecisionCentisecond(DateTime dateTime)
{
int millisecond = dateTime.Millisecond - (dateTime.Millisecond % 10);
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
dateTime.Hour, dateTime.Minute, dateTime.Second, millisecond, dateTime.Kind);
}
public static DateTime WithPrecisionDecisecond(DateTime dateTime)
{
int millisecond = dateTime.Millisecond - (dateTime.Millisecond % 100);
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
dateTime.Hour, dateTime.Minute, dateTime.Second, millisecond, dateTime.Kind);
}
public static DateTime WithPrecisionMillisecond(DateTime dateTime)
{
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond, dateTime.Kind);
}
public static DateTime WithPrecisionSecond(DateTime dateTime)
{
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Kind);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 85931186ecac6fa43a89af5ddc60b835
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a1c695eec32cfe44ba8bb5c6b6230161
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,124 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using System.Text;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
public sealed class Base64
{
private Base64()
{
}
public static string ToBase64String(
byte[] data)
{
return Convert.ToBase64String(data, 0, data.Length);
}
public static string ToBase64String(
byte[] data,
int off,
int length)
{
return Convert.ToBase64String(data, off, length);
}
/**
* encode the input data producing a base 64 encoded byte array.
*
* @return a byte array containing the base 64 encoded data.
*/
public static byte[] Encode(
byte[] data)
{
return Encode(data, 0, data.Length);
}
/**
* encode the input data producing a base 64 encoded byte array.
*
* @return a byte array containing the base 64 encoded data.
*/
public static byte[] Encode(
byte[] data,
int off,
int length)
{
string s = Convert.ToBase64String(data, off, length);
return Strings.ToAsciiByteArray(s);
}
/**
* Encode the byte data to base 64 writing it to the given output stream.
*
* @return the number of bytes produced.
*/
public static int Encode(
byte[] data,
Stream outStream)
{
byte[] encoded = Encode(data);
outStream.Write(encoded, 0, encoded.Length);
return encoded.Length;
}
/**
* Encode the byte data to base 64 writing it to the given output stream.
*
* @return the number of bytes produced.
*/
public static int Encode(
byte[] data,
int off,
int length,
Stream outStream)
{
byte[] encoded = Encode(data, off, length);
outStream.Write(encoded, 0, encoded.Length);
return encoded.Length;
}
/**
* decode the base 64 encoded input data. It is assumed the input data is valid.
*
* @return a byte array representing the decoded data.
*/
public static byte[] Decode(
byte[] data)
{
string s = Strings.FromAsciiByteArray(data);
return Convert.FromBase64String(s);
}
/**
* decode the base 64 encoded string data - whitespace will be ignored.
*
* @return a byte array representing the decoded data.
*/
public static byte[] Decode(
string data)
{
return Convert.FromBase64String(data);
}
/**
* decode the base 64 encoded string data writing it to the given output stream,
* whitespace characters will be ignored.
*
* @return the number of bytes produced.
*/
public static int Decode(
string data,
Stream outStream)
{
byte[] decoded = Decode(data);
outStream.Write(decoded, 0, decoded.Length);
return decoded.Length;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2d6f9d60f7dc61d48babd61d65e4a234
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,511 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
public class Base64Encoder
: IEncoder
{
protected readonly byte[] encodingTable =
{
(byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G',
(byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N',
(byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U',
(byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z',
(byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g',
(byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n',
(byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u',
(byte)'v',
(byte)'w', (byte)'x', (byte)'y', (byte)'z',
(byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6',
(byte)'7', (byte)'8', (byte)'9',
(byte)'+', (byte)'/'
};
protected byte padding = (byte)'=';
/*
* set up the decoding table.
*/
protected readonly byte[] decodingTable = new byte[128];
protected void InitialiseDecodingTable()
{
Arrays.Fill(decodingTable, (byte)0xff);
for (int i = 0; i < encodingTable.Length; i++)
{
decodingTable[encodingTable[i]] = (byte)i;
}
}
public Base64Encoder()
{
InitialiseDecodingTable();
}
public int Encode(byte[] inBuf, int inOff, int inLen, byte[] outBuf, int outOff)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return Encode(inBuf.AsSpan(inOff, inLen), outBuf.AsSpan(outOff));
#else
int inPos = inOff;
int inEnd = inOff + inLen - 2;
int outPos = outOff;
while (inPos < inEnd)
{
uint a1 = inBuf[inPos++];
uint a2 = inBuf[inPos++];
uint a3 = inBuf[inPos++];
outBuf[outPos++] = encodingTable[(a1 >> 2) & 0x3F];
outBuf[outPos++] = encodingTable[((a1 << 4) | (a2 >> 4)) & 0x3F];
outBuf[outPos++] = encodingTable[((a2 << 2) | (a3 >> 6)) & 0x3F];
outBuf[outPos++] = encodingTable[a3 & 0x3F];
}
switch (inLen - (inPos - inOff))
{
case 1:
{
uint a1 = inBuf[inPos++];
outBuf[outPos++] = encodingTable[(a1 >> 2) & 0x3F];
outBuf[outPos++] = encodingTable[(a1 << 4) & 0x3F];
outBuf[outPos++] = padding;
outBuf[outPos++] = padding;
break;
}
case 2:
{
uint a1 = inBuf[inPos++];
uint a2 = inBuf[inPos++];
outBuf[outPos++] = encodingTable[(a1 >> 2) & 0x3F];
outBuf[outPos++] = encodingTable[((a1 << 4) | (a2 >> 4)) & 0x3F];
outBuf[outPos++] = encodingTable[(a2 << 2) & 0x3F];
outBuf[outPos++] = padding;
break;
}
}
return outPos - outOff;
#endif
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public int Encode(ReadOnlySpan<byte> input, Span<byte> output)
{
int inPos = 0;
int inEnd = input.Length - 2;
int outPos = 0;
while (inPos < inEnd)
{
uint a1 = input[inPos++];
uint a2 = input[inPos++];
uint a3 = input[inPos++];
output[outPos++] = encodingTable[(a1 >> 2) & 0x3F];
output[outPos++] = encodingTable[((a1 << 4) | (a2 >> 4)) & 0x3F];
output[outPos++] = encodingTable[((a2 << 2) | (a3 >> 6)) & 0x3F];
output[outPos++] = encodingTable[a3 & 0x3F];
}
switch (input.Length - inPos)
{
case 1:
{
uint a1 = input[inPos++];
output[outPos++] = encodingTable[(a1 >> 2) & 0x3F];
output[outPos++] = encodingTable[(a1 << 4) & 0x3F];
output[outPos++] = padding;
output[outPos++] = padding;
break;
}
case 2:
{
uint a1 = input[inPos++];
uint a2 = input[inPos++];
output[outPos++] = encodingTable[(a1 >> 2) & 0x3F];
output[outPos++] = encodingTable[((a1 << 4) | (a2 >> 4)) & 0x3F];
output[outPos++] = encodingTable[(a2 << 2) & 0x3F];
output[outPos++] = padding;
break;
}
}
return outPos;
}
#endif
/**
* encode the input data producing a base 64 output stream.
*
* @return the number of bytes produced.
*/
public int Encode(byte[] buf, int off, int len, Stream outStream)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return Encode(buf.AsSpan(off, len), outStream);
#else
if (len < 0)
return 0;
byte[] tmp = new byte[72];
int remaining = len;
while (remaining > 0)
{
int inLen = System.Math.Min(54, remaining);
int outLen = Encode(buf, off, inLen, tmp, 0);
outStream.Write(tmp, 0, outLen);
off += inLen;
remaining -= inLen;
}
return (len + 2) / 3 * 4;
#endif
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public int Encode(ReadOnlySpan<byte> data, Stream outStream)
{
Span<byte> tmp = stackalloc byte[72];
int result = (data.Length + 2) / 3 * 4;
while (!data.IsEmpty)
{
int inLen = System.Math.Min(54, data.Length);
int outLen = Encode(data[..inLen], tmp);
outStream.Write(tmp[..outLen]);
data = data[inLen..];
}
return result;
}
#endif
private bool Ignore(char c)
{
return c == '\n' || c =='\r' || c == '\t' || c == ' ';
}
/**
* decode the base 64 encoded byte data writing it to the given output stream,
* whitespace characters will be ignored.
*
* @return the number of bytes produced.
*/
public int Decode(byte[] data, int off, int length, Stream outStream)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return Decode(data.AsSpan(off, length), outStream);
#else
byte b1, b2, b3, b4;
byte[] outBuffer = new byte[54]; // S/MIME standard
int bufOff = 0;
int outLen = 0;
int end = off + length;
while (end > off)
{
if (!Ignore((char)data[end - 1]))
break;
end--;
}
int finish = end - 4;
int i = NextI(data, off, finish);
while (i < finish)
{
b1 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b2 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b3 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b4 = decodingTable[data[i++]];
if ((b1 | b2 | b3 | b4) >= 0x80)
throw new IOException("invalid characters encountered in base64 data");
outBuffer[bufOff++] = (byte)((b1 << 2) | (b2 >> 4));
outBuffer[bufOff++] = (byte)((b2 << 4) | (b3 >> 2));
outBuffer[bufOff++] = (byte)((b3 << 6) | b4);
if (bufOff == outBuffer.Length)
{
outStream.Write(outBuffer, 0, bufOff);
bufOff = 0;
}
outLen += 3;
i = NextI(data, i, finish);
}
if (bufOff > 0)
{
outStream.Write(outBuffer, 0, bufOff);
}
int e0 = NextI(data, i, end);
int e1 = NextI(data, e0 + 1, end);
int e2 = NextI(data, e1 + 1, end);
int e3 = NextI(data, e2 + 1, end);
outLen += DecodeLastBlock(outStream, (char)data[e0], (char)data[e1], (char)data[e2], (char)data[e3]);
return outLen;
#endif
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public int Decode(ReadOnlySpan<byte> data, Stream outStream)
{
byte b1, b2, b3, b4;
Span<byte> outBuffer = stackalloc byte[54]; // S/MIME standard
int bufOff = 0;
int outLen = 0;
int end = data.Length;
while (end > 0)
{
if (!Ignore((char)data[end - 1]))
break;
end--;
}
int finish = end - 4;
int i = NextI(data, 0, finish);
while (i < finish)
{
b1 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b2 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b3 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b4 = decodingTable[data[i++]];
if ((b1 | b2 | b3 | b4) >= 0x80)
throw new IOException("invalid characters encountered in base64 data");
outBuffer[bufOff++] = (byte)((b1 << 2) | (b2 >> 4));
outBuffer[bufOff++] = (byte)((b2 << 4) | (b3 >> 2));
outBuffer[bufOff++] = (byte)((b3 << 6) | b4);
if (bufOff == outBuffer.Length)
{
outStream.Write(outBuffer);
bufOff = 0;
}
outLen += 3;
i = NextI(data, i, finish);
}
if (bufOff > 0)
{
outStream.Write(outBuffer[..bufOff]);
}
int e0 = NextI(data, i, end);
int e1 = NextI(data, e0 + 1, end);
int e2 = NextI(data, e1 + 1, end);
int e3 = NextI(data, e2 + 1, end);
outLen += DecodeLastBlock(outStream, (char)data[e0], (char)data[e1], (char)data[e2], (char)data[e3]);
return outLen;
}
#endif
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
private int NextI(ReadOnlySpan<byte> data, int i, int finish)
#else
private int NextI(byte[] data, int i, int finish)
#endif
{
while ((i < finish) && Ignore((char)data[i]))
{
i++;
}
return i;
}
/**
* decode the base 64 encoded string data writing it to the given output stream,
* whitespace characters will be ignored.
*
* @return the number of bytes produced.
*/
public int DecodeString(string data, Stream outStream)
{
// Platform Implementation
// byte[] bytes = Convert.FromBase64String(data);
// outStream.Write(bytes, 0, bytes.Length);
// return bytes.Length;
byte b1, b2, b3, b4;
int length = 0;
int end = data.Length;
while (end > 0)
{
if (!Ignore(data[end - 1]))
break;
end--;
}
int finish = end - 4;
int i = NextI(data, 0, finish);
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
Span<byte> buf = stackalloc byte[3];
#endif
while (i < finish)
{
b1 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b2 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b3 = decodingTable[data[i++]];
i = NextI(data, i, finish);
b4 = decodingTable[data[i++]];
if ((b1 | b2 | b3 | b4) >= 0x80)
throw new IOException("invalid characters encountered in base64 data");
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
buf[0] = (byte)((b1 << 2) | (b2 >> 4));
buf[1] = (byte)((b2 << 4) | (b3 >> 2));
buf[2] = (byte)((b3 << 6) | b4);
outStream.Write(buf);
#else
outStream.WriteByte((byte)((b1 << 2) | (b2 >> 4)));
outStream.WriteByte((byte)((b2 << 4) | (b3 >> 2)));
outStream.WriteByte((byte)((b3 << 6) | b4));
#endif
length += 3;
i = NextI(data, i, finish);
}
length += DecodeLastBlock(outStream, data[end - 4], data[end - 3], data[end - 2], data[end - 1]);
return length;
}
private int DecodeLastBlock(
Stream outStream,
char c1,
char c2,
char c3,
char c4)
{
if (c3 == padding)
{
if (c4 != padding)
throw new IOException("invalid characters encountered at end of base64 data");
byte b1 = decodingTable[c1];
byte b2 = decodingTable[c2];
if ((b1 | b2) >= 0x80)
throw new IOException("invalid characters encountered at end of base64 data");
outStream.WriteByte((byte)((b1 << 2) | (b2 >> 4)));
return 1;
}
if (c4 == padding)
{
byte b1 = decodingTable[c1];
byte b2 = decodingTable[c2];
byte b3 = decodingTable[c3];
if ((b1 | b2 | b3) >= 0x80)
throw new IOException("invalid characters encountered at end of base64 data");
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
Span<byte> buf = stackalloc byte[2] {
(byte)((b1 << 2) | (b2 >> 4)),
(byte)((b2 << 4) | (b3 >> 2)),
};
outStream.Write(buf);
#else
outStream.WriteByte((byte)((b1 << 2) | (b2 >> 4)));
outStream.WriteByte((byte)((b2 << 4) | (b3 >> 2)));
#endif
return 2;
}
{
byte b1 = decodingTable[c1];
byte b2 = decodingTable[c2];
byte b3 = decodingTable[c3];
byte b4 = decodingTable[c4];
if ((b1 | b2 | b3 | b4) >= 0x80)
throw new IOException("invalid characters encountered at end of base64 data");
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
Span<byte> buf = stackalloc byte[3] {
(byte)((b1 << 2) | (b2 >> 4)),
(byte)((b2 << 4) | (b3 >> 2)),
(byte)((b3 << 6) | b4),
};
outStream.Write(buf);
#else
outStream.WriteByte((byte)((b1 << 2) | (b2 >> 4)));
outStream.WriteByte((byte)((b2 << 4) | (b3 >> 2)));
outStream.WriteByte((byte)((b3 << 6) | b4));
#endif
return 3;
}
}
private int NextI(string data, int i, int finish)
{
while ((i < finish) && Ignore(data[i]))
{
i++;
}
return i;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f905b3d88fa2c734fb7553270ac7e0b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,121 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
/// <summary>
/// A buffering class to allow translation from one format to another to
/// be done in discrete chunks.
/// </summary>
public class BufferedDecoder
{
internal byte[] buffer;
internal int bufOff;
internal ITranslator translator;
/// <summary>
/// Create a buffered Decoder.
/// </summary>
/// <param name="translator">The translater to use.</param>
/// <param name="bufferSize">The size of the buffer.</param>
public BufferedDecoder(
ITranslator translator,
int bufferSize)
{
this.translator = translator;
if ((bufferSize % translator.GetEncodedBlockSize()) != 0)
{
throw new ArgumentException("buffer size not multiple of input block size");
}
buffer = new byte[bufferSize];
// bufOff = 0;
}
/// <summary>
/// Process one byte of data.
/// </summary>
/// <param name="input">Data in.</param>
/// <param name="output">Byte array for the output.</param>
/// <param name="outOff">The offset in the output byte array to start writing from.</param>
/// <returns>The amount of output bytes.</returns>
public int ProcessByte(
byte input,
byte[] output,
int outOff)
{
int resultLen = 0;
buffer[bufOff++] = input;
if (bufOff == buffer.Length)
{
resultLen = translator.Decode(buffer, 0, buffer.Length, output, outOff);
bufOff = 0;
}
return resultLen;
}
/// <summary>
/// Process data from a byte array.
/// </summary>
/// <param name="input">The input data.</param>
/// <param name="inOff">Start position within input data array.</param>
/// <param name="len">Amount of data to process from input data array.</param>
/// <param name="outBytes">Array to store output.</param>
/// <param name="outOff">Position in output array to start writing from.</param>
/// <returns>The amount of output bytes.</returns>
public int ProcessBytes(
byte[] input,
int inOff,
int len,
byte[] outBytes,
int outOff)
{
if (len < 0)
{
throw new ArgumentException("Can't have a negative input length!");
}
int resultLen = 0;
int gapLen = buffer.Length - bufOff;
if (len > gapLen)
{
Array.Copy(input, inOff, buffer, bufOff, gapLen);
resultLen += translator.Decode(buffer, 0, buffer.Length, outBytes, outOff);
bufOff = 0;
len -= gapLen;
inOff += gapLen;
outOff += resultLen;
int chunkSize = len - (len % buffer.Length);
resultLen += translator.Decode(input, inOff, chunkSize, outBytes, outOff);
len -= chunkSize;
inOff += chunkSize;
}
if (len != 0)
{
Array.Copy(input, inOff, buffer, bufOff, len);
bufOff += len;
}
return resultLen;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f6c49427e416a0845b216c1bc698f79c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,121 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
/// <summary>
/// A class that allows encoding of data using a specific encoder to be processed in chunks.
/// </summary>
public class BufferedEncoder
{
internal byte[] Buffer;
internal int bufOff;
internal ITranslator translator;
/// <summary>
/// Create.
/// </summary>
/// <param name="translator">The translator to use.</param>
/// <param name="bufferSize">Size of the chunks.</param>
public BufferedEncoder(
ITranslator translator,
int bufferSize)
{
this.translator = translator;
if ((bufferSize % translator.GetEncodedBlockSize()) != 0)
{
throw new ArgumentException("buffer size not multiple of input block size");
}
Buffer = new byte[bufferSize];
// bufOff = 0;
}
/// <summary>
/// Process one byte of data.
/// </summary>
/// <param name="input">The byte.</param>
/// <param name="outBytes">An array to store output in.</param>
/// <param name="outOff">Offset within output array to start writing from.</param>
/// <returns></returns>
public int ProcessByte(
byte input,
byte[] outBytes,
int outOff)
{
int resultLen = 0;
Buffer[bufOff++] = input;
if (bufOff == Buffer.Length)
{
resultLen = translator.Encode(Buffer, 0, Buffer.Length, outBytes, outOff);
bufOff = 0;
}
return resultLen;
}
/// <summary>
/// Process data from a byte array.
/// </summary>
/// <param name="input">Input data Byte array containing data to be processed.</param>
/// <param name="inOff">Start position within input data array.</param>
/// <param name="len">Amount of input data to be processed.</param>
/// <param name="outBytes">Output data array.</param>
/// <param name="outOff">Offset within output data array to start writing to.</param>
/// <returns>The amount of data written.</returns>
public int ProcessBytes(
byte[] input,
int inOff,
int len,
byte[] outBytes,
int outOff)
{
if (len < 0)
{
throw new ArgumentException("Can't have a negative input length!");
}
int resultLen = 0;
int gapLen = Buffer.Length - bufOff;
if (len > gapLen)
{
Array.Copy(input, inOff, Buffer, bufOff, gapLen);
resultLen += translator.Encode(Buffer, 0, Buffer.Length, outBytes, outOff);
bufOff = 0;
len -= gapLen;
inOff += gapLen;
outOff += resultLen;
int chunkSize = len - (len % Buffer.Length);
resultLen += translator.Encode(input, inOff, chunkSize, outBytes, outOff);
len -= chunkSize;
inOff += chunkSize;
}
if (len != 0)
{
Array.Copy(input, inOff, Buffer, bufOff, len);
bufOff += len;
}
return resultLen;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 53ece357fad218446b6823b06ffea94d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,155 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
/// <summary>
/// Class to decode and encode Hex.
/// </summary>
public sealed class Hex
{
private static readonly HexEncoder encoder = new HexEncoder();
private Hex()
{
}
public static string ToHexString(
byte[] data)
{
return ToHexString(data, 0, data.Length);
}
public static string ToHexString(
byte[] data,
int off,
int length)
{
byte[] hex = Encode(data, off, length);
return Strings.FromAsciiByteArray(hex);
}
/**
* encode the input data producing a Hex encoded byte array.
*
* @return a byte array containing the Hex encoded data.
*/
public static byte[] Encode(
byte[] data)
{
return Encode(data, 0, data.Length);
}
/**
* encode the input data producing a Hex encoded byte array.
*
* @return a byte array containing the Hex encoded data.
*/
public static byte[] Encode(
byte[] data,
int off,
int length)
{
MemoryStream bOut = new MemoryStream(length * 2);
encoder.Encode(data, off, length, bOut);
return bOut.ToArray();
}
/**
* Hex encode the byte data writing it to the given output stream.
*
* @return the number of bytes produced.
*/
public static int Encode(
byte[] data,
Stream outStream)
{
return encoder.Encode(data, 0, data.Length, outStream);
}
/**
* Hex encode the byte data writing it to the given output stream.
*
* @return the number of bytes produced.
*/
public static int Encode(
byte[] data,
int off,
int length,
Stream outStream)
{
return encoder.Encode(data, off, length, outStream);
}
/**
* decode the Hex encoded input data. It is assumed the input data is valid.
*
* @return a byte array representing the decoded data.
*/
public static byte[] Decode(
byte[] data)
{
MemoryStream bOut = new MemoryStream((data.Length + 1) / 2);
encoder.Decode(data, 0, data.Length, bOut);
return bOut.ToArray();
}
/**
* decode the Hex encoded string data - whitespace will be ignored.
*
* @return a byte array representing the decoded data.
*/
public static byte[] Decode(
string data)
{
MemoryStream bOut = new MemoryStream((data.Length + 1) / 2);
encoder.DecodeString(data, bOut);
return bOut.ToArray();
}
/**
* decode the Hex encoded string data writing it to the given output stream,
* whitespace characters will be ignored.
*
* @return the number of bytes produced.
*/
public static int Decode(
string data,
Stream outStream)
{
return encoder.DecodeString(data, outStream);
}
/**
* Decode the hexadecimal-encoded string strictly i.e. any non-hexadecimal characters will be
* considered an error.
*
* @return a byte array representing the decoded data.
*/
public static byte[] DecodeStrict(string str)
{
return encoder.DecodeStrict(str, 0, str.Length);
}
/**
* Decode the hexadecimal-encoded string strictly i.e. any non-hexadecimal characters will be
* considered an error.
*
* @return a byte array representing the decoded data.
*/
public static byte[] DecodeStrict(string str, int off, int len)
{
return encoder.DecodeStrict(str, off, len);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ed222e1db807254592957eb36667273
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,356 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
public class HexEncoder
: IEncoder
{
protected readonly byte[] encodingTable =
{
(byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7',
(byte)'8', (byte)'9', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f'
};
/*
* set up the decoding table.
*/
protected readonly byte[] decodingTable = new byte[128];
protected void InitialiseDecodingTable()
{
Arrays.Fill(decodingTable, (byte)0xff);
for (int i = 0; i < encodingTable.Length; i++)
{
decodingTable[encodingTable[i]] = (byte)i;
}
decodingTable['A'] = decodingTable['a'];
decodingTable['B'] = decodingTable['b'];
decodingTable['C'] = decodingTable['c'];
decodingTable['D'] = decodingTable['d'];
decodingTable['E'] = decodingTable['e'];
decodingTable['F'] = decodingTable['f'];
}
public HexEncoder()
{
InitialiseDecodingTable();
}
public int Encode(byte[] inBuf, int inOff, int inLen, byte[] outBuf, int outOff)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return Encode(inBuf.AsSpan(inOff, inLen), outBuf.AsSpan(outOff));
#else
int inPos = inOff;
int inEnd = inOff + inLen;
int outPos = outOff;
while (inPos < inEnd)
{
uint b = inBuf[inPos++];
outBuf[outPos++] = encodingTable[b >> 4];
outBuf[outPos++] = encodingTable[b & 0xF];
}
return outPos - outOff;
#endif
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public int Encode(ReadOnlySpan<byte> input, Span<byte> output)
{
int inPos = 0;
int inEnd = input.Length;
int outPos = 0;
while (inPos < inEnd)
{
uint b = input[inPos++];
output[outPos++] = encodingTable[b >> 4];
output[outPos++] = encodingTable[b & 0xF];
}
return outPos;
}
#endif
/**
* encode the input data producing a Hex output stream.
*
* @return the number of bytes produced.
*/
public int Encode(byte[] buf, int off, int len, Stream outStream)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return Encode(buf.AsSpan(off, len), outStream);
#else
if (len < 0)
return 0;
byte[] tmp = new byte[72];
int remaining = len;
while (remaining > 0)
{
int inLen = System.Math.Min(36, remaining);
int outLen = Encode(buf, off, inLen, tmp, 0);
outStream.Write(tmp, 0, outLen);
off += inLen;
remaining -= inLen;
}
return len * 2;
#endif
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public int Encode(ReadOnlySpan<byte> data, Stream outStream)
{
Span<byte> tmp = stackalloc byte[72];
int result = data.Length * 2;
while (!data.IsEmpty)
{
int inLen = System.Math.Min(36, data.Length);
int outLen = Encode(data[..inLen], tmp);
outStream.Write(tmp[..outLen]);
data = data[inLen..];
}
return result;
}
#endif
private static bool Ignore(char c)
{
return c == '\n' || c =='\r' || c == '\t' || c == ' ';
}
/**
* decode the Hex encoded byte data writing it to the given output stream,
* whitespace characters will be ignored.
*
* @return the number of bytes produced.
*/
public int Decode(byte[] data, int off, int length, Stream outStream)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
return Decode(data.AsSpan(off, length), outStream);
#else
byte b1, b2;
int outLen = 0;
byte[] buf = new byte[36];
int bufOff = 0;
int end = off + length;
while (end > off)
{
if (!Ignore((char)data[end - 1]))
break;
end--;
}
int i = off;
while (i < end)
{
while (i < end && Ignore((char)data[i]))
{
i++;
}
b1 = decodingTable[data[i++]];
while (i < end && Ignore((char)data[i]))
{
i++;
}
b2 = decodingTable[data[i++]];
if ((b1 | b2) >= 0x80)
throw new IOException("invalid characters encountered in Hex data");
buf[bufOff++] = (byte)((b1 << 4) | b2);
if (bufOff == buf.Length)
{
outStream.Write(buf, 0, bufOff);
bufOff = 0;
}
outLen++;
}
if (bufOff > 0)
{
outStream.Write(buf, 0, bufOff);
}
return outLen;
#endif
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public int Decode(ReadOnlySpan<byte> data, Stream outStream)
{
byte b1, b2;
int outLen = 0;
Span<byte> buf = stackalloc byte[36];
int bufOff = 0;
int end = data.Length;
while (end > 0)
{
if (!Ignore((char)data[end - 1]))
break;
end--;
}
int i = 0;
while (i < end)
{
while (i < end && Ignore((char)data[i]))
{
i++;
}
b1 = decodingTable[data[i++]];
while (i < end && Ignore((char)data[i]))
{
i++;
}
b2 = decodingTable[data[i++]];
if ((b1 | b2) >= 0x80)
throw new IOException("invalid characters encountered in Hex data");
buf[bufOff++] = (byte)((b1 << 4) | b2);
if (bufOff == buf.Length)
{
outStream.Write(buf);
bufOff = 0;
}
outLen++;
}
if (bufOff > 0)
{
outStream.Write(buf[..bufOff]);
}
return outLen;
}
#endif
/**
* decode the Hex encoded string data writing it to the given output stream,
* whitespace characters will be ignored.
*
* @return the number of bytes produced.
*/
public int DecodeString(string data, Stream outStream)
{
byte b1, b2;
int length = 0;
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
Span<byte> buf = stackalloc byte[36];
#else
byte[] buf = new byte[36];
#endif
int bufOff = 0;
int end = data.Length;
while (end > 0)
{
if (!Ignore(data[end - 1]))
break;
end--;
}
int i = 0;
while (i < end)
{
while (i < end && Ignore(data[i]))
{
i++;
}
b1 = decodingTable[data[i++]];
while (i < end && Ignore(data[i]))
{
i++;
}
b2 = decodingTable[data[i++]];
if ((b1 | b2) >= 0x80)
throw new IOException("invalid characters encountered in Hex data");
buf[bufOff++] = (byte)((b1 << 4) | b2);
if (bufOff == buf.Length)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
outStream.Write(buf);
#else
outStream.Write(buf, 0, bufOff);
#endif
bufOff = 0;
}
length++;
}
if (bufOff > 0)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
outStream.Write(buf[..bufOff]);
#else
outStream.Write(buf, 0, bufOff);
#endif
}
return length;
}
internal byte[] DecodeStrict(string str, int off, int len)
{
if (null == str)
throw new ArgumentNullException("str");
if (off < 0 || len < 0 || off > (str.Length - len))
throw new IndexOutOfRangeException("invalid offset and/or length specified");
if (0 != (len & 1))
throw new ArgumentException("a hexadecimal encoding must have an even number of characters", "len");
int resultLen = len >> 1;
byte[] result = new byte[resultLen];
int strPos = off;
for (int i = 0; i < resultLen; ++i)
{
byte b1 = decodingTable[str[strPos++]];
byte b2 = decodingTable[str[strPos++]];
if ((b1 | b2) >= 0x80)
throw new IOException("invalid characters encountered in Hex data");
result[i] = (byte)((b1 << 4) | b2);
}
return result;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 05d0f6c3caab0a549b8c1067b01bcbb2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,112 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
/// <summary>
/// A hex translator.
/// </summary>
public class HexTranslator : ITranslator
{
private static readonly byte[] hexTable =
{
(byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7',
(byte)'8', (byte)'9', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f'
};
/// <summary>
/// Return encoded block size.
/// </summary>
/// <returns>2</returns>
public int GetEncodedBlockSize()
{
return 2;
}
/// <summary>
/// Encode some data.
/// </summary>
/// <param name="input">Input data array.</param>
/// <param name="inOff">Start position within input data array.</param>
/// <param name="length">The amount of data to process.</param>
/// <param name="outBytes">The output data array.</param>
/// <param name="outOff">The offset within the output data array to start writing from.</param>
/// <returns>Amount of data encoded.</returns>
public int Encode(
byte[] input,
int inOff,
int length,
byte[] outBytes,
int outOff)
{
for (int i = 0, j = 0; i < length; i++, j += 2)
{
outBytes[outOff + j] = hexTable[(input[inOff] >> 4) & 0x0f];
outBytes[outOff + j + 1] = hexTable[input[inOff] & 0x0f];
inOff++;
}
return length * 2;
}
/// <summary>
/// Returns the decoded block size.
/// </summary>
/// <returns>1</returns>
public int GetDecodedBlockSize()
{
return 1;
}
/// <summary>
/// Decode data from a byte array.
/// </summary>
/// <param name="input">The input data array.</param>
/// <param name="inOff">Start position within input data array.</param>
/// <param name="length">The amounty of data to process.</param>
/// <param name="outBytes">The output data array.</param>
/// <param name="outOff">The position within the output data array to start writing from.</param>
/// <returns>The amount of data written.</returns>
public int Decode(
byte[] input,
int inOff,
int length,
byte[] outBytes,
int outOff)
{
int halfLength = length / 2;
byte left, right;
for (int i = 0; i < halfLength; i++)
{
left = input[inOff + i * 2];
right = input[inOff + i * 2 + 1];
if (left < (byte)'a')
{
outBytes[outOff] = (byte)((left - '0') << 4);
}
else
{
outBytes[outOff] = (byte)((left - 'a' + 10) << 4);
}
if (right < (byte)'a')
{
outBytes[outOff] += (byte)(right - '0');
}
else
{
outBytes[outOff] += (byte)(right - 'a' + 10);
}
outOff++;
}
return halfLength;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a4cfe8d15199522458337f90de553550
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
/**
* Encode and decode byte arrays (typically from binary to 7-bit ASCII
* encodings).
*/
public interface IEncoder
{
int Encode(byte[] data, int off, int length, Stream outStream);
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
int Encode(ReadOnlySpan<byte> data, Stream outStream);
#endif
int Decode(byte[] data, int off, int length, Stream outStream);
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
int Decode(ReadOnlySpan<byte> data, Stream outStream);
#endif
int DecodeString(string data, Stream outStream);
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2e240a99386c56d4c833831f5247b554
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
/// <summary>
/// Translator interface.
/// </summary>
public interface ITranslator
{
int GetEncodedBlockSize();
int Encode(byte[] input, int inOff, int length, byte[] outBytes, int outOff);
int GetDecodedBlockSize();
int Decode(byte[] input, int inOff, int length, byte[] outBytes, int outOff);
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fd4d0e7a77106f047a8aab6380c5e046
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,131 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
/**
* Convert binary data to and from UrlBase64 encoding. This is identical to
* Base64 encoding, except that the padding character is "." and the other
* non-alphanumeric characters are "-" and "_" instead of "+" and "/".
* <p>
* The purpose of UrlBase64 encoding is to provide a compact encoding of binary
* data that is safe for use as an URL parameter. Base64 encoding does not
* produce encoded values that are safe for use in URLs, since "/" can be
* interpreted as a path delimiter; "+" is the encoded form of a space; and
* "=" is used to separate a name from the corresponding value in an URL
* parameter.
* </p>
*/
public class UrlBase64
{
private static readonly IEncoder encoder = new UrlBase64Encoder();
/**
* Encode the input data producing a URL safe base 64 encoded byte array.
*
* @return a byte array containing the URL safe base 64 encoded data.
*/
public static byte[] Encode(
byte[] data)
{
MemoryStream bOut = new MemoryStream();
try
{
encoder.Encode(data, 0, data.Length, bOut);
}
catch (IOException e)
{
throw new Exception("exception encoding URL safe base64 string: " + e.Message, e);
}
return bOut.ToArray();
}
/**
* Encode the byte data writing it to the given output stream.
*
* @return the number of bytes produced.
*/
public static int Encode(
byte[] data,
Stream outStr)
{
return encoder.Encode(data, 0, data.Length, outStr);
}
/**
* Decode the URL safe base 64 encoded input data - white space will be ignored.
*
* @return a byte array representing the decoded data.
*/
public static byte[] Decode(
byte[] data)
{
MemoryStream bOut = new MemoryStream();
try
{
encoder.Decode(data, 0, data.Length, bOut);
}
catch (IOException e)
{
throw new Exception("exception decoding URL safe base64 string: " + e.Message, e);
}
return bOut.ToArray();
}
/**
* decode the URL safe base 64 encoded byte data writing it to the given output stream,
* whitespace characters will be ignored.
*
* @return the number of bytes produced.
*/
public static int Decode(
byte[] data,
Stream outStr)
{
return encoder.Decode(data, 0, data.Length, outStr);
}
/**
* decode the URL safe base 64 encoded string data - whitespace will be ignored.
*
* @return a byte array representing the decoded data.
*/
public static byte[] Decode(
string data)
{
MemoryStream bOut = new MemoryStream();
try
{
encoder.DecodeString(data, bOut);
}
catch (IOException e)
{
throw new Exception("exception decoding URL safe base64 string: " + e.Message, e);
}
return bOut.ToArray();
}
/**
* Decode the URL safe base 64 encoded string data writing it to the given output stream,
* whitespace characters will be ignored.
*
* @return the number of bytes produced.
*/
public static int Decode(
string data,
Stream outStr)
{
return encoder.DecodeString(data, outStr);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b90f1cc819741c42aa20ee7dee4e85a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders
{
/**
* Convert binary data to and from UrlBase64 encoding. This is identical to
* Base64 encoding, except that the padding character is "." and the other
* non-alphanumeric characters are "-" and "_" instead of "+" and "/".
* <p>
* The purpose of UrlBase64 encoding is to provide a compact encoding of binary
* data that is safe for use as an URL parameter. Base64 encoding does not
* produce encoded values that are safe for use in URLs, since "/" can be
* interpreted as a path delimiter; "+" is the encoded form of a space; and
* "=" is used to separate a name from the corresponding value in an URL
* parameter.
* </p>
*/
public class UrlBase64Encoder
: Base64Encoder
{
public UrlBase64Encoder()
{
encodingTable[encodingTable.Length - 2] = (byte) '-';
encodingTable[encodingTable.Length - 1] = (byte) '_';
padding = (byte) '.';
// we must re-create the decoding table with the new encoded values.
InitialiseDecodingTable();
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39a7d129d5716d94db71754607e15ec5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8d0ebd9539721c34daaadeafccd8ed9d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
{
public abstract class BaseInputStream
: Stream
{
public sealed override bool CanRead { get { return true; } }
public sealed override bool CanSeek { get { return false; } }
public sealed override bool CanWrite { get { return false; } }
public sealed override void 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)
{
Streams.ValidateBufferArguments(buffer, offset, count);
int pos = 0;
try
{
while (pos < count)
{
int b = ReadByte();
if (b < 0)
break;
buffer[offset + pos++] = (byte)b;
}
}
catch (IOException)
{
if (pos == 0)
throw;
}
return pos;
}
public sealed override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); }
public sealed override void SetLength(long value) { throw new NotSupportedException(); }
public sealed override void Write(byte[] buffer, int offset, int count) { throw new NotSupportedException(); }
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public override void Write(ReadOnlySpan<byte> buffer) { throw new NotSupportedException(); }
#endif
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6c55c7018496d63408687d3da511e3ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
{
public abstract class BaseOutputStream
: Stream
{
public sealed override bool CanRead { get { return false; } }
public sealed override bool CanSeek { get { return false; } }
public sealed override bool CanWrite { get { return true; } }
#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) { throw new NotSupportedException(); }
#endif
public override void Flush() {}
public sealed override long Length { get { throw new NotSupportedException(); } }
public sealed override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public sealed override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); }
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public sealed override int Read(Span<byte> buffer) { throw new NotSupportedException(); }
#endif
public sealed override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); }
public sealed override void SetLength(long value) { throw new NotSupportedException(); }
public override void Write(byte[] buffer, int offset, int count)
{
Streams.ValidateBufferArguments(buffer, offset, count);
for (int i = 0; i < count; ++i)
{
WriteByte(buffer[offset + i]);
}
}
public virtual void Write(params byte[] buffer)
{
Write(buffer, 0, buffer.Length);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a6aa30f111ed30408694c452b3e0947
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,98 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
{
public static class BinaryReaders
{
public static byte[] ReadBytesFully(BinaryReader binaryReader, int count)
{
byte[] bytes = binaryReader.ReadBytes(count);
if (bytes == null || bytes.Length != count)
throw new EndOfStreamException();
return bytes;
}
public static short ReadInt16BigEndian(BinaryReader binaryReader)
{
short n = binaryReader.ReadInt16();
return BitConverter.IsLittleEndian ? Shorts.ReverseBytes(n) : n;
}
public static short ReadInt16LittleEndian(BinaryReader binaryReader)
{
short n = binaryReader.ReadInt16();
return BitConverter.IsLittleEndian ? n : Shorts.ReverseBytes(n);
}
public static int ReadInt32BigEndian(BinaryReader binaryReader)
{
int n = binaryReader.ReadInt32();
return BitConverter.IsLittleEndian ? Integers.ReverseBytes(n) : n;
}
public static int ReadInt32LittleEndian(BinaryReader binaryReader)
{
int n = binaryReader.ReadInt32();
return BitConverter.IsLittleEndian ? n : Integers.ReverseBytes(n);
}
public static long ReadInt64BigEndian(BinaryReader binaryReader)
{
long n = binaryReader.ReadInt64();
return BitConverter.IsLittleEndian ? Longs.ReverseBytes(n) : n;
}
public static long ReadInt64LittleEndian(BinaryReader binaryReader)
{
long n = binaryReader.ReadInt64();
return BitConverter.IsLittleEndian ? n : Longs.ReverseBytes(n);
}
[CLSCompliant(false)]
public static ushort ReadUInt16BigEndian(BinaryReader binaryReader)
{
ushort n = binaryReader.ReadUInt16();
return BitConverter.IsLittleEndian ? Shorts.ReverseBytes(n) : n;
}
[CLSCompliant(false)]
public static ushort ReadUInt16LittleEndian(BinaryReader binaryReader)
{
ushort n = binaryReader.ReadUInt16();
return BitConverter.IsLittleEndian ? n : Shorts.ReverseBytes(n);
}
[CLSCompliant(false)]
public static uint ReadUInt32BigEndian(BinaryReader binaryReader)
{
uint n = binaryReader.ReadUInt32();
return BitConverter.IsLittleEndian ? Integers.ReverseBytes(n) : n;
}
[CLSCompliant(false)]
public static uint ReadUInt32LittleEndian(BinaryReader binaryReader)
{
uint n = binaryReader.ReadUInt32();
return BitConverter.IsLittleEndian ? n : Integers.ReverseBytes(n);
}
[CLSCompliant(false)]
public static ulong ReadUInt64BigEndian(BinaryReader binaryReader)
{
ulong n = binaryReader.ReadUInt64();
return BitConverter.IsLittleEndian ? Longs.ReverseBytes(n) : n;
}
[CLSCompliant(false)]
public static ulong ReadUInt64LittleEndian(BinaryReader binaryReader)
{
ulong n = binaryReader.ReadUInt64();
return BitConverter.IsLittleEndian ? n : Longs.ReverseBytes(n);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 363e4c910179d7244a77ced662a52003
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
{
public static class BinaryWriters
{
public static void WriteInt16BigEndian(BinaryWriter binaryWriter, short n)
{
short bigEndian = BitConverter.IsLittleEndian ? Shorts.ReverseBytes(n) : n;
binaryWriter.Write(bigEndian);
}
public static void WriteInt16LittleEndian(BinaryWriter binaryWriter, short n)
{
short littleEndian = BitConverter.IsLittleEndian ? n : Shorts.ReverseBytes(n);
binaryWriter.Write(littleEndian);
}
public static void WriteInt32BigEndian(BinaryWriter binaryWriter, int n)
{
int bigEndian = BitConverter.IsLittleEndian ? Integers.ReverseBytes(n) : n;
binaryWriter.Write(bigEndian);
}
public static void WriteInt32LittleEndian(BinaryWriter binaryWriter, int n)
{
int littleEndian = BitConverter.IsLittleEndian ? n : Integers.ReverseBytes(n);
binaryWriter.Write(littleEndian);
}
public static void WriteInt64BigEndian(BinaryWriter binaryWriter, long n)
{
long bigEndian = BitConverter.IsLittleEndian ? Longs.ReverseBytes(n) : n;
binaryWriter.Write(bigEndian);
}
public static void WriteInt64LittleEndian(BinaryWriter binaryWriter, long n)
{
long littleEndian = BitConverter.IsLittleEndian ? n : Longs.ReverseBytes(n);
binaryWriter.Write(littleEndian);
}
[CLSCompliant(false)]
public static void WriteUInt16BigEndian(BinaryWriter binaryWriter, ushort n)
{
ushort bigEndian = BitConverter.IsLittleEndian ? Shorts.ReverseBytes(n) : n;
binaryWriter.Write(bigEndian);
}
[CLSCompliant(false)]
public static void WriteUInt16LittleEndian(BinaryWriter binaryWriter, ushort n)
{
ushort littleEndian = BitConverter.IsLittleEndian ? n : Shorts.ReverseBytes(n);
binaryWriter.Write(littleEndian);
}
[CLSCompliant(false)]
public static void WriteUInt32BigEndian(BinaryWriter binaryWriter, uint n)
{
uint bigEndian = BitConverter.IsLittleEndian ? Integers.ReverseBytes(n) : n;
binaryWriter.Write(bigEndian);
}
[CLSCompliant(false)]
public static void WriteUInt32LittleEndian(BinaryWriter binaryWriter, uint n)
{
uint littleEndian = BitConverter.IsLittleEndian ? n : Integers.ReverseBytes(n);
binaryWriter.Write(littleEndian);
}
[CLSCompliant(false)]
public static void WriteUInt64BigEndian(BinaryWriter binaryWriter, ulong n)
{
ulong bigEndian = BitConverter.IsLittleEndian ? Longs.ReverseBytes(n) : n;
binaryWriter.Write(bigEndian);
}
[CLSCompliant(false)]
public static void WriteUInt64LittleEndian(BinaryWriter binaryWriter, ulong n)
{
ulong littleEndian = BitConverter.IsLittleEndian ? n : Longs.ReverseBytes(n);
binaryWriter.Write(littleEndian);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7f41708fc94768343bede3d0cee338ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,100 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
{
public class FilterStream
: Stream
{
protected readonly Stream s;
public FilterStream(Stream s)
{
this.s = s ?? throw new ArgumentNullException(nameof(s));
}
public override bool CanRead
{
get { return s.CanRead; }
}
public override bool CanSeek
{
get { return s.CanSeek; }
}
public override bool CanWrite
{
get { return s.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)
{
s.CopyTo(destination, bufferSize);
}
#endif
public override void Flush()
{
s.Flush();
}
public override long Length
{
get { return s.Length; }
}
public override long Position
{
get { return s.Position; }
set { s.Position = value; }
}
public override int Read(byte[] buffer, int offset, int count)
{
return s.Read(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 s.Read(buffer);
}
#endif
public override int ReadByte()
{
return s.ReadByte();
}
public override long Seek(long offset, SeekOrigin origin)
{
return s.Seek(offset, origin);
}
public override void SetLength(long value)
{
s.SetLength(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
s.Write(buffer, offset, count);
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public override void Write(ReadOnlySpan<byte> buffer)
{
s.Write(buffer);
}
#endif
public override void WriteByte(byte value)
{
s.WriteByte(value);
}
protected void Detach(bool disposing)
{
base.Dispose(disposing);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
s.Dispose();
}
base.Dispose(disposing);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3fce67f814432d848a840ddec287f366
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Zlib;
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
{
internal class LimitedInputStream
: BaseInputStream
{
private readonly Stream m_stream;
private long m_limit;
internal LimitedInputStream(Stream stream, long limit)
{
this.m_stream = stream;
this.m_limit = limit;
}
internal long CurrentLimit => m_limit;
public override int Read(byte[] buffer, int offset, int count)
{
int numRead = m_stream.Read(buffer, offset, count);
if (numRead > 0)
{
if ((m_limit -= numRead) < 0)
throw new StreamOverflowException("Data Overflow");
}
return numRead;
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public override int Read(Span<byte> buffer)
{
int numRead = m_stream.Read(buffer);
if (numRead > 0)
{
if ((m_limit -= numRead) < 0)
throw new StreamOverflowException("Data Overflow");
}
return numRead;
}
#endif
public override int ReadByte()
{
int b = m_stream.ReadByte();
if (b >= 0)
{
if (--m_limit < 0)
throw new StreamOverflowException("Data Overflow");
}
return b;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 51e6e462295cfec4893c651eb750729f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
{
public class MemoryInputStream
: MemoryStream
{
public MemoryInputStream(byte[] buffer)
: base(buffer, false)
{
}
public sealed override bool CanWrite
{
get { return false; }
}
}
}
#pragma warning restore
#endif

Some files were not shown because too many files have changed in this diff Show More