up
This commit is contained in:
68
Assets/BestHTTP/SecureProtocol/util/io/BaseInputStream.cs
Normal file
68
Assets/BestHTTP/SecureProtocol/util/io/BaseInputStream.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO
|
||||
{
|
||||
public abstract class BaseInputStream : Stream
|
||||
{
|
||||
private bool closed;
|
||||
|
||||
public sealed override bool CanRead { get { return !closed; } }
|
||||
public sealed override bool CanSeek { get { return false; } }
|
||||
public sealed override bool CanWrite { get { return false; } }
|
||||
|
||||
#if PORTABLE || NETFX_CORE
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
closed = true;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#else
|
||||
public override void Close()
|
||||
{
|
||||
closed = true;
|
||||
base.Close();
|
||||
}
|
||||
#endif
|
||||
|
||||
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)
|
||||
{
|
||||
int pos = offset;
|
||||
try
|
||||
{
|
||||
int end = offset + count;
|
||||
while (pos < end)
|
||||
{
|
||||
int b = ReadByte();
|
||||
if (b == -1) break;
|
||||
buffer[pos++] = (byte) b;
|
||||
}
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
if (pos == offset) throw;
|
||||
}
|
||||
return pos - offset;
|
||||
}
|
||||
|
||||
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(); }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6357fddea7644e249766dab6f5b96d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
Assets/BestHTTP/SecureProtocol/util/io/BaseOutputStream.cs
Normal file
68
Assets/BestHTTP/SecureProtocol/util/io/BaseOutputStream.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO
|
||||
{
|
||||
public abstract class BaseOutputStream : Stream
|
||||
{
|
||||
private bool closed;
|
||||
|
||||
public sealed override bool CanRead { get { return false; } }
|
||||
public sealed override bool CanSeek { get { return false; } }
|
||||
public sealed override bool CanWrite { get { return !closed; } }
|
||||
|
||||
#if PORTABLE || NETFX_CORE
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
closed = true;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#else
|
||||
public override void Close()
|
||||
{
|
||||
closed = true;
|
||||
base.Close();
|
||||
}
|
||||
#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(); }
|
||||
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)
|
||||
{
|
||||
Debug.Assert(buffer != null);
|
||||
Debug.Assert(0 <= offset && offset <= buffer.Length);
|
||||
Debug.Assert(count >= 0);
|
||||
|
||||
int end = offset + count;
|
||||
|
||||
Debug.Assert(0 <= end && end <= buffer.Length);
|
||||
|
||||
for (int i = offset; i < end; ++i)
|
||||
{
|
||||
this.WriteByte(buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Write(params byte[] buffer)
|
||||
{
|
||||
Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6afc1dbc44f374dfa8e140562e41e37e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
82
Assets/BestHTTP/SecureProtocol/util/io/FilterStream.cs
Normal file
82
Assets/BestHTTP/SecureProtocol/util/io/FilterStream.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO
|
||||
{
|
||||
public class FilterStream : Stream
|
||||
{
|
||||
public FilterStream(Stream s)
|
||||
{
|
||||
this.s = 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; }
|
||||
}
|
||||
public override long Length
|
||||
{
|
||||
get { return s.Length; }
|
||||
}
|
||||
public override long Position
|
||||
{
|
||||
get { return s.Position; }
|
||||
set { s.Position = value; }
|
||||
}
|
||||
#if PORTABLE || NETFX_CORE
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Platform.Dispose(s);
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#else
|
||||
public override void Close()
|
||||
{
|
||||
Platform.Dispose(s);
|
||||
base.Close();
|
||||
}
|
||||
#endif
|
||||
public override void Flush()
|
||||
{
|
||||
s.Flush();
|
||||
}
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
return s.Seek(offset, origin);
|
||||
}
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
s.SetLength(value);
|
||||
}
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
return s.Read(buffer, offset, count);
|
||||
}
|
||||
public override int ReadByte()
|
||||
{
|
||||
return s.ReadByte();
|
||||
}
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
s.Write(buffer, offset, count);
|
||||
}
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
s.WriteByte(value);
|
||||
}
|
||||
protected readonly Stream s;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/util/io/FilterStream.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/util/io/FilterStream.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 529d64ed1d56842e9944f996a207f013
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
Assets/BestHTTP/SecureProtocol/util/io/PushbackStream.cs
Normal file
56
Assets/BestHTTP/SecureProtocol/util/io/PushbackStream.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Asn1.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO
|
||||
{
|
||||
public class PushbackStream
|
||||
: FilterStream
|
||||
{
|
||||
private int buf = -1;
|
||||
|
||||
public PushbackStream(
|
||||
Stream s)
|
||||
: base(s)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
if (buf != -1)
|
||||
{
|
||||
int tmp = buf;
|
||||
buf = -1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return base.ReadByte();
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (buf != -1 && count > 0)
|
||||
{
|
||||
// TODO Can this case be made more efficient?
|
||||
buffer[offset] = (byte) buf;
|
||||
buf = -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return base.Read(buffer, offset, count);
|
||||
}
|
||||
|
||||
public virtual void Unread(int b)
|
||||
{
|
||||
if (buf != -1)
|
||||
throw new InvalidOperationException("Can only push back one byte");
|
||||
|
||||
buf = b & 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cb0ac95874654e44aaf0c5248b0d03f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO
|
||||
{
|
||||
#if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || NETFX_CORE)
|
||||
[Serializable]
|
||||
#endif
|
||||
public class StreamOverflowException
|
||||
: IOException
|
||||
{
|
||||
public StreamOverflowException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public StreamOverflowException(
|
||||
string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public StreamOverflowException(
|
||||
string message,
|
||||
Exception exception)
|
||||
: base(message, exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0b1e84e6f92445578cb3ed0e2050eb1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
98
Assets/BestHTTP/SecureProtocol/util/io/Streams.cs
Normal file
98
Assets/BestHTTP/SecureProtocol/util/io/Streams.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO
|
||||
{
|
||||
public sealed class Streams
|
||||
{
|
||||
private const int BufferSize = 512;
|
||||
|
||||
private Streams()
|
||||
{
|
||||
}
|
||||
|
||||
public static void Drain(Stream inStr)
|
||||
{
|
||||
byte[] bs = new byte[BufferSize];
|
||||
while (inStr.Read(bs, 0, bs.Length) > 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] ReadAll(Stream inStr)
|
||||
{
|
||||
MemoryStream buf = new MemoryStream();
|
||||
PipeAll(inStr, buf);
|
||||
return buf.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] ReadAllLimited(Stream inStr, int limit)
|
||||
{
|
||||
MemoryStream buf = new MemoryStream();
|
||||
PipeAllLimited(inStr, limit, buf);
|
||||
return buf.ToArray();
|
||||
}
|
||||
|
||||
public static int ReadFully(Stream inStr, byte[] buf)
|
||||
{
|
||||
return ReadFully(inStr, buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
public static int ReadFully(Stream inStr, byte[] buf, int off, int len)
|
||||
{
|
||||
int totalRead = 0;
|
||||
while (totalRead < len)
|
||||
{
|
||||
int numRead = inStr.Read(buf, off + totalRead, len - totalRead);
|
||||
if (numRead < 1)
|
||||
break;
|
||||
totalRead += numRead;
|
||||
}
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
public static void PipeAll(Stream inStr, Stream outStr)
|
||||
{
|
||||
byte[] bs = new byte[BufferSize];
|
||||
int numRead;
|
||||
while ((numRead = inStr.Read(bs, 0, bs.Length)) > 0)
|
||||
{
|
||||
outStr.Write(bs, 0, numRead);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pipe all bytes from <c>inStr</c> to <c>outStr</c>, throwing <c>StreamFlowException</c> if greater
|
||||
/// than <c>limit</c> bytes in <c>inStr</c>.
|
||||
/// </summary>
|
||||
/// <param name="inStr">
|
||||
/// A <see cref="Stream"/>
|
||||
/// </param>
|
||||
/// <param name="limit">
|
||||
/// A <see cref="System.Int64"/>
|
||||
/// </param>
|
||||
/// <param name="outStr">
|
||||
/// A <see cref="Stream"/>
|
||||
/// </param>
|
||||
/// <returns>The number of bytes actually transferred, if not greater than <c>limit</c></returns>
|
||||
/// <exception cref="IOException"></exception>
|
||||
public static long PipeAllLimited(Stream inStr, long limit, Stream outStr)
|
||||
{
|
||||
byte[] bs = new byte[BufferSize];
|
||||
long total = 0;
|
||||
int numRead;
|
||||
while ((numRead = inStr.Read(bs, 0, bs.Length)) > 0)
|
||||
{
|
||||
if ((limit - total) < numRead)
|
||||
throw new StreamOverflowException("Data Overflow");
|
||||
total += numRead;
|
||||
outStr.Write(bs, 0, numRead);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/util/io/Streams.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/util/io/Streams.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78c26e49b7eb341f6b73fb38eedac9fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
Assets/BestHTTP/SecureProtocol/util/io/TeeInputStream.cs
Normal file
68
Assets/BestHTTP/SecureProtocol/util/io/TeeInputStream.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO
|
||||
{
|
||||
public class TeeInputStream
|
||||
: BaseInputStream
|
||||
{
|
||||
private readonly Stream input, tee;
|
||||
|
||||
public TeeInputStream(Stream input, Stream tee)
|
||||
{
|
||||
Debug.Assert(input.CanRead);
|
||||
Debug.Assert(tee.CanWrite);
|
||||
|
||||
this.input = input;
|
||||
this.tee = tee;
|
||||
}
|
||||
|
||||
#if PORTABLE || NETFX_CORE
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Platform.Dispose(input);
|
||||
Platform.Dispose(tee);
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#else
|
||||
public override void Close()
|
||||
{
|
||||
Platform.Dispose(input);
|
||||
Platform.Dispose(tee);
|
||||
base.Close();
|
||||
}
|
||||
#endif
|
||||
|
||||
public override int Read(byte[] buf, int off, int len)
|
||||
{
|
||||
int i = input.Read(buf, off, len);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
tee.Write(buf, off, i);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
int i = input.ReadByte();
|
||||
|
||||
if (i >= 0)
|
||||
{
|
||||
tee.WriteByte((byte)i);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1099b7adb6d741bc81389d373287854
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
Assets/BestHTTP/SecureProtocol/util/io/TeeOutputStream.cs
Normal file
56
Assets/BestHTTP/SecureProtocol/util/io/TeeOutputStream.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO
|
||||
{
|
||||
public class TeeOutputStream
|
||||
: BaseOutputStream
|
||||
{
|
||||
private readonly Stream output, tee;
|
||||
|
||||
public TeeOutputStream(Stream output, Stream tee)
|
||||
{
|
||||
Debug.Assert(output.CanWrite);
|
||||
Debug.Assert(tee.CanWrite);
|
||||
|
||||
this.output = output;
|
||||
this.tee = tee;
|
||||
}
|
||||
|
||||
#if PORTABLE || NETFX_CORE
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Platform.Dispose(output);
|
||||
Platform.Dispose(tee);
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#else
|
||||
public override void Close()
|
||||
{
|
||||
Platform.Dispose(output);
|
||||
Platform.Dispose(tee);
|
||||
base.Close();
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
output.Write(buffer, offset, count);
|
||||
tee.Write(buffer, offset, count);
|
||||
}
|
||||
|
||||
public override void WriteByte(byte b)
|
||||
{
|
||||
output.WriteByte(b);
|
||||
tee.WriteByte(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a41fb5b961c6e432f867965b7c9d2e8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/BestHTTP/SecureProtocol/util/io/pem.meta
Normal file
8
Assets/BestHTTP/SecureProtocol/util/io/pem.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2aad6b33bf5124304a603320ea6c46bd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO.Pem
|
||||
{
|
||||
#if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || NETFX_CORE || PORTABLE)
|
||||
[Serializable]
|
||||
#endif
|
||||
public class PemGenerationException
|
||||
: Exception
|
||||
{
|
||||
public PemGenerationException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public PemGenerationException(
|
||||
string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public PemGenerationException(
|
||||
string message,
|
||||
Exception exception)
|
||||
: base(message, exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e7b8e2ca4c2e4f6586b9a1eccf99cdd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
59
Assets/BestHTTP/SecureProtocol/util/io/pem/PemHeader.cs
Normal file
59
Assets/BestHTTP/SecureProtocol/util/io/pem/PemHeader.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO.Pem
|
||||
{
|
||||
public class PemHeader
|
||||
{
|
||||
private string name;
|
||||
private string val;
|
||||
|
||||
public PemHeader(string name, string val)
|
||||
{
|
||||
this.name = name;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public virtual string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public virtual string Value
|
||||
{
|
||||
get { return val; }
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return GetHashCode(this.name) + 31 * GetHashCode(this.val);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
if (!(obj is PemHeader))
|
||||
return false;
|
||||
|
||||
PemHeader other = (PemHeader)obj;
|
||||
|
||||
return Platform.Equals(this.name, other.name)
|
||||
&& Platform.Equals(this.val, other.val);
|
||||
}
|
||||
|
||||
private int GetHashCode(string s)
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return s.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/util/io/pem/PemHeader.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/util/io/pem/PemHeader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f2ca8f97e5a942d7a2f54a04b48edc3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/BestHTTP/SecureProtocol/util/io/pem/PemObject.cs
Normal file
51
Assets/BestHTTP/SecureProtocol/util/io/pem/PemObject.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO.Pem
|
||||
{
|
||||
public class PemObject
|
||||
: PemObjectGenerator
|
||||
{
|
||||
private string type;
|
||||
private IList headers;
|
||||
private byte[] content;
|
||||
|
||||
public PemObject(string type, byte[] content)
|
||||
: this(type, Platform.CreateArrayList(), content)
|
||||
{
|
||||
}
|
||||
|
||||
public PemObject(String type, IList headers, byte[] content)
|
||||
{
|
||||
this.type = type;
|
||||
this.headers = Platform.CreateArrayList(headers);
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public string Type
|
||||
{
|
||||
get { return type; }
|
||||
}
|
||||
|
||||
public IList Headers
|
||||
{
|
||||
get { return headers; }
|
||||
}
|
||||
|
||||
public byte[] Content
|
||||
{
|
||||
get { return content; }
|
||||
}
|
||||
|
||||
public PemObject Generate()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/util/io/pem/PemObject.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/util/io/pem/PemObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01648e8319fa246d69d930c059436d58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO.Pem
|
||||
{
|
||||
public interface PemObjectGenerator
|
||||
{
|
||||
/// <returns>
|
||||
/// A <see cref="PemObject"/>
|
||||
/// </returns>
|
||||
/// <exception cref="PemGenerationException"></exception>
|
||||
PemObject Generate();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1e75865d48ea41928e9f47afcf717c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
100
Assets/BestHTTP/SecureProtocol/util/io/pem/PemReader.cs
Normal file
100
Assets/BestHTTP/SecureProtocol/util/io/pem/PemReader.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using Org.BouncyCastle.Utilities.Encoders;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO.Pem
|
||||
{
|
||||
public class PemReader
|
||||
{
|
||||
private const string BeginString = "-----BEGIN ";
|
||||
private const string EndString = "-----END ";
|
||||
|
||||
private readonly TextReader reader;
|
||||
|
||||
public PemReader(TextReader reader)
|
||||
{
|
||||
if (reader == null)
|
||||
throw new ArgumentNullException("reader");
|
||||
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public TextReader Reader
|
||||
{
|
||||
get { return reader; }
|
||||
}
|
||||
|
||||
/// <returns>
|
||||
/// A <see cref="PemObject"/>
|
||||
/// </returns>
|
||||
/// <exception cref="IOException"></exception>
|
||||
public PemObject ReadPemObject()
|
||||
{
|
||||
string line = reader.ReadLine();
|
||||
|
||||
if (line != null && Platform.StartsWith(line, BeginString))
|
||||
{
|
||||
line = line.Substring(BeginString.Length);
|
||||
int index = line.IndexOf('-');
|
||||
string type = line.Substring(0, index);
|
||||
|
||||
if (index > 0)
|
||||
return LoadObject(type);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private PemObject LoadObject(string type)
|
||||
{
|
||||
string endMarker = EndString + type;
|
||||
IList headers = Platform.CreateArrayList();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null
|
||||
&& Platform.IndexOf(line, endMarker) == -1)
|
||||
{
|
||||
int colonPos = line.IndexOf(':');
|
||||
|
||||
if (colonPos == -1)
|
||||
{
|
||||
buf.Append(line.Trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Process field
|
||||
string fieldName = line.Substring(0, colonPos).Trim();
|
||||
|
||||
if (Platform.StartsWith(fieldName, "X-"))
|
||||
{
|
||||
fieldName = fieldName.Substring(2);
|
||||
}
|
||||
|
||||
string fieldValue = line.Substring(colonPos + 1).Trim();
|
||||
|
||||
headers.Add(new PemHeader(fieldName, fieldValue));
|
||||
}
|
||||
}
|
||||
|
||||
if (line == null)
|
||||
{
|
||||
throw new IOException(endMarker + " not found");
|
||||
}
|
||||
|
||||
if (buf.Length % 4 != 0)
|
||||
{
|
||||
throw new IOException("base64 data appears to be truncated");
|
||||
}
|
||||
|
||||
return new PemObject(type, headers, Base64.Decode(buf.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/util/io/pem/PemReader.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/util/io/pem/PemReader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dca10f52a37dd414dbda6523a138f7ab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
124
Assets/BestHTTP/SecureProtocol/util/io/pem/PemWriter.cs
Normal file
124
Assets/BestHTTP/SecureProtocol/util/io/pem/PemWriter.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.Encoders;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.IO.Pem
|
||||
{
|
||||
/**
|
||||
* A generic PEM writer, based on RFC 1421
|
||||
*/
|
||||
public class PemWriter
|
||||
{
|
||||
private const int LineLength = 64;
|
||||
|
||||
private readonly TextWriter writer;
|
||||
private readonly int nlLength;
|
||||
private char[] buf = new char[LineLength];
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param out output stream to use.
|
||||
*/
|
||||
public PemWriter(TextWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
throw new ArgumentNullException("writer");
|
||||
|
||||
this.writer = writer;
|
||||
this.nlLength = Platform.NewLine.Length;
|
||||
}
|
||||
|
||||
public TextWriter Writer
|
||||
{
|
||||
get { return writer; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of bytes or characters required to contain the
|
||||
* passed in object if it is PEM encoded.
|
||||
*
|
||||
* @param obj pem object to be output
|
||||
* @return an estimate of the number of bytes
|
||||
*/
|
||||
public int GetOutputSize(PemObject obj)
|
||||
{
|
||||
// BEGIN and END boundaries.
|
||||
int size = (2 * (obj.Type.Length + 10 + nlLength)) + 6 + 4;
|
||||
|
||||
if (obj.Headers.Count > 0)
|
||||
{
|
||||
foreach (PemHeader header in obj.Headers)
|
||||
{
|
||||
size += header.Name.Length + ": ".Length + header.Value.Length + nlLength;
|
||||
}
|
||||
|
||||
size += nlLength;
|
||||
}
|
||||
|
||||
// base64 encoding
|
||||
int dataLen = ((obj.Content.Length + 2) / 3) * 4;
|
||||
|
||||
size += dataLen + (((dataLen + LineLength - 1) / LineLength) * nlLength);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public void WriteObject(PemObjectGenerator objGen)
|
||||
{
|
||||
PemObject obj = objGen.Generate();
|
||||
|
||||
WritePreEncapsulationBoundary(obj.Type);
|
||||
|
||||
if (obj.Headers.Count > 0)
|
||||
{
|
||||
foreach (PemHeader header in obj.Headers)
|
||||
{
|
||||
writer.Write(header.Name);
|
||||
writer.Write(": ");
|
||||
writer.WriteLine(header.Value);
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
WriteEncoded(obj.Content);
|
||||
WritePostEncapsulationBoundary(obj.Type);
|
||||
}
|
||||
|
||||
private void WriteEncoded(byte[] bytes)
|
||||
{
|
||||
bytes = Base64.Encode(bytes);
|
||||
|
||||
for (int i = 0; i < bytes.Length; i += buf.Length)
|
||||
{
|
||||
int index = 0;
|
||||
while (index != buf.Length)
|
||||
{
|
||||
if ((i + index) >= bytes.Length)
|
||||
break;
|
||||
|
||||
buf[index] = (char)bytes[i + index];
|
||||
index++;
|
||||
}
|
||||
writer.WriteLine(buf, 0, index);
|
||||
}
|
||||
}
|
||||
|
||||
private void WritePreEncapsulationBoundary(string type)
|
||||
{
|
||||
writer.WriteLine("-----BEGIN " + type + "-----");
|
||||
}
|
||||
|
||||
private void WritePostEncapsulationBoundary(string type)
|
||||
{
|
||||
writer.WriteLine("-----END " + type + "-----");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/util/io/pem/PemWriter.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/util/io/pem/PemWriter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e2d2085aa7c54e9c82ff4d569e6bf5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user