up
This commit is contained in:
112
Assets/BestHTTP/SecureProtocol/ReflectionHelpers.cs
Normal file
112
Assets/BestHTTP/SecureProtocol/ReflectionHelpers.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#if UNITY_WSA && !UNITY_EDITOR && !ENABLE_IL2CPP
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace System.TypeFix
|
||||
{
|
||||
public static class ReflectionHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the specified object is an instance of the current Type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="o">The object to compare with the current type.</param>
|
||||
/// <returns>true if the current Type is in the inheritance hierarchy of the
|
||||
/// object represented by o, or if the current Type is an interface that o
|
||||
/// supports. false if neither of these conditions is the case, or if o is
|
||||
/// null, or if the current Type is an open generic type (that is,
|
||||
/// ContainsGenericParameters returns true).</returns>
|
||||
public static bool IsInstanceOfType(this Type type, object o)
|
||||
{
|
||||
return o != null && type.IsAssignableFrom(o.GetType());
|
||||
}
|
||||
|
||||
|
||||
internal static bool ImplementInterface(this Type type, Type ifaceType)
|
||||
{
|
||||
while (type != null)
|
||||
{
|
||||
Type[] interfaces = type.GetTypeInfo().ImplementedInterfaces.ToArray(); // .GetInterfaces();
|
||||
if (interfaces != null)
|
||||
{
|
||||
for (int i = 0; i < interfaces.Length; i++)
|
||||
{
|
||||
if (interfaces[i] == ifaceType || (interfaces[i] != null && interfaces[i].ImplementInterface(ifaceType)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
type = type.GetTypeInfo().BaseType;
|
||||
// type = type.BaseType;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static bool IsAssignableFrom(this Type type, Type c)
|
||||
{
|
||||
if (c == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (type == c)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//RuntimeType runtimeType = type.UnderlyingSystemType as RuntimeType;
|
||||
//if (runtimeType != null)
|
||||
//{
|
||||
// return runtimeType.IsAssignableFrom(c);
|
||||
//}
|
||||
|
||||
|
||||
//if (c.IsSubclassOf(type))
|
||||
if (c.GetTypeInfo().IsSubclassOf(c))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//if (type.IsInterface)
|
||||
if (type.GetTypeInfo().IsInterface)
|
||||
{
|
||||
return c.ImplementInterface(type);
|
||||
}
|
||||
|
||||
|
||||
if (type.IsGenericParameter)
|
||||
{
|
||||
Type[] genericParameterConstraints = type.GetTypeInfo().GetGenericParameterConstraints();
|
||||
for (int i = 0; i < genericParameterConstraints.Length; i++)
|
||||
{
|
||||
if (!genericParameterConstraints[i].IsAssignableFrom(c))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsEnum(this Type type)
|
||||
{
|
||||
return type.GetTypeInfo().IsEnum;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/ReflectionHelpers.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/ReflectionHelpers.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8809bc3d6c6b400189a506a614ab811
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/BestHTTP/SecureProtocol/asn1.meta
Normal file
8
Assets/BestHTTP/SecureProtocol/asn1.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e82bfa3d7f9554965834febd9183c55e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/BestHTTP/SecureProtocol/asn1/ASN1Generator.cs
Normal file
30
Assets/BestHTTP/SecureProtocol/asn1/ASN1Generator.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public abstract class Asn1Generator
|
||||
{
|
||||
private Stream _out;
|
||||
|
||||
protected Asn1Generator(
|
||||
Stream outStream)
|
||||
{
|
||||
_out = outStream;
|
||||
}
|
||||
|
||||
protected Stream Out
|
||||
{
|
||||
get { return _out; }
|
||||
}
|
||||
|
||||
public abstract void AddObject(Asn1Encodable obj);
|
||||
|
||||
public abstract Stream GetRawOutputStream();
|
||||
|
||||
public abstract void Close();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1Generator.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1Generator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f61b28da807554faa8ece27cbf5f1cd8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/BestHTTP/SecureProtocol/asn1/ASN1OctetStringParser.cs
Normal file
13
Assets/BestHTTP/SecureProtocol/asn1/ASN1OctetStringParser.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public interface Asn1OctetStringParser
|
||||
: IAsn1Convertible
|
||||
{
|
||||
Stream GetOctetStream();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92c88ef3211aa4b20a978eeb60e139c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1SequenceParser.cs
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1SequenceParser.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public interface Asn1SequenceParser
|
||||
: IAsn1Convertible
|
||||
{
|
||||
IAsn1Convertible ReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ac5f855dafce47359f20ba9e8a9a602
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1SetParser.cs
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1SetParser.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public interface Asn1SetParser
|
||||
: IAsn1Convertible
|
||||
{
|
||||
IAsn1Convertible ReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1SetParser.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1SetParser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f30ef4f908a364cbd86c07f07f63e800
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
237
Assets/BestHTTP/SecureProtocol/asn1/ASN1StreamParser.cs
Normal file
237
Assets/BestHTTP/SecureProtocol/asn1/ASN1StreamParser.cs
Normal file
@@ -0,0 +1,237 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class Asn1StreamParser
|
||||
{
|
||||
private readonly Stream _in;
|
||||
private readonly int _limit;
|
||||
|
||||
private readonly byte[][] tmpBuffers;
|
||||
|
||||
public Asn1StreamParser(
|
||||
Stream inStream)
|
||||
: this(inStream, Asn1InputStream.FindLimit(inStream))
|
||||
{
|
||||
}
|
||||
|
||||
public Asn1StreamParser(
|
||||
Stream inStream,
|
||||
int limit)
|
||||
{
|
||||
if (!inStream.CanRead)
|
||||
throw new ArgumentException("Expected stream to be readable", "inStream");
|
||||
|
||||
this._in = inStream;
|
||||
this._limit = limit;
|
||||
this.tmpBuffers = new byte[16][];
|
||||
}
|
||||
|
||||
public Asn1StreamParser(
|
||||
byte[] encoding)
|
||||
: this(new MemoryStream(encoding, false), encoding.Length)
|
||||
{
|
||||
}
|
||||
|
||||
internal IAsn1Convertible ReadIndef(int tagValue)
|
||||
{
|
||||
// Note: INDEF => CONSTRUCTED
|
||||
|
||||
// TODO There are other tags that may be constructed (e.g. BIT_STRING)
|
||||
switch (tagValue)
|
||||
{
|
||||
case Asn1Tags.External:
|
||||
return new DerExternalParser(this);
|
||||
case Asn1Tags.OctetString:
|
||||
return new BerOctetStringParser(this);
|
||||
case Asn1Tags.Sequence:
|
||||
return new BerSequenceParser(this);
|
||||
case Asn1Tags.Set:
|
||||
return new BerSetParser(this);
|
||||
default:
|
||||
throw new Asn1Exception("unknown BER object encountered: 0x" + tagValue.ToString("X"));
|
||||
}
|
||||
}
|
||||
|
||||
internal IAsn1Convertible ReadImplicit(bool constructed, int tag)
|
||||
{
|
||||
if (_in is IndefiniteLengthInputStream)
|
||||
{
|
||||
if (!constructed)
|
||||
throw new IOException("indefinite length primitive encoding encountered");
|
||||
|
||||
return ReadIndef(tag);
|
||||
}
|
||||
|
||||
if (constructed)
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
case Asn1Tags.Set:
|
||||
return new DerSetParser(this);
|
||||
case Asn1Tags.Sequence:
|
||||
return new DerSequenceParser(this);
|
||||
case Asn1Tags.OctetString:
|
||||
return new BerOctetStringParser(this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
case Asn1Tags.Set:
|
||||
throw new Asn1Exception("sequences must use constructed encoding (see X.690 8.9.1/8.10.1)");
|
||||
case Asn1Tags.Sequence:
|
||||
throw new Asn1Exception("sets must use constructed encoding (see X.690 8.11.1/8.12.1)");
|
||||
case Asn1Tags.OctetString:
|
||||
return new DerOctetStringParser((DefiniteLengthInputStream)_in);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Asn1Exception("implicit tagging not implemented");
|
||||
}
|
||||
|
||||
internal Asn1Object ReadTaggedObject(bool constructed, int tag)
|
||||
{
|
||||
if (!constructed)
|
||||
{
|
||||
// Note: !CONSTRUCTED => IMPLICIT
|
||||
DefiniteLengthInputStream defIn = (DefiniteLengthInputStream)_in;
|
||||
return new DerTaggedObject(false, tag, new DerOctetString(defIn.ToArray()));
|
||||
}
|
||||
|
||||
Asn1EncodableVector v = ReadVector();
|
||||
|
||||
if (_in is IndefiniteLengthInputStream)
|
||||
{
|
||||
return v.Count == 1
|
||||
? new BerTaggedObject(true, tag, v[0])
|
||||
: new BerTaggedObject(false, tag, BerSequence.FromVector(v));
|
||||
}
|
||||
|
||||
return v.Count == 1
|
||||
? new DerTaggedObject(true, tag, v[0])
|
||||
: new DerTaggedObject(false, tag, DerSequence.FromVector(v));
|
||||
}
|
||||
|
||||
public virtual IAsn1Convertible ReadObject()
|
||||
{
|
||||
int tag = _in.ReadByte();
|
||||
if (tag == -1)
|
||||
return null;
|
||||
|
||||
// turn of looking for "00" while we resolve the tag
|
||||
Set00Check(false);
|
||||
|
||||
//
|
||||
// calculate tag number
|
||||
//
|
||||
int tagNo = Asn1InputStream.ReadTagNumber(_in, tag);
|
||||
|
||||
bool isConstructed = (tag & Asn1Tags.Constructed) != 0;
|
||||
|
||||
//
|
||||
// calculate length
|
||||
//
|
||||
int length = Asn1InputStream.ReadLength(_in, _limit);
|
||||
|
||||
if (length < 0) // indefinite length method
|
||||
{
|
||||
if (!isConstructed)
|
||||
throw new IOException("indefinite length primitive encoding encountered");
|
||||
|
||||
IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in, _limit);
|
||||
Asn1StreamParser sp = new Asn1StreamParser(indIn, _limit);
|
||||
|
||||
if ((tag & Asn1Tags.Application) != 0)
|
||||
{
|
||||
return new BerApplicationSpecificParser(tagNo, sp);
|
||||
}
|
||||
|
||||
if ((tag & Asn1Tags.Tagged) != 0)
|
||||
{
|
||||
return new BerTaggedObjectParser(true, tagNo, sp);
|
||||
}
|
||||
|
||||
return sp.ReadIndef(tagNo);
|
||||
}
|
||||
else
|
||||
{
|
||||
DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(_in, length);
|
||||
|
||||
if ((tag & Asn1Tags.Application) != 0)
|
||||
{
|
||||
return new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray());
|
||||
}
|
||||
|
||||
if ((tag & Asn1Tags.Tagged) != 0)
|
||||
{
|
||||
return new BerTaggedObjectParser(isConstructed, tagNo, new Asn1StreamParser(defIn));
|
||||
}
|
||||
|
||||
if (isConstructed)
|
||||
{
|
||||
// TODO There are other tags that may be constructed (e.g. BitString)
|
||||
switch (tagNo)
|
||||
{
|
||||
case Asn1Tags.OctetString:
|
||||
//
|
||||
// yes, people actually do this...
|
||||
//
|
||||
return new BerOctetStringParser(new Asn1StreamParser(defIn));
|
||||
case Asn1Tags.Sequence:
|
||||
return new DerSequenceParser(new Asn1StreamParser(defIn));
|
||||
case Asn1Tags.Set:
|
||||
return new DerSetParser(new Asn1StreamParser(defIn));
|
||||
case Asn1Tags.External:
|
||||
return new DerExternalParser(new Asn1StreamParser(defIn));
|
||||
default:
|
||||
throw new IOException("unknown tag " + tagNo + " encountered");
|
||||
}
|
||||
}
|
||||
|
||||
// Some primitive encodings can be handled by parsers too...
|
||||
switch (tagNo)
|
||||
{
|
||||
case Asn1Tags.OctetString:
|
||||
return new DerOctetStringParser(defIn);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Asn1InputStream.CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
throw new Asn1Exception("corrupted stream detected", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Set00Check(
|
||||
bool enabled)
|
||||
{
|
||||
if (_in is IndefiniteLengthInputStream)
|
||||
{
|
||||
((IndefiniteLengthInputStream) _in).SetEofOn00(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
internal Asn1EncodableVector ReadVector()
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector();
|
||||
|
||||
IAsn1Convertible obj;
|
||||
while ((obj = ReadObject()) != null)
|
||||
{
|
||||
v.Add(obj.ToAsn1Object());
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1StreamParser.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/ASN1StreamParser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60e992105d6c640059e17c85b9ea5b98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public interface Asn1TaggedObjectParser
|
||||
: IAsn1Convertible
|
||||
{
|
||||
int TagNo { get; }
|
||||
|
||||
IAsn1Convertible GetObjectParser(int tag, bool isExplicit);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6339ddf5b72845e992e0cb28d98e814
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
81
Assets/BestHTTP/SecureProtocol/asn1/Asn1Encodable.cs
Normal file
81
Assets/BestHTTP/SecureProtocol/asn1/Asn1Encodable.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public abstract class Asn1Encodable
|
||||
: IAsn1Convertible
|
||||
{
|
||||
public const string Der = "DER";
|
||||
public const string Ber = "BER";
|
||||
|
||||
public byte[] GetEncoded()
|
||||
{
|
||||
MemoryStream bOut = new MemoryStream();
|
||||
Asn1OutputStream aOut = new Asn1OutputStream(bOut);
|
||||
|
||||
aOut.WriteObject(this);
|
||||
|
||||
return bOut.ToArray();
|
||||
}
|
||||
|
||||
public byte[] GetEncoded(
|
||||
string encoding)
|
||||
{
|
||||
if (encoding.Equals(Der))
|
||||
{
|
||||
MemoryStream bOut = new MemoryStream();
|
||||
DerOutputStream dOut = new DerOutputStream(bOut);
|
||||
|
||||
dOut.WriteObject(this);
|
||||
|
||||
return bOut.ToArray();
|
||||
}
|
||||
|
||||
return GetEncoded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DER encoding of the object, null if the DER encoding can not be made.
|
||||
*
|
||||
* @return a DER byte array, null otherwise.
|
||||
*/
|
||||
public byte[] GetDerEncoded()
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetEncoded(Der);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed override int GetHashCode()
|
||||
{
|
||||
return ToAsn1Object().CallAsn1GetHashCode();
|
||||
}
|
||||
|
||||
public sealed override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
IAsn1Convertible other = obj as IAsn1Convertible;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
Asn1Object o1 = ToAsn1Object();
|
||||
Asn1Object o2 = other.ToAsn1Object();
|
||||
|
||||
return o1 == o2 || o1.CallAsn1Equals(o2);
|
||||
}
|
||||
|
||||
public abstract Asn1Object ToAsn1Object();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Encodable.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Encodable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72e76c6f100de4f009c34dbc283f2c5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
96
Assets/BestHTTP/SecureProtocol/asn1/Asn1EncodableVector.cs
Normal file
96
Assets/BestHTTP/SecureProtocol/asn1/Asn1EncodableVector.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class Asn1EncodableVector
|
||||
: IEnumerable
|
||||
{
|
||||
private IList v = Platform.CreateArrayList();
|
||||
|
||||
public static Asn1EncodableVector FromEnumerable(
|
||||
IEnumerable e)
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector();
|
||||
foreach (Asn1Encodable obj in e)
|
||||
{
|
||||
v.Add(obj);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
// public Asn1EncodableVector()
|
||||
// {
|
||||
// }
|
||||
|
||||
public Asn1EncodableVector(
|
||||
params Asn1Encodable[] v)
|
||||
{
|
||||
Add(v);
|
||||
}
|
||||
|
||||
// public void Add(
|
||||
// Asn1Encodable obj)
|
||||
// {
|
||||
// v.Add(obj);
|
||||
// }
|
||||
|
||||
public void Add(
|
||||
params Asn1Encodable[] objs)
|
||||
{
|
||||
foreach (Asn1Encodable obj in objs)
|
||||
{
|
||||
v.Add(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOptional(
|
||||
params Asn1Encodable[] objs)
|
||||
{
|
||||
if (objs != null)
|
||||
{
|
||||
foreach (Asn1Encodable obj in objs)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
v.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Asn1Encodable this[
|
||||
int index]
|
||||
{
|
||||
get { return (Asn1Encodable) v[index]; }
|
||||
}
|
||||
|
||||
[Obsolete("Use 'object[index]' syntax instead")]
|
||||
public Asn1Encodable Get(
|
||||
int index)
|
||||
{
|
||||
return this[index];
|
||||
}
|
||||
|
||||
[Obsolete("Use 'Count' property instead")]
|
||||
public int Size
|
||||
{
|
||||
get { return v.Count; }
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return v.Count; }
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return v.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5afb2a2504a44c23b00911bac15f34a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/BestHTTP/SecureProtocol/asn1/Asn1Exception.cs
Normal file
33
Assets/BestHTTP/SecureProtocol/asn1/Asn1Exception.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
#if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || NETFX_CORE || PORTABLE)
|
||||
[Serializable]
|
||||
#endif
|
||||
public class Asn1Exception
|
||||
: IOException
|
||||
{
|
||||
public Asn1Exception()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public Asn1Exception(
|
||||
string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public Asn1Exception(
|
||||
string message,
|
||||
Exception exception)
|
||||
: base(message, exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Exception.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Exception.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 256fcf9bccb264163b1100fe3643ef76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
374
Assets/BestHTTP/SecureProtocol/asn1/Asn1InputStream.cs
Normal file
374
Assets/BestHTTP/SecureProtocol/asn1/Asn1InputStream.cs
Normal file
@@ -0,0 +1,374 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
/**
|
||||
* a general purpose ASN.1 decoder - note: this class differs from the
|
||||
* others in that it returns null after it has read the last object in
|
||||
* the stream. If an ASN.1 Null is encountered a Der/BER Null object is
|
||||
* returned.
|
||||
*/
|
||||
public class Asn1InputStream
|
||||
: FilterStream
|
||||
{
|
||||
private readonly int limit;
|
||||
|
||||
private readonly byte[][] tmpBuffers;
|
||||
|
||||
internal static int FindLimit(Stream input)
|
||||
{
|
||||
if (input is LimitedInputStream)
|
||||
{
|
||||
return ((LimitedInputStream)input).GetRemaining();
|
||||
}
|
||||
else if (input is MemoryStream)
|
||||
{
|
||||
MemoryStream mem = (MemoryStream)input;
|
||||
return (int)(mem.Length - mem.Position);
|
||||
}
|
||||
|
||||
return int.MaxValue;
|
||||
}
|
||||
|
||||
public Asn1InputStream(
|
||||
Stream inputStream)
|
||||
: this(inputStream, FindLimit(inputStream))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an ASN1InputStream where no DER object will be longer than limit.
|
||||
*
|
||||
* @param input stream containing ASN.1 encoded data.
|
||||
* @param limit maximum size of a DER encoded object.
|
||||
*/
|
||||
public Asn1InputStream(
|
||||
Stream inputStream,
|
||||
int limit)
|
||||
: base(inputStream)
|
||||
{
|
||||
this.limit = limit;
|
||||
this.tmpBuffers = new byte[16][];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an ASN1InputStream based on the input byte array. The length of DER objects in
|
||||
* the stream is automatically limited to the length of the input array.
|
||||
*
|
||||
* @param input array containing ASN.1 encoded data.
|
||||
*/
|
||||
public Asn1InputStream(
|
||||
byte[] input)
|
||||
: this(new MemoryStream(input, false), input.Length)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* build an object given its tag and the number of bytes to construct it from.
|
||||
*/
|
||||
private Asn1Object BuildObject(
|
||||
int tag,
|
||||
int tagNo,
|
||||
int length)
|
||||
{
|
||||
bool isConstructed = (tag & Asn1Tags.Constructed) != 0;
|
||||
|
||||
DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(this.s, length);
|
||||
|
||||
if ((tag & Asn1Tags.Application) != 0)
|
||||
{
|
||||
return new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray());
|
||||
}
|
||||
|
||||
if ((tag & Asn1Tags.Tagged) != 0)
|
||||
{
|
||||
return new Asn1StreamParser(defIn).ReadTaggedObject(isConstructed, tagNo);
|
||||
}
|
||||
|
||||
if (isConstructed)
|
||||
{
|
||||
// TODO There are other tags that may be constructed (e.g. BitString)
|
||||
switch (tagNo)
|
||||
{
|
||||
case Asn1Tags.OctetString:
|
||||
//
|
||||
// yes, people actually do this...
|
||||
//
|
||||
return new BerOctetString(BuildDerEncodableVector(defIn));
|
||||
case Asn1Tags.Sequence:
|
||||
return CreateDerSequence(defIn);
|
||||
case Asn1Tags.Set:
|
||||
return CreateDerSet(defIn);
|
||||
case Asn1Tags.External:
|
||||
return new DerExternal(BuildDerEncodableVector(defIn));
|
||||
default:
|
||||
throw new IOException("unknown tag " + tagNo + " encountered");
|
||||
}
|
||||
}
|
||||
|
||||
return CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers);
|
||||
}
|
||||
|
||||
internal Asn1EncodableVector BuildEncodableVector()
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector();
|
||||
|
||||
Asn1Object o;
|
||||
while ((o = ReadObject()) != null)
|
||||
{
|
||||
v.Add(o);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
internal virtual Asn1EncodableVector BuildDerEncodableVector(
|
||||
DefiniteLengthInputStream dIn)
|
||||
{
|
||||
return new Asn1InputStream(dIn).BuildEncodableVector();
|
||||
}
|
||||
|
||||
internal virtual DerSequence CreateDerSequence(
|
||||
DefiniteLengthInputStream dIn)
|
||||
{
|
||||
return DerSequence.FromVector(BuildDerEncodableVector(dIn));
|
||||
}
|
||||
|
||||
internal virtual DerSet CreateDerSet(
|
||||
DefiniteLengthInputStream dIn)
|
||||
{
|
||||
return DerSet.FromVector(BuildDerEncodableVector(dIn), false);
|
||||
}
|
||||
|
||||
public Asn1Object ReadObject()
|
||||
{
|
||||
int tag = ReadByte();
|
||||
if (tag <= 0)
|
||||
{
|
||||
if (tag == 0)
|
||||
throw new IOException("unexpected end-of-contents marker");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
// calculate tag number
|
||||
//
|
||||
int tagNo = ReadTagNumber(this.s, tag);
|
||||
|
||||
bool isConstructed = (tag & Asn1Tags.Constructed) != 0;
|
||||
|
||||
//
|
||||
// calculate length
|
||||
//
|
||||
int length = ReadLength(this.s, limit);
|
||||
|
||||
if (length < 0) // indefinite length method
|
||||
{
|
||||
if (!isConstructed)
|
||||
throw new IOException("indefinite length primitive encoding encountered");
|
||||
|
||||
IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(this.s, limit);
|
||||
Asn1StreamParser sp = new Asn1StreamParser(indIn, limit);
|
||||
|
||||
if ((tag & Asn1Tags.Application) != 0)
|
||||
{
|
||||
return new BerApplicationSpecificParser(tagNo, sp).ToAsn1Object();
|
||||
}
|
||||
|
||||
if ((tag & Asn1Tags.Tagged) != 0)
|
||||
{
|
||||
return new BerTaggedObjectParser(true, tagNo, sp).ToAsn1Object();
|
||||
}
|
||||
|
||||
// TODO There are other tags that may be constructed (e.g. BitString)
|
||||
switch (tagNo)
|
||||
{
|
||||
case Asn1Tags.OctetString:
|
||||
return new BerOctetStringParser(sp).ToAsn1Object();
|
||||
case Asn1Tags.Sequence:
|
||||
return new BerSequenceParser(sp).ToAsn1Object();
|
||||
case Asn1Tags.Set:
|
||||
return new BerSetParser(sp).ToAsn1Object();
|
||||
case Asn1Tags.External:
|
||||
return new DerExternalParser(sp).ToAsn1Object();
|
||||
default:
|
||||
throw new IOException("unknown BER object encountered");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
return BuildObject(tag, tagNo, length);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
throw new Asn1Exception("corrupted stream detected", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static int ReadTagNumber(
|
||||
Stream s,
|
||||
int tag)
|
||||
{
|
||||
int tagNo = tag & 0x1f;
|
||||
|
||||
//
|
||||
// with tagged object tag number is bottom 5 bits, or stored at the start of the content
|
||||
//
|
||||
if (tagNo == 0x1f)
|
||||
{
|
||||
tagNo = 0;
|
||||
|
||||
int b = s.ReadByte();
|
||||
|
||||
// X.690-0207 8.1.2.4.2
|
||||
// "c) bits 7 to 1 of the first subsequent octet shall not all be zero."
|
||||
if ((b & 0x7f) == 0) // Note: -1 will pass
|
||||
{
|
||||
throw new IOException("Corrupted stream - invalid high tag number found");
|
||||
}
|
||||
|
||||
while ((b >= 0) && ((b & 0x80) != 0))
|
||||
{
|
||||
tagNo |= (b & 0x7f);
|
||||
tagNo <<= 7;
|
||||
b = s.ReadByte();
|
||||
}
|
||||
|
||||
if (b < 0)
|
||||
throw new EndOfStreamException("EOF found inside tag value.");
|
||||
|
||||
tagNo |= (b & 0x7f);
|
||||
}
|
||||
|
||||
return tagNo;
|
||||
}
|
||||
|
||||
internal static int ReadLength(
|
||||
Stream s,
|
||||
int limit)
|
||||
{
|
||||
int length = s.ReadByte();
|
||||
if (length < 0)
|
||||
throw new EndOfStreamException("EOF found when length expected");
|
||||
|
||||
if (length == 0x80)
|
||||
return -1; // indefinite-length encoding
|
||||
|
||||
if (length > 127)
|
||||
{
|
||||
int size = length & 0x7f;
|
||||
|
||||
// Note: The invalid long form "0xff" (see X.690 8.1.3.5c) will be caught here
|
||||
if (size > 4)
|
||||
throw new IOException("DER length more than 4 bytes: " + size);
|
||||
|
||||
length = 0;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
int next = s.ReadByte();
|
||||
|
||||
if (next < 0)
|
||||
throw new EndOfStreamException("EOF found reading length");
|
||||
|
||||
length = (length << 8) + next;
|
||||
}
|
||||
|
||||
if (length < 0)
|
||||
throw new IOException("Corrupted stream - negative length found");
|
||||
|
||||
if (length >= limit) // after all we must have read at least 1 byte
|
||||
throw new IOException("Corrupted stream - out of bounds length found");
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
internal static byte[] GetBuffer(DefiniteLengthInputStream defIn, byte[][] tmpBuffers)
|
||||
{
|
||||
int len = defIn.GetRemaining();
|
||||
if (len >= tmpBuffers.Length)
|
||||
{
|
||||
return defIn.ToArray();
|
||||
}
|
||||
|
||||
byte[] buf = tmpBuffers[len];
|
||||
if (buf == null)
|
||||
{
|
||||
buf = tmpBuffers[len] = new byte[len];
|
||||
}
|
||||
|
||||
defIn.ReadAllIntoByteArray(buf);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
internal static Asn1Object CreatePrimitiveDerObject(
|
||||
int tagNo,
|
||||
DefiniteLengthInputStream defIn,
|
||||
byte[][] tmpBuffers)
|
||||
{
|
||||
switch (tagNo)
|
||||
{
|
||||
case Asn1Tags.Boolean:
|
||||
return DerBoolean.FromOctetString(GetBuffer(defIn, tmpBuffers));
|
||||
case Asn1Tags.Enumerated:
|
||||
return DerEnumerated.FromOctetString(GetBuffer(defIn, tmpBuffers));
|
||||
case Asn1Tags.ObjectIdentifier:
|
||||
return DerObjectIdentifier.FromOctetString(GetBuffer(defIn, tmpBuffers));
|
||||
}
|
||||
|
||||
byte[] bytes = defIn.ToArray();
|
||||
|
||||
switch (tagNo)
|
||||
{
|
||||
case Asn1Tags.BitString:
|
||||
return DerBitString.FromAsn1Octets(bytes);
|
||||
case Asn1Tags.BmpString:
|
||||
return new DerBmpString(bytes);
|
||||
case Asn1Tags.GeneralizedTime:
|
||||
return new DerGeneralizedTime(bytes);
|
||||
case Asn1Tags.GeneralString:
|
||||
return new DerGeneralString(bytes);
|
||||
case Asn1Tags.GraphicString:
|
||||
return new DerGraphicString(bytes);
|
||||
case Asn1Tags.IA5String:
|
||||
return new DerIA5String(bytes);
|
||||
case Asn1Tags.Integer:
|
||||
return new DerInteger(bytes);
|
||||
case Asn1Tags.Null:
|
||||
return DerNull.Instance; // actual content is ignored (enforce 0 length?)
|
||||
case Asn1Tags.NumericString:
|
||||
return new DerNumericString(bytes);
|
||||
case Asn1Tags.OctetString:
|
||||
return new DerOctetString(bytes);
|
||||
case Asn1Tags.PrintableString:
|
||||
return new DerPrintableString(bytes);
|
||||
case Asn1Tags.T61String:
|
||||
return new DerT61String(bytes);
|
||||
case Asn1Tags.UniversalString:
|
||||
return new DerUniversalString(bytes);
|
||||
case Asn1Tags.UtcTime:
|
||||
return new DerUtcTime(bytes);
|
||||
case Asn1Tags.Utf8String:
|
||||
return new DerUtf8String(bytes);
|
||||
case Asn1Tags.VideotexString:
|
||||
return new DerVideotexString(bytes);
|
||||
case Asn1Tags.VisibleString:
|
||||
return new DerVisibleString(bytes);
|
||||
default:
|
||||
throw new IOException("unknown tag " + tagNo + " encountered");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1InputStream.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1InputStream.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26d814f7d5cac433eab93f8b16f90721
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/BestHTTP/SecureProtocol/asn1/Asn1Null.cs
Normal file
21
Assets/BestHTTP/SecureProtocol/asn1/Asn1Null.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
/**
|
||||
* A Null object.
|
||||
*/
|
||||
public abstract class Asn1Null
|
||||
: Asn1Object
|
||||
{
|
||||
internal Asn1Null()
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "NULL";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Null.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Null.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8549d49b2af694846b87e5f7803e6641
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
Assets/BestHTTP/SecureProtocol/asn1/Asn1Object.cs
Normal file
71
Assets/BestHTTP/SecureProtocol/asn1/Asn1Object.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public abstract class Asn1Object
|
||||
: Asn1Encodable
|
||||
{
|
||||
/// <summary>Create a base ASN.1 object from a byte array.</summary>
|
||||
/// <param name="data">The byte array to parse.</param>
|
||||
/// <returns>The base ASN.1 object represented by the byte array.</returns>
|
||||
/// <exception cref="IOException">If there is a problem parsing the data.</exception>
|
||||
public static Asn1Object FromByteArray(
|
||||
byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
MemoryStream input = new MemoryStream(data, false);
|
||||
Asn1InputStream asn1 = new Asn1InputStream(input, data.Length);
|
||||
Asn1Object result = asn1.ReadObject();
|
||||
if (input.Position != input.Length)
|
||||
throw new IOException("extra data found after object");
|
||||
return result;
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
throw new IOException("cannot recognise object in byte array");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Read a base ASN.1 object from a stream.</summary>
|
||||
/// <param name="inStr">The stream to parse.</param>
|
||||
/// <returns>The base ASN.1 object represented by the byte array.</returns>
|
||||
/// <exception cref="IOException">If there is a problem parsing the data.</exception>
|
||||
public static Asn1Object FromStream(
|
||||
Stream inStr)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Asn1InputStream(inStr).ReadObject();
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
throw new IOException("cannot recognise object in stream");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
internal abstract void Encode(DerOutputStream derOut);
|
||||
|
||||
protected abstract bool Asn1Equals(Asn1Object asn1Object);
|
||||
protected abstract int Asn1GetHashCode();
|
||||
|
||||
internal bool CallAsn1Equals(Asn1Object obj)
|
||||
{
|
||||
return Asn1Equals(obj);
|
||||
}
|
||||
|
||||
internal int CallAsn1GetHashCode()
|
||||
{
|
||||
return Asn1GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Object.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Object.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9604cd2989b1c4bbd8c830f2ca5c754a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
122
Assets/BestHTTP/SecureProtocol/asn1/Asn1OctetString.cs
Normal file
122
Assets/BestHTTP/SecureProtocol/asn1/Asn1OctetString.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Encoders;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public abstract class Asn1OctetString
|
||||
: Asn1Object, Asn1OctetStringParser
|
||||
{
|
||||
internal byte[] str;
|
||||
|
||||
/**
|
||||
* return an Octet string from a tagged object.
|
||||
*
|
||||
* @param obj the tagged object holding the object we want.
|
||||
* @param explicitly true if the object is meant to be explicitly
|
||||
* tagged false otherwise.
|
||||
* @exception ArgumentException if the tagged object cannot
|
||||
* be converted.
|
||||
*/
|
||||
public static Asn1OctetString GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool isExplicit)
|
||||
{
|
||||
Asn1Object o = obj.GetObject();
|
||||
|
||||
if (isExplicit || o is Asn1OctetString)
|
||||
{
|
||||
return GetInstance(o);
|
||||
}
|
||||
|
||||
return BerOctetString.FromSequence(Asn1Sequence.GetInstance(o));
|
||||
}
|
||||
|
||||
/**
|
||||
* return an Octet string from the given object.
|
||||
*
|
||||
* @param obj the object we want converted.
|
||||
* @exception ArgumentException if the object cannot be converted.
|
||||
*/
|
||||
public static Asn1OctetString GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is Asn1OctetString)
|
||||
{
|
||||
return (Asn1OctetString)obj;
|
||||
}
|
||||
|
||||
// TODO: this needs to be deleted in V2
|
||||
if (obj is Asn1TaggedObject)
|
||||
return GetInstance(((Asn1TaggedObject)obj).GetObject());
|
||||
|
||||
throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string the octets making up the octet string.
|
||||
*/
|
||||
internal Asn1OctetString(
|
||||
byte[] str)
|
||||
{
|
||||
if (str == null)
|
||||
throw new ArgumentNullException("str");
|
||||
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
internal Asn1OctetString(
|
||||
Asn1Encodable obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.str = obj.GetEncoded(Asn1Encodable.Der);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ArgumentException("Error processing object : " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public Stream GetOctetStream()
|
||||
{
|
||||
return new MemoryStream(str, false);
|
||||
}
|
||||
|
||||
public Asn1OctetStringParser Parser
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public virtual byte[] GetOctets()
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
return Arrays.GetHashCode(GetOctets());
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
DerOctetString other = asn1Object as DerOctetString;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Arrays.AreEqual(GetOctets(), other.GetOctets());
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "#" + Hex.ToHexString(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1OctetString.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1OctetString.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a12c62a29f6e8439ebc5b0d6289eb631
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Assets/BestHTTP/SecureProtocol/asn1/Asn1OutputStream.cs
Normal file
38
Assets/BestHTTP/SecureProtocol/asn1/Asn1OutputStream.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class Asn1OutputStream
|
||||
: DerOutputStream
|
||||
{
|
||||
public Asn1OutputStream(Stream os) : base(os)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Use version taking an Asn1Encodable arg instead")]
|
||||
public override void WriteObject(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
WriteNull();
|
||||
}
|
||||
else if (obj is Asn1Object)
|
||||
{
|
||||
((Asn1Object)obj).Encode(this);
|
||||
}
|
||||
else if (obj is Asn1Encodable)
|
||||
{
|
||||
((Asn1Encodable)obj).ToAsn1Object().Encode(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("object not Asn1Encodable");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1OutputStream.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1OutputStream.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 140c17ffcaf9d4f6d89c294b6cb97136
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/BestHTTP/SecureProtocol/asn1/Asn1ParsingException.cs
Normal file
32
Assets/BestHTTP/SecureProtocol/asn1/Asn1ParsingException.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
#if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || NETFX_CORE || PORTABLE)
|
||||
[Serializable]
|
||||
#endif
|
||||
public class Asn1ParsingException
|
||||
: InvalidOperationException
|
||||
{
|
||||
public Asn1ParsingException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public Asn1ParsingException(
|
||||
string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public Asn1ParsingException(
|
||||
string message,
|
||||
Exception exception)
|
||||
: base(message, exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68405cc3e0a52454e8041a9d9e158eed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
271
Assets/BestHTTP/SecureProtocol/asn1/Asn1Sequence.cs
Normal file
271
Assets/BestHTTP/SecureProtocol/asn1/Asn1Sequence.cs
Normal file
@@ -0,0 +1,271 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public abstract class Asn1Sequence
|
||||
: Asn1Object, IEnumerable
|
||||
{
|
||||
private readonly IList seq;
|
||||
|
||||
/**
|
||||
* return an Asn1Sequence from the given object.
|
||||
*
|
||||
* @param obj the object we want converted.
|
||||
* @exception ArgumentException if the object cannot be converted.
|
||||
*/
|
||||
public static Asn1Sequence GetInstance(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null || obj is Asn1Sequence)
|
||||
{
|
||||
return (Asn1Sequence)obj;
|
||||
}
|
||||
else if (obj is Asn1SequenceParser)
|
||||
{
|
||||
return Asn1Sequence.GetInstance(((Asn1SequenceParser)obj).ToAsn1Object());
|
||||
}
|
||||
else if (obj is byte[])
|
||||
{
|
||||
try
|
||||
{
|
||||
return Asn1Sequence.GetInstance(FromByteArray((byte[])obj));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ArgumentException("failed to construct sequence from byte[]: " + e.Message);
|
||||
}
|
||||
}
|
||||
else if (obj is Asn1Encodable)
|
||||
{
|
||||
Asn1Object primitive = ((Asn1Encodable)obj).ToAsn1Object();
|
||||
|
||||
if (primitive is Asn1Sequence)
|
||||
{
|
||||
return (Asn1Sequence)primitive;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an ASN1 sequence from a tagged object. There is a special
|
||||
* case here, if an object appears to have been explicitly tagged on
|
||||
* reading but we were expecting it to be implicitly tagged in the
|
||||
* normal course of events it indicates that we lost the surrounding
|
||||
* sequence - so we need to add it back (this will happen if the tagged
|
||||
* object is a sequence that contains other sequences). If you are
|
||||
* dealing with implicitly tagged sequences you really <b>should</b>
|
||||
* be using this method.
|
||||
*
|
||||
* @param obj the tagged object.
|
||||
* @param explicitly true if the object is meant to be explicitly tagged,
|
||||
* false otherwise.
|
||||
* @exception ArgumentException if the tagged object cannot
|
||||
* be converted.
|
||||
*/
|
||||
public static Asn1Sequence GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool explicitly)
|
||||
{
|
||||
Asn1Object inner = obj.GetObject();
|
||||
|
||||
if (explicitly)
|
||||
{
|
||||
if (!obj.IsExplicit())
|
||||
throw new ArgumentException("object implicit - explicit expected.");
|
||||
|
||||
return (Asn1Sequence) inner;
|
||||
}
|
||||
|
||||
//
|
||||
// constructed object which appears to be explicitly tagged
|
||||
// when it should be implicit means we have to add the
|
||||
// surrounding sequence.
|
||||
//
|
||||
if (obj.IsExplicit())
|
||||
{
|
||||
if (obj is BerTaggedObject)
|
||||
{
|
||||
return new BerSequence(inner);
|
||||
}
|
||||
|
||||
return new DerSequence(inner);
|
||||
}
|
||||
|
||||
if (inner is Asn1Sequence)
|
||||
{
|
||||
return (Asn1Sequence) inner;
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
protected internal Asn1Sequence(
|
||||
int capacity)
|
||||
{
|
||||
seq = Platform.CreateArrayList(capacity);
|
||||
}
|
||||
|
||||
public virtual IEnumerator GetEnumerator()
|
||||
{
|
||||
return seq.GetEnumerator();
|
||||
}
|
||||
|
||||
[Obsolete("Use GetEnumerator() instead")]
|
||||
public IEnumerator GetObjects()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
private class Asn1SequenceParserImpl
|
||||
: Asn1SequenceParser
|
||||
{
|
||||
private readonly Asn1Sequence outer;
|
||||
private readonly int max;
|
||||
private int index;
|
||||
|
||||
public Asn1SequenceParserImpl(
|
||||
Asn1Sequence outer)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.max = outer.Count;
|
||||
}
|
||||
|
||||
public IAsn1Convertible ReadObject()
|
||||
{
|
||||
if (index == max)
|
||||
return null;
|
||||
|
||||
Asn1Encodable obj = outer[index++];
|
||||
|
||||
if (obj is Asn1Sequence)
|
||||
return ((Asn1Sequence)obj).Parser;
|
||||
|
||||
if (obj is Asn1Set)
|
||||
return ((Asn1Set)obj).Parser;
|
||||
|
||||
// NB: Asn1OctetString implements Asn1OctetStringParser directly
|
||||
// if (obj is Asn1OctetString)
|
||||
// return ((Asn1OctetString)obj).Parser;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
return outer;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Asn1SequenceParser Parser
|
||||
{
|
||||
get { return new Asn1SequenceParserImpl(this); }
|
||||
}
|
||||
|
||||
/**
|
||||
* return the object at the sequence position indicated by index.
|
||||
*
|
||||
* @param index the sequence number (starting at zero) of the object
|
||||
* @return the object at the sequence position indicated by index.
|
||||
*/
|
||||
public virtual Asn1Encodable this[int index]
|
||||
{
|
||||
get { return (Asn1Encodable) seq[index]; }
|
||||
}
|
||||
|
||||
[Obsolete("Use 'object[index]' syntax instead")]
|
||||
public Asn1Encodable GetObjectAt(
|
||||
int index)
|
||||
{
|
||||
return this[index];
|
||||
}
|
||||
|
||||
[Obsolete("Use 'Count' property instead")]
|
||||
public int Size
|
||||
{
|
||||
get { return Count; }
|
||||
}
|
||||
|
||||
public virtual int Count
|
||||
{
|
||||
get { return seq.Count; }
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
int hc = Count;
|
||||
|
||||
foreach (object o in this)
|
||||
{
|
||||
hc *= 17;
|
||||
if (o == null)
|
||||
{
|
||||
hc ^= DerNull.Instance.GetHashCode();
|
||||
}
|
||||
else
|
||||
{
|
||||
hc ^= o.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
return hc;
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
Asn1Sequence other = asn1Object as Asn1Sequence;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
if (Count != other.Count)
|
||||
return false;
|
||||
|
||||
IEnumerator s1 = GetEnumerator();
|
||||
IEnumerator s2 = other.GetEnumerator();
|
||||
|
||||
while (s1.MoveNext() && s2.MoveNext())
|
||||
{
|
||||
Asn1Object o1 = GetCurrent(s1).ToAsn1Object();
|
||||
Asn1Object o2 = GetCurrent(s2).ToAsn1Object();
|
||||
|
||||
if (!o1.Equals(o2))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Asn1Encodable GetCurrent(IEnumerator e)
|
||||
{
|
||||
Asn1Encodable encObj = (Asn1Encodable)e.Current;
|
||||
|
||||
// unfortunately null was allowed as a substitute for DER null
|
||||
if (encObj == null)
|
||||
return DerNull.Instance;
|
||||
|
||||
return encObj;
|
||||
}
|
||||
|
||||
protected internal void AddObject(
|
||||
Asn1Encodable obj)
|
||||
{
|
||||
seq.Add(obj);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return CollectionUtilities.ToString(seq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Sequence.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Sequence.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 783fccef749e8401ab70df7ae0522fa7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
375
Assets/BestHTTP/SecureProtocol/asn1/Asn1Set.cs
Normal file
375
Assets/BestHTTP/SecureProtocol/asn1/Asn1Set.cs
Normal file
@@ -0,0 +1,375 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
#if PORTABLE || NETFX_CORE
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endif
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
abstract public class Asn1Set
|
||||
: Asn1Object, IEnumerable
|
||||
{
|
||||
private readonly IList _set;
|
||||
|
||||
/**
|
||||
* return an ASN1Set from the given object.
|
||||
*
|
||||
* @param obj the object we want converted.
|
||||
* @exception ArgumentException if the object cannot be converted.
|
||||
*/
|
||||
public static Asn1Set GetInstance(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null || obj is Asn1Set)
|
||||
{
|
||||
return (Asn1Set)obj;
|
||||
}
|
||||
else if (obj is Asn1SetParser)
|
||||
{
|
||||
return Asn1Set.GetInstance(((Asn1SetParser)obj).ToAsn1Object());
|
||||
}
|
||||
else if (obj is byte[])
|
||||
{
|
||||
try
|
||||
{
|
||||
return Asn1Set.GetInstance(FromByteArray((byte[])obj));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ArgumentException("failed to construct set from byte[]: " + e.Message);
|
||||
}
|
||||
}
|
||||
else if (obj is Asn1Encodable)
|
||||
{
|
||||
Asn1Object primitive = ((Asn1Encodable)obj).ToAsn1Object();
|
||||
|
||||
if (primitive is Asn1Set)
|
||||
{
|
||||
return (Asn1Set)primitive;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an ASN1 set from a tagged object. There is a special
|
||||
* case here, if an object appears to have been explicitly tagged on
|
||||
* reading but we were expecting it to be implicitly tagged in the
|
||||
* normal course of events it indicates that we lost the surrounding
|
||||
* set - so we need to add it back (this will happen if the tagged
|
||||
* object is a sequence that contains other sequences). If you are
|
||||
* dealing with implicitly tagged sets you really <b>should</b>
|
||||
* be using this method.
|
||||
*
|
||||
* @param obj the tagged object.
|
||||
* @param explicitly true if the object is meant to be explicitly tagged
|
||||
* false otherwise.
|
||||
* @exception ArgumentException if the tagged object cannot
|
||||
* be converted.
|
||||
*/
|
||||
public static Asn1Set GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool explicitly)
|
||||
{
|
||||
Asn1Object inner = obj.GetObject();
|
||||
|
||||
if (explicitly)
|
||||
{
|
||||
if (!obj.IsExplicit())
|
||||
throw new ArgumentException("object implicit - explicit expected.");
|
||||
|
||||
return (Asn1Set) inner;
|
||||
}
|
||||
|
||||
//
|
||||
// constructed object which appears to be explicitly tagged
|
||||
// and it's really implicit means we have to add the
|
||||
// surrounding sequence.
|
||||
//
|
||||
if (obj.IsExplicit())
|
||||
{
|
||||
return new DerSet(inner);
|
||||
}
|
||||
|
||||
if (inner is Asn1Set)
|
||||
{
|
||||
return (Asn1Set) inner;
|
||||
}
|
||||
|
||||
//
|
||||
// in this case the parser returns a sequence, convert it
|
||||
// into a set.
|
||||
//
|
||||
if (inner is Asn1Sequence)
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector();
|
||||
Asn1Sequence s = (Asn1Sequence) inner;
|
||||
|
||||
foreach (Asn1Encodable ae in s)
|
||||
{
|
||||
v.Add(ae);
|
||||
}
|
||||
|
||||
// TODO Should be able to construct set directly from sequence?
|
||||
return new DerSet(v, false);
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
protected internal Asn1Set(
|
||||
int capacity)
|
||||
{
|
||||
_set = Platform.CreateArrayList(capacity);
|
||||
}
|
||||
|
||||
public virtual IEnumerator GetEnumerator()
|
||||
{
|
||||
return _set.GetEnumerator();
|
||||
}
|
||||
|
||||
[Obsolete("Use GetEnumerator() instead")]
|
||||
public IEnumerator GetObjects()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* return the object at the set position indicated by index.
|
||||
*
|
||||
* @param index the set number (starting at zero) of the object
|
||||
* @return the object at the set position indicated by index.
|
||||
*/
|
||||
public virtual Asn1Encodable this[int index]
|
||||
{
|
||||
get { return (Asn1Encodable) _set[index]; }
|
||||
}
|
||||
|
||||
[Obsolete("Use 'object[index]' syntax instead")]
|
||||
public Asn1Encodable GetObjectAt(
|
||||
int index)
|
||||
{
|
||||
return this[index];
|
||||
}
|
||||
|
||||
[Obsolete("Use 'Count' property instead")]
|
||||
public int Size
|
||||
{
|
||||
get { return Count; }
|
||||
}
|
||||
|
||||
public virtual int Count
|
||||
{
|
||||
get { return _set.Count; }
|
||||
}
|
||||
|
||||
public virtual Asn1Encodable[] ToArray()
|
||||
{
|
||||
Asn1Encodable[] values = new Asn1Encodable[this.Count];
|
||||
for (int i = 0; i < this.Count; ++i)
|
||||
{
|
||||
values[i] = this[i];
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private class Asn1SetParserImpl
|
||||
: Asn1SetParser
|
||||
{
|
||||
private readonly Asn1Set outer;
|
||||
private readonly int max;
|
||||
private int index;
|
||||
|
||||
public Asn1SetParserImpl(
|
||||
Asn1Set outer)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.max = outer.Count;
|
||||
}
|
||||
|
||||
public IAsn1Convertible ReadObject()
|
||||
{
|
||||
if (index == max)
|
||||
return null;
|
||||
|
||||
Asn1Encodable obj = outer[index++];
|
||||
if (obj is Asn1Sequence)
|
||||
return ((Asn1Sequence)obj).Parser;
|
||||
|
||||
if (obj is Asn1Set)
|
||||
return ((Asn1Set)obj).Parser;
|
||||
|
||||
// NB: Asn1OctetString implements Asn1OctetStringParser directly
|
||||
// if (obj is Asn1OctetString)
|
||||
// return ((Asn1OctetString)obj).Parser;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public virtual Asn1Object ToAsn1Object()
|
||||
{
|
||||
return outer;
|
||||
}
|
||||
}
|
||||
|
||||
public Asn1SetParser Parser
|
||||
{
|
||||
get { return new Asn1SetParserImpl(this); }
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
int hc = Count;
|
||||
|
||||
foreach (object o in this)
|
||||
{
|
||||
hc *= 17;
|
||||
if (o == null)
|
||||
{
|
||||
hc ^= DerNull.Instance.GetHashCode();
|
||||
}
|
||||
else
|
||||
{
|
||||
hc ^= o.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
return hc;
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
Asn1Set other = asn1Object as Asn1Set;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
if (Count != other.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IEnumerator s1 = GetEnumerator();
|
||||
IEnumerator s2 = other.GetEnumerator();
|
||||
|
||||
while (s1.MoveNext() && s2.MoveNext())
|
||||
{
|
||||
Asn1Object o1 = GetCurrent(s1).ToAsn1Object();
|
||||
Asn1Object o2 = GetCurrent(s2).ToAsn1Object();
|
||||
|
||||
if (!o1.Equals(o2))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Asn1Encodable GetCurrent(IEnumerator e)
|
||||
{
|
||||
Asn1Encodable encObj = (Asn1Encodable)e.Current;
|
||||
|
||||
// unfortunately null was allowed as a substitute for DER null
|
||||
if (encObj == null)
|
||||
return DerNull.Instance;
|
||||
|
||||
return encObj;
|
||||
}
|
||||
|
||||
protected internal void Sort()
|
||||
{
|
||||
if (_set.Count < 2)
|
||||
return;
|
||||
|
||||
#if PORTABLE || NETFX_CORE
|
||||
var sorted = _set.Cast<Asn1Encodable>()
|
||||
.Select(a => new { Item = a, Key = a.GetEncoded(Asn1Encodable.Der) })
|
||||
.OrderBy(t => t.Key, new DerComparer())
|
||||
.Select(t => t.Item)
|
||||
.ToList();
|
||||
|
||||
for (int i = 0; i < _set.Count; ++i)
|
||||
{
|
||||
_set[i] = sorted[i];
|
||||
}
|
||||
#else
|
||||
Asn1Encodable[] items = new Asn1Encodable[_set.Count];
|
||||
byte[][] keys = new byte[_set.Count][];
|
||||
|
||||
for (int i = 0; i < _set.Count; ++i)
|
||||
{
|
||||
Asn1Encodable item = (Asn1Encodable)_set[i];
|
||||
items[i] = item;
|
||||
keys[i] = item.GetEncoded(Asn1Encodable.Der);
|
||||
}
|
||||
|
||||
Array.Sort(keys, items, new DerComparer());
|
||||
|
||||
for (int i = 0; i < _set.Count; ++i)
|
||||
{
|
||||
_set[i] = items[i];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
protected internal void AddObject(Asn1Encodable obj)
|
||||
{
|
||||
_set.Add(obj);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return CollectionUtilities.ToString(_set);
|
||||
}
|
||||
|
||||
#if PORTABLE || NETFX_CORE
|
||||
private class DerComparer
|
||||
: IComparer<byte[]>
|
||||
{
|
||||
public int Compare(byte[] x, byte[] y)
|
||||
{
|
||||
byte[] a = x, b = y;
|
||||
#else
|
||||
private class DerComparer
|
||||
: IComparer
|
||||
{
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
byte[] a = (byte[])x, b = (byte[])y;
|
||||
#endif
|
||||
int len = System.Math.Min(a.Length, b.Length);
|
||||
for (int i = 0; i != len; ++i)
|
||||
{
|
||||
byte ai = a[i], bi = b[i];
|
||||
if (ai != bi)
|
||||
return ai < bi ? -1 : 1;
|
||||
}
|
||||
if (a.Length > b.Length)
|
||||
return AllZeroesFrom(a, len) ? 0 : 1;
|
||||
if (a.Length < b.Length)
|
||||
return AllZeroesFrom(b, len) ? 0 : -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private bool AllZeroesFrom(byte[] bs, int pos)
|
||||
{
|
||||
while (pos < bs.Length)
|
||||
{
|
||||
if (bs[pos++] != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Set.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Set.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 462883479974e4d77971fe4c4d5100ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
191
Assets/BestHTTP/SecureProtocol/asn1/Asn1TaggedObject.cs
Normal file
191
Assets/BestHTTP/SecureProtocol/asn1/Asn1TaggedObject.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
/**
|
||||
* ASN.1 TaggedObject - in ASN.1 notation this is any object preceded by
|
||||
* a [n] where n is some number - these are assumed to follow the construction
|
||||
* rules (as with sequences).
|
||||
*/
|
||||
public abstract class Asn1TaggedObject
|
||||
: Asn1Object, Asn1TaggedObjectParser
|
||||
{
|
||||
internal static bool IsConstructed(bool isExplicit, Asn1Object obj)
|
||||
{
|
||||
if (isExplicit || obj is Asn1Sequence || obj is Asn1Set)
|
||||
return true;
|
||||
Asn1TaggedObject tagged = obj as Asn1TaggedObject;
|
||||
if (tagged == null)
|
||||
return false;
|
||||
return IsConstructed(tagged.IsExplicit(), tagged.GetObject());
|
||||
}
|
||||
|
||||
internal int tagNo;
|
||||
// internal bool empty;
|
||||
internal bool explicitly = true;
|
||||
internal Asn1Encodable obj;
|
||||
|
||||
static public Asn1TaggedObject GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool explicitly)
|
||||
{
|
||||
if (explicitly)
|
||||
{
|
||||
return (Asn1TaggedObject) obj.GetObject();
|
||||
}
|
||||
|
||||
throw new ArgumentException("implicitly tagged tagged object");
|
||||
}
|
||||
|
||||
static public Asn1TaggedObject GetInstance(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null || obj is Asn1TaggedObject)
|
||||
{
|
||||
return (Asn1TaggedObject) obj;
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tagNo the tag number for this object.
|
||||
* @param obj the tagged object.
|
||||
*/
|
||||
protected Asn1TaggedObject(
|
||||
int tagNo,
|
||||
Asn1Encodable obj)
|
||||
{
|
||||
this.explicitly = true;
|
||||
this.tagNo = tagNo;
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param explicitly true if the object is explicitly tagged.
|
||||
* @param tagNo the tag number for this object.
|
||||
* @param obj the tagged object.
|
||||
*/
|
||||
protected Asn1TaggedObject(
|
||||
bool explicitly,
|
||||
int tagNo,
|
||||
Asn1Encodable obj)
|
||||
{
|
||||
// IAsn1Choice marker interface 'insists' on explicit tagging
|
||||
this.explicitly = explicitly || (obj is IAsn1Choice);
|
||||
this.tagNo = tagNo;
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
Asn1TaggedObject other = asn1Object as Asn1TaggedObject;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return this.tagNo == other.tagNo
|
||||
// && this.empty == other.empty
|
||||
&& this.explicitly == other.explicitly // TODO Should this be part of equality?
|
||||
&& Platform.Equals(GetObject(), other.GetObject());
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
int code = tagNo.GetHashCode();
|
||||
|
||||
// TODO: actually this is wrong - the problem is that a re-encoded
|
||||
// object may end up with a different hashCode due to implicit
|
||||
// tagging. As implicit tagging is ambiguous if a sequence is involved
|
||||
// it seems the only correct method for both equals and hashCode is to
|
||||
// compare the encodings...
|
||||
// code ^= explicitly.GetHashCode();
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
code ^= obj.GetHashCode();
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
public int TagNo
|
||||
{
|
||||
get { return tagNo; }
|
||||
}
|
||||
|
||||
/**
|
||||
* return whether or not the object may be explicitly tagged.
|
||||
* <p>
|
||||
* Note: if the object has been read from an input stream, the only
|
||||
* time you can be sure if isExplicit is returning the true state of
|
||||
* affairs is if it returns false. An implicitly tagged object may appear
|
||||
* to be explicitly tagged, so you need to understand the context under
|
||||
* which the reading was done as well, see GetObject below.</p>
|
||||
*/
|
||||
public bool IsExplicit()
|
||||
{
|
||||
return explicitly;
|
||||
}
|
||||
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return false; //empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* return whatever was following the tag.
|
||||
* <p>
|
||||
* Note: tagged objects are generally context dependent if you're
|
||||
* trying to extract a tagged object you should be going via the
|
||||
* appropriate GetInstance method.</p>
|
||||
*/
|
||||
public Asn1Object GetObject()
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
return obj.ToAsn1Object();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the object held in this tagged object as a parser assuming it has
|
||||
* the type of the passed in tag. If the object doesn't have a parser
|
||||
* associated with it, the base object is returned.
|
||||
*/
|
||||
public IAsn1Convertible GetObjectParser(
|
||||
int tag,
|
||||
bool isExplicit)
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
case Asn1Tags.Set:
|
||||
return Asn1Set.GetInstance(this, isExplicit).Parser;
|
||||
case Asn1Tags.Sequence:
|
||||
return Asn1Sequence.GetInstance(this, isExplicit).Parser;
|
||||
case Asn1Tags.OctetString:
|
||||
return Asn1OctetString.GetInstance(this, isExplicit).Parser;
|
||||
}
|
||||
|
||||
if (isExplicit)
|
||||
{
|
||||
return GetObject();
|
||||
}
|
||||
|
||||
throw Platform.CreateNotImplementedException("implicit tagging for tag: " + tag);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "[" + tagNo + "]" + obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1TaggedObject.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1TaggedObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39e28e4df8089419bb3dcc331068aab0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/BestHTTP/SecureProtocol/asn1/Asn1Tags.cs
Normal file
39
Assets/BestHTTP/SecureProtocol/asn1/Asn1Tags.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class Asn1Tags
|
||||
{
|
||||
public const int Boolean = 0x01;
|
||||
public const int Integer = 0x02;
|
||||
public const int BitString = 0x03;
|
||||
public const int OctetString = 0x04;
|
||||
public const int Null = 0x05;
|
||||
public const int ObjectIdentifier = 0x06;
|
||||
public const int External = 0x08;
|
||||
public const int Enumerated = 0x0a;
|
||||
public const int Sequence = 0x10;
|
||||
public const int SequenceOf = 0x10; // for completeness
|
||||
public const int Set = 0x11;
|
||||
public const int SetOf = 0x11; // for completeness
|
||||
|
||||
public const int NumericString = 0x12;
|
||||
public const int PrintableString = 0x13;
|
||||
public const int T61String = 0x14;
|
||||
public const int VideotexString = 0x15;
|
||||
public const int IA5String = 0x16;
|
||||
public const int UtcTime = 0x17;
|
||||
public const int GeneralizedTime = 0x18;
|
||||
public const int GraphicString = 0x19;
|
||||
public const int VisibleString = 0x1a;
|
||||
public const int GeneralString = 0x1b;
|
||||
public const int UniversalString = 0x1c;
|
||||
public const int BmpString = 0x1e;
|
||||
public const int Utf8String = 0x0c;
|
||||
|
||||
public const int Constructed = 0x20;
|
||||
public const int Application = 0x40;
|
||||
public const int Tagged = 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Tags.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/Asn1Tags.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38eaca5e6bb434609b4076e926f21883
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/BestHTTP/SecureProtocol/asn1/BERBitString.cs
Normal file
46
Assets/BestHTTP/SecureProtocol/asn1/BERBitString.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerBitString
|
||||
: DerBitString
|
||||
{
|
||||
public BerBitString(byte[] data, int padBits)
|
||||
: base(data, padBits)
|
||||
{
|
||||
}
|
||||
|
||||
public BerBitString(byte[] data)
|
||||
: base(data)
|
||||
{
|
||||
}
|
||||
|
||||
public BerBitString(int namedBits)
|
||||
: base(namedBits)
|
||||
{
|
||||
}
|
||||
|
||||
public BerBitString(Asn1Encodable obj)
|
||||
: base(obj)
|
||||
{
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
if (derOut is Asn1OutputStream || derOut is BerOutputStream)
|
||||
{
|
||||
derOut.WriteEncoded(Asn1Tags.BitString, (byte)mPadBits, mData);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Encode(derOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BERBitString.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BERBitString.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32ef67513f7bd494bbf8ac11a730ddb8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
105
Assets/BestHTTP/SecureProtocol/asn1/BERGenerator.cs
Normal file
105
Assets/BestHTTP/SecureProtocol/asn1/BERGenerator.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerGenerator
|
||||
: Asn1Generator
|
||||
{
|
||||
private bool _tagged = false;
|
||||
private bool _isExplicit;
|
||||
private int _tagNo;
|
||||
|
||||
protected BerGenerator(
|
||||
Stream outStream)
|
||||
: base(outStream)
|
||||
{
|
||||
}
|
||||
|
||||
public BerGenerator(
|
||||
Stream outStream,
|
||||
int tagNo,
|
||||
bool isExplicit)
|
||||
: base(outStream)
|
||||
{
|
||||
_tagged = true;
|
||||
_isExplicit = isExplicit;
|
||||
_tagNo = tagNo;
|
||||
}
|
||||
|
||||
public override void AddObject(
|
||||
Asn1Encodable obj)
|
||||
{
|
||||
new BerOutputStream(Out).WriteObject(obj);
|
||||
}
|
||||
|
||||
public override Stream GetRawOutputStream()
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
WriteBerEnd();
|
||||
}
|
||||
|
||||
private void WriteHdr(
|
||||
int tag)
|
||||
{
|
||||
Out.WriteByte((byte) tag);
|
||||
Out.WriteByte(0x80);
|
||||
}
|
||||
|
||||
protected void WriteBerHeader(
|
||||
int tag)
|
||||
{
|
||||
if (_tagged)
|
||||
{
|
||||
int tagNum = _tagNo | Asn1Tags.Tagged;
|
||||
|
||||
if (_isExplicit)
|
||||
{
|
||||
WriteHdr(tagNum | Asn1Tags.Constructed);
|
||||
WriteHdr(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((tag & Asn1Tags.Constructed) != 0)
|
||||
{
|
||||
WriteHdr(tagNum | Asn1Tags.Constructed);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteHdr(tagNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteHdr(tag);
|
||||
}
|
||||
}
|
||||
|
||||
protected void WriteBerBody(
|
||||
Stream contentStream)
|
||||
{
|
||||
Streams.PipeAll(contentStream, Out);
|
||||
}
|
||||
|
||||
protected void WriteBerEnd()
|
||||
{
|
||||
Out.WriteByte(0x00);
|
||||
Out.WriteByte(0x00);
|
||||
|
||||
if (_tagged && _isExplicit) // write extra end for tag header
|
||||
{
|
||||
Out.WriteByte(0x00);
|
||||
Out.WriteByte(0x00);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BERGenerator.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BERGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a0bc402f13404c2c83adf8e511d4a0a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/BestHTTP/SecureProtocol/asn1/BEROctetStringParser.cs
Normal file
39
Assets/BestHTTP/SecureProtocol/asn1/BEROctetStringParser.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerOctetStringParser
|
||||
: Asn1OctetStringParser
|
||||
{
|
||||
private readonly Asn1StreamParser _parser;
|
||||
|
||||
internal BerOctetStringParser(
|
||||
Asn1StreamParser parser)
|
||||
{
|
||||
_parser = parser;
|
||||
}
|
||||
|
||||
public Stream GetOctetStream()
|
||||
{
|
||||
return new ConstructedOctetStream(_parser);
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new BerOctetString(Streams.ReadAll(GetOctetStream()));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new Asn1ParsingException("IOException converting stream to byte array: " + e.Message, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7476fb334fea14f05a8143dd9d8c6a5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/BestHTTP/SecureProtocol/asn1/BERSequenceGenerator.cs
Normal file
27
Assets/BestHTTP/SecureProtocol/asn1/BERSequenceGenerator.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerSequenceGenerator
|
||||
: BerGenerator
|
||||
{
|
||||
public BerSequenceGenerator(
|
||||
Stream outStream)
|
||||
: base(outStream)
|
||||
{
|
||||
WriteBerHeader(Asn1Tags.Constructed | Asn1Tags.Sequence);
|
||||
}
|
||||
|
||||
public BerSequenceGenerator(
|
||||
Stream outStream,
|
||||
int tagNo,
|
||||
bool isExplicit)
|
||||
: base(outStream, tagNo, isExplicit)
|
||||
{
|
||||
WriteBerHeader(Asn1Tags.Constructed | Asn1Tags.Sequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8a8bb79d3b5f432e9eab06291a19f8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/BestHTTP/SecureProtocol/asn1/BERSequenceParser.cs
Normal file
27
Assets/BestHTTP/SecureProtocol/asn1/BERSequenceParser.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerSequenceParser
|
||||
: Asn1SequenceParser
|
||||
{
|
||||
private readonly Asn1StreamParser _parser;
|
||||
|
||||
internal BerSequenceParser(
|
||||
Asn1StreamParser parser)
|
||||
{
|
||||
this._parser = parser;
|
||||
}
|
||||
|
||||
public IAsn1Convertible ReadObject()
|
||||
{
|
||||
return _parser.ReadObject();
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new BerSequence(_parser.ReadVector());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80ab79fc73d434ee5ad7e7acb7f618b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/BestHTTP/SecureProtocol/asn1/BERSetGenerator.cs
Normal file
27
Assets/BestHTTP/SecureProtocol/asn1/BERSetGenerator.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerSetGenerator
|
||||
: BerGenerator
|
||||
{
|
||||
public BerSetGenerator(
|
||||
Stream outStream)
|
||||
: base(outStream)
|
||||
{
|
||||
WriteBerHeader(Asn1Tags.Constructed | Asn1Tags.Set);
|
||||
}
|
||||
|
||||
public BerSetGenerator(
|
||||
Stream outStream,
|
||||
int tagNo,
|
||||
bool isExplicit)
|
||||
: base(outStream, tagNo, isExplicit)
|
||||
{
|
||||
WriteBerHeader(Asn1Tags.Constructed | Asn1Tags.Set);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BERSetGenerator.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BERSetGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1e981562073745ad84d87fcea69601c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/BestHTTP/SecureProtocol/asn1/BERSetParser.cs
Normal file
27
Assets/BestHTTP/SecureProtocol/asn1/BERSetParser.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerSetParser
|
||||
: Asn1SetParser
|
||||
{
|
||||
private readonly Asn1StreamParser _parser;
|
||||
|
||||
internal BerSetParser(
|
||||
Asn1StreamParser parser)
|
||||
{
|
||||
this._parser = parser;
|
||||
}
|
||||
|
||||
public IAsn1Convertible ReadObject()
|
||||
{
|
||||
return _parser.ReadObject();
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new BerSet(_parser.ReadVector(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BERSetParser.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BERSetParser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b19c20ba086d540c68537bf4468a4de2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Assets/BestHTTP/SecureProtocol/asn1/BERTaggedObjectParser.cs
Normal file
74
Assets/BestHTTP/SecureProtocol/asn1/BERTaggedObjectParser.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerTaggedObjectParser
|
||||
: Asn1TaggedObjectParser
|
||||
{
|
||||
private bool _constructed;
|
||||
private int _tagNumber;
|
||||
private Asn1StreamParser _parser;
|
||||
|
||||
[Obsolete]
|
||||
internal BerTaggedObjectParser(
|
||||
int baseTag,
|
||||
int tagNumber,
|
||||
Stream contentStream)
|
||||
: this((baseTag & Asn1Tags.Constructed) != 0, tagNumber, new Asn1StreamParser(contentStream))
|
||||
{
|
||||
}
|
||||
|
||||
internal BerTaggedObjectParser(
|
||||
bool constructed,
|
||||
int tagNumber,
|
||||
Asn1StreamParser parser)
|
||||
{
|
||||
_constructed = constructed;
|
||||
_tagNumber = tagNumber;
|
||||
_parser = parser;
|
||||
}
|
||||
|
||||
public bool IsConstructed
|
||||
{
|
||||
get { return _constructed; }
|
||||
}
|
||||
|
||||
public int TagNo
|
||||
{
|
||||
get { return _tagNumber; }
|
||||
}
|
||||
|
||||
public IAsn1Convertible GetObjectParser(
|
||||
int tag,
|
||||
bool isExplicit)
|
||||
{
|
||||
if (isExplicit)
|
||||
{
|
||||
if (!_constructed)
|
||||
throw new IOException("Explicit tags must be constructed (see X.690 8.14.2)");
|
||||
|
||||
return _parser.ReadObject();
|
||||
}
|
||||
|
||||
return _parser.ReadImplicit(_constructed, tag);
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _parser.ReadTaggedObject(_constructed, _tagNumber);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new Asn1ParsingException(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f59391e1167964ec7a9a1fa8fe43175b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerApplicationSpecific
|
||||
: DerApplicationSpecific
|
||||
{
|
||||
public BerApplicationSpecific(
|
||||
int tagNo,
|
||||
Asn1EncodableVector vec)
|
||||
: base(tagNo, vec)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da56e2cd0ec0441e6a82ea62f14ee76a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerApplicationSpecificParser
|
||||
: IAsn1ApplicationSpecificParser
|
||||
{
|
||||
private readonly int tag;
|
||||
private readonly Asn1StreamParser parser;
|
||||
|
||||
internal BerApplicationSpecificParser(
|
||||
int tag,
|
||||
Asn1StreamParser parser)
|
||||
{
|
||||
this.tag = tag;
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public IAsn1Convertible ReadObject()
|
||||
{
|
||||
return parser.ReadObject();
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new BerApplicationSpecific(tag, parser.ReadVector());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: daa2a17ea11194d64822ab2fbfbdc7cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
138
Assets/BestHTTP/SecureProtocol/asn1/BerOctetString.cs
Normal file
138
Assets/BestHTTP/SecureProtocol/asn1/BerOctetString.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerOctetString
|
||||
: DerOctetString, IEnumerable
|
||||
{
|
||||
public static BerOctetString FromSequence(Asn1Sequence seq)
|
||||
{
|
||||
IList v = Platform.CreateArrayList();
|
||||
|
||||
foreach (Asn1Encodable obj in seq)
|
||||
{
|
||||
v.Add(obj);
|
||||
}
|
||||
|
||||
return new BerOctetString(v);
|
||||
}
|
||||
|
||||
private const int MaxLength = 1000;
|
||||
|
||||
/**
|
||||
* convert a vector of octet strings into a single byte string
|
||||
*/
|
||||
private static byte[] ToBytes(
|
||||
IEnumerable octs)
|
||||
{
|
||||
MemoryStream bOut = new MemoryStream();
|
||||
foreach (DerOctetString o in octs)
|
||||
{
|
||||
byte[] octets = o.GetOctets();
|
||||
bOut.Write(octets, 0, octets.Length);
|
||||
}
|
||||
return bOut.ToArray();
|
||||
}
|
||||
|
||||
private readonly IEnumerable octs;
|
||||
|
||||
/// <param name="str">The octets making up the octet string.</param>
|
||||
public BerOctetString(
|
||||
byte[] str)
|
||||
: base(str)
|
||||
{
|
||||
}
|
||||
|
||||
public BerOctetString(
|
||||
IEnumerable octets)
|
||||
: base(ToBytes(octets))
|
||||
{
|
||||
this.octs = octets;
|
||||
}
|
||||
|
||||
public BerOctetString(
|
||||
Asn1Object obj)
|
||||
: base(obj)
|
||||
{
|
||||
}
|
||||
|
||||
public BerOctetString(
|
||||
Asn1Encodable obj)
|
||||
: base(obj.ToAsn1Object())
|
||||
{
|
||||
}
|
||||
|
||||
public override byte[] GetOctets()
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the DER octets that make up this string.
|
||||
*/
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
if (octs == null)
|
||||
{
|
||||
return GenerateOcts().GetEnumerator();
|
||||
}
|
||||
|
||||
return octs.GetEnumerator();
|
||||
}
|
||||
|
||||
[Obsolete("Use GetEnumerator() instead")]
|
||||
public IEnumerator GetObjects()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
private IList GenerateOcts()
|
||||
{
|
||||
IList vec = Platform.CreateArrayList();
|
||||
for (int i = 0; i < str.Length; i += MaxLength)
|
||||
{
|
||||
int end = System.Math.Min(str.Length, i + MaxLength);
|
||||
|
||||
byte[] nStr = new byte[end - i];
|
||||
|
||||
Array.Copy(str, i, nStr, 0, nStr.Length);
|
||||
|
||||
vec.Add(new DerOctetString(nStr));
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
if (derOut is Asn1OutputStream || derOut is BerOutputStream)
|
||||
{
|
||||
derOut.WriteByte(Asn1Tags.Constructed | Asn1Tags.OctetString);
|
||||
|
||||
derOut.WriteByte(0x80);
|
||||
|
||||
//
|
||||
// write out the octet array
|
||||
//
|
||||
foreach (DerOctetString oct in this)
|
||||
{
|
||||
derOut.WriteObject(oct);
|
||||
}
|
||||
|
||||
derOut.WriteByte(0x00);
|
||||
derOut.WriteByte(0x00);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Encode(derOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BerOctetString.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BerOctetString.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e86617df65876411696de6cc8f9de8bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/BestHTTP/SecureProtocol/asn1/BerOutputStream.cs
Normal file
39
Assets/BestHTTP/SecureProtocol/asn1/BerOutputStream.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
// TODO Make Obsolete in favour of Asn1OutputStream?
|
||||
public class BerOutputStream
|
||||
: DerOutputStream
|
||||
{
|
||||
public BerOutputStream(Stream os) : base(os)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Use version taking an Asn1Encodable arg instead")]
|
||||
public override void WriteObject(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
WriteNull();
|
||||
}
|
||||
else if (obj is Asn1Object)
|
||||
{
|
||||
((Asn1Object)obj).Encode(this);
|
||||
}
|
||||
else if (obj is Asn1Encodable)
|
||||
{
|
||||
((Asn1Encodable)obj).ToAsn1Object().Encode(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("object not BerEncodable");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BerOutputStream.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BerOutputStream.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04d52ea69c22c4aac89def4f94d2dd79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
72
Assets/BestHTTP/SecureProtocol/asn1/BerSequence.cs
Normal file
72
Assets/BestHTTP/SecureProtocol/asn1/BerSequence.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerSequence
|
||||
: DerSequence
|
||||
{
|
||||
public static new readonly BerSequence Empty = new BerSequence();
|
||||
|
||||
public static new BerSequence FromVector(
|
||||
Asn1EncodableVector v)
|
||||
{
|
||||
return v.Count < 1 ? Empty : new BerSequence(v);
|
||||
}
|
||||
|
||||
/**
|
||||
* create an empty sequence
|
||||
*/
|
||||
public BerSequence()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* create a sequence containing one object
|
||||
*/
|
||||
public BerSequence(
|
||||
Asn1Encodable obj)
|
||||
: base(obj)
|
||||
{
|
||||
}
|
||||
|
||||
public BerSequence(
|
||||
params Asn1Encodable[] v)
|
||||
: base(v)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* create a sequence containing a vector of objects.
|
||||
*/
|
||||
public BerSequence(
|
||||
Asn1EncodableVector v)
|
||||
: base(v)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
if (derOut is Asn1OutputStream || derOut is BerOutputStream)
|
||||
{
|
||||
derOut.WriteByte(Asn1Tags.Sequence | Asn1Tags.Constructed);
|
||||
derOut.WriteByte(0x80);
|
||||
|
||||
foreach (Asn1Encodable o in this)
|
||||
{
|
||||
derOut.WriteObject(o);
|
||||
}
|
||||
|
||||
derOut.WriteByte(0x00);
|
||||
derOut.WriteByte(0x00);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Encode(derOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BerSequence.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BerSequence.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfc1c4182a25e4724a3aa4d1767d6fdd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
73
Assets/BestHTTP/SecureProtocol/asn1/BerSet.cs
Normal file
73
Assets/BestHTTP/SecureProtocol/asn1/BerSet.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class BerSet
|
||||
: DerSet
|
||||
{
|
||||
public static new readonly BerSet Empty = new BerSet();
|
||||
|
||||
public static new BerSet FromVector(
|
||||
Asn1EncodableVector v)
|
||||
{
|
||||
return v.Count < 1 ? Empty : new BerSet(v);
|
||||
}
|
||||
|
||||
internal static new BerSet FromVector(
|
||||
Asn1EncodableVector v,
|
||||
bool needsSorting)
|
||||
{
|
||||
return v.Count < 1 ? Empty : new BerSet(v, needsSorting);
|
||||
}
|
||||
|
||||
/**
|
||||
* create an empty sequence
|
||||
*/
|
||||
public BerSet()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* create a set containing one object
|
||||
*/
|
||||
public BerSet(Asn1Encodable obj) : base(obj)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* create a set containing a vector of objects.
|
||||
*/
|
||||
public BerSet(Asn1EncodableVector v) : base(v, false)
|
||||
{
|
||||
}
|
||||
|
||||
internal BerSet(Asn1EncodableVector v, bool needsSorting) : base(v, needsSorting)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
if (derOut is Asn1OutputStream || derOut is BerOutputStream)
|
||||
{
|
||||
derOut.WriteByte(Asn1Tags.Set | Asn1Tags.Constructed);
|
||||
derOut.WriteByte(0x80);
|
||||
|
||||
foreach (Asn1Encodable o in this)
|
||||
{
|
||||
derOut.WriteObject(o);
|
||||
}
|
||||
|
||||
derOut.WriteByte(0x00);
|
||||
derOut.WriteByte(0x00);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Encode(derOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BerSet.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BerSet.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3056339eb39ae44a596bd29ee13bb2ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
111
Assets/BestHTTP/SecureProtocol/asn1/BerTaggedObject.cs
Normal file
111
Assets/BestHTTP/SecureProtocol/asn1/BerTaggedObject.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
/**
|
||||
* BER TaggedObject - in ASN.1 notation this is any object preceded by
|
||||
* a [n] where n is some number - these are assumed to follow the construction
|
||||
* rules (as with sequences).
|
||||
*/
|
||||
public class BerTaggedObject
|
||||
: DerTaggedObject
|
||||
{
|
||||
/**
|
||||
* @param tagNo the tag number for this object.
|
||||
* @param obj the tagged object.
|
||||
*/
|
||||
public BerTaggedObject(
|
||||
int tagNo,
|
||||
Asn1Encodable obj)
|
||||
: base(tagNo, obj)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param explicitly true if an explicitly tagged object.
|
||||
* @param tagNo the tag number for this object.
|
||||
* @param obj the tagged object.
|
||||
*/
|
||||
public BerTaggedObject(
|
||||
bool explicitly,
|
||||
int tagNo,
|
||||
Asn1Encodable obj)
|
||||
: base(explicitly, tagNo, obj)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* create an implicitly tagged object that contains a zero
|
||||
* length sequence.
|
||||
*/
|
||||
public BerTaggedObject(
|
||||
int tagNo)
|
||||
: base(false, tagNo, BerSequence.Empty)
|
||||
{
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
if (derOut is Asn1OutputStream || derOut is BerOutputStream)
|
||||
{
|
||||
derOut.WriteTag((byte)(Asn1Tags.Constructed | Asn1Tags.Tagged), tagNo);
|
||||
derOut.WriteByte(0x80);
|
||||
|
||||
if (!IsEmpty())
|
||||
{
|
||||
if (!explicitly)
|
||||
{
|
||||
IEnumerable eObj;
|
||||
if (obj is Asn1OctetString)
|
||||
{
|
||||
if (obj is BerOctetString)
|
||||
{
|
||||
eObj = (BerOctetString) obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
Asn1OctetString octs = (Asn1OctetString)obj;
|
||||
eObj = new BerOctetString(octs.GetOctets());
|
||||
}
|
||||
}
|
||||
else if (obj is Asn1Sequence)
|
||||
{
|
||||
eObj = (Asn1Sequence) obj;
|
||||
}
|
||||
else if (obj is Asn1Set)
|
||||
{
|
||||
eObj = (Asn1Set) obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Platform.CreateNotImplementedException(Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
foreach (Asn1Encodable o in eObj)
|
||||
{
|
||||
derOut.WriteObject(o);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
derOut.WriteObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
derOut.WriteByte(0x00);
|
||||
derOut.WriteByte(0x00);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Encode(derOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/BerTaggedObject.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/BerTaggedObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40a1f4d9d7fab43f2b931f0ca19b55c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
105
Assets/BestHTTP/SecureProtocol/asn1/ConstructedOctetStream.cs
Normal file
105
Assets/BestHTTP/SecureProtocol/asn1/ConstructedOctetStream.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
internal class ConstructedOctetStream
|
||||
: BaseInputStream
|
||||
{
|
||||
private readonly Asn1StreamParser _parser;
|
||||
|
||||
private bool _first = true;
|
||||
private Stream _currentStream;
|
||||
|
||||
internal ConstructedOctetStream(
|
||||
Asn1StreamParser parser)
|
||||
{
|
||||
_parser = parser;
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (_currentStream == null)
|
||||
{
|
||||
if (!_first)
|
||||
return 0;
|
||||
|
||||
Asn1OctetStringParser s = (Asn1OctetStringParser)_parser.ReadObject();
|
||||
|
||||
if (s == null)
|
||||
return 0;
|
||||
|
||||
_first = false;
|
||||
_currentStream = s.GetOctetStream();
|
||||
}
|
||||
|
||||
int totalRead = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int numRead = _currentStream.Read(buffer, offset + totalRead, count - totalRead);
|
||||
|
||||
if (numRead > 0)
|
||||
{
|
||||
totalRead += numRead;
|
||||
|
||||
if (totalRead == count)
|
||||
return totalRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
Asn1OctetStringParser aos = (Asn1OctetStringParser)_parser.ReadObject();
|
||||
|
||||
if (aos == null)
|
||||
{
|
||||
_currentStream = null;
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
_currentStream = aos.GetOctetStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
if (_currentStream == null)
|
||||
{
|
||||
if (!_first)
|
||||
return 0;
|
||||
|
||||
Asn1OctetStringParser s = (Asn1OctetStringParser)_parser.ReadObject();
|
||||
|
||||
if (s == null)
|
||||
return 0;
|
||||
|
||||
_first = false;
|
||||
_currentStream = s.GetOctetStream();
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int b = _currentStream.ReadByte();
|
||||
|
||||
if (b >= 0)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
Asn1OctetStringParser aos = (Asn1OctetStringParser)_parser.ReadObject();
|
||||
|
||||
if (aos == null)
|
||||
{
|
||||
_currentStream = null;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_currentStream = aos.GetOctetStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 199bbcc81dbd24e3c9ba706ac66dc8a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
205
Assets/BestHTTP/SecureProtocol/asn1/DERExternal.cs
Normal file
205
Assets/BestHTTP/SecureProtocol/asn1/DERExternal.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
/**
|
||||
* Class representing the DER-type External
|
||||
*/
|
||||
public class DerExternal
|
||||
: Asn1Object
|
||||
{
|
||||
private DerObjectIdentifier directReference;
|
||||
private DerInteger indirectReference;
|
||||
private Asn1Object dataValueDescriptor;
|
||||
private int encoding;
|
||||
private Asn1Object externalContent;
|
||||
|
||||
public DerExternal(
|
||||
Asn1EncodableVector vector)
|
||||
{
|
||||
int offset = 0;
|
||||
Asn1Object enc = GetObjFromVector(vector, offset);
|
||||
if (enc is DerObjectIdentifier)
|
||||
{
|
||||
directReference = (DerObjectIdentifier)enc;
|
||||
offset++;
|
||||
enc = GetObjFromVector(vector, offset);
|
||||
}
|
||||
if (enc is DerInteger)
|
||||
{
|
||||
indirectReference = (DerInteger) enc;
|
||||
offset++;
|
||||
enc = GetObjFromVector(vector, offset);
|
||||
}
|
||||
if (!(enc is Asn1TaggedObject))
|
||||
{
|
||||
dataValueDescriptor = enc;
|
||||
offset++;
|
||||
enc = GetObjFromVector(vector, offset);
|
||||
}
|
||||
|
||||
if (vector.Count != offset + 1)
|
||||
throw new ArgumentException("input vector too large", "vector");
|
||||
|
||||
if (!(enc is Asn1TaggedObject))
|
||||
throw new ArgumentException("No tagged object found in vector. Structure doesn't seem to be of type External", "vector");
|
||||
|
||||
Asn1TaggedObject obj = (Asn1TaggedObject)enc;
|
||||
|
||||
// Use property accessor to include check on value
|
||||
Encoding = obj.TagNo;
|
||||
|
||||
if (encoding < 0 || encoding > 2)
|
||||
throw new InvalidOperationException("invalid encoding value");
|
||||
|
||||
externalContent = obj.GetObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of DerExternal
|
||||
* See X.690 for more informations about the meaning of these parameters
|
||||
* @param directReference The direct reference or <code>null</code> if not set.
|
||||
* @param indirectReference The indirect reference or <code>null</code> if not set.
|
||||
* @param dataValueDescriptor The data value descriptor or <code>null</code> if not set.
|
||||
* @param externalData The external data in its encoded form.
|
||||
*/
|
||||
public DerExternal(DerObjectIdentifier directReference, DerInteger indirectReference, Asn1Object dataValueDescriptor, DerTaggedObject externalData)
|
||||
: this(directReference, indirectReference, dataValueDescriptor, externalData.TagNo, externalData.ToAsn1Object())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of DerExternal.
|
||||
* See X.690 for more informations about the meaning of these parameters
|
||||
* @param directReference The direct reference or <code>null</code> if not set.
|
||||
* @param indirectReference The indirect reference or <code>null</code> if not set.
|
||||
* @param dataValueDescriptor The data value descriptor or <code>null</code> if not set.
|
||||
* @param encoding The encoding to be used for the external data
|
||||
* @param externalData The external data
|
||||
*/
|
||||
public DerExternal(DerObjectIdentifier directReference, DerInteger indirectReference, Asn1Object dataValueDescriptor, int encoding, Asn1Object externalData)
|
||||
{
|
||||
DirectReference = directReference;
|
||||
IndirectReference = indirectReference;
|
||||
DataValueDescriptor = dataValueDescriptor;
|
||||
Encoding = encoding;
|
||||
ExternalContent = externalData.ToAsn1Object();
|
||||
}
|
||||
|
||||
internal override void Encode(DerOutputStream derOut)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
WriteEncodable(ms, directReference);
|
||||
WriteEncodable(ms, indirectReference);
|
||||
WriteEncodable(ms, dataValueDescriptor);
|
||||
WriteEncodable(ms, new DerTaggedObject(Asn1Tags.External, externalContent));
|
||||
|
||||
derOut.WriteEncoded(Asn1Tags.Constructed, Asn1Tags.External, ms.ToArray());
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
int ret = externalContent.GetHashCode();
|
||||
if (directReference != null)
|
||||
{
|
||||
ret ^= directReference.GetHashCode();
|
||||
}
|
||||
if (indirectReference != null)
|
||||
{
|
||||
ret ^= indirectReference.GetHashCode();
|
||||
}
|
||||
if (dataValueDescriptor != null)
|
||||
{
|
||||
ret ^= dataValueDescriptor.GetHashCode();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
if (this == asn1Object)
|
||||
return true;
|
||||
|
||||
DerExternal other = asn1Object as DerExternal;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Platform.Equals(directReference, other.directReference)
|
||||
&& Platform.Equals(indirectReference, other.indirectReference)
|
||||
&& Platform.Equals(dataValueDescriptor, other.dataValueDescriptor)
|
||||
&& externalContent.Equals(other.externalContent);
|
||||
}
|
||||
|
||||
public Asn1Object DataValueDescriptor
|
||||
{
|
||||
get { return dataValueDescriptor; }
|
||||
set { this.dataValueDescriptor = value; }
|
||||
}
|
||||
|
||||
public DerObjectIdentifier DirectReference
|
||||
{
|
||||
get { return directReference; }
|
||||
set { this.directReference = value; }
|
||||
}
|
||||
|
||||
/**
|
||||
* The encoding of the content. Valid values are
|
||||
* <ul>
|
||||
* <li><code>0</code> single-ASN1-type</li>
|
||||
* <li><code>1</code> OCTET STRING</li>
|
||||
* <li><code>2</code> BIT STRING</li>
|
||||
* </ul>
|
||||
*/
|
||||
public int Encoding
|
||||
{
|
||||
get
|
||||
{
|
||||
return encoding;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (encoding < 0 || encoding > 2)
|
||||
throw new InvalidOperationException("invalid encoding value: " + encoding);
|
||||
|
||||
this.encoding = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Asn1Object ExternalContent
|
||||
{
|
||||
get { return externalContent; }
|
||||
set { this.externalContent = value; }
|
||||
}
|
||||
|
||||
public DerInteger IndirectReference
|
||||
{
|
||||
get { return indirectReference; }
|
||||
set { this.indirectReference = value; }
|
||||
}
|
||||
|
||||
private static Asn1Object GetObjFromVector(Asn1EncodableVector v, int index)
|
||||
{
|
||||
if (v.Count <= index)
|
||||
throw new ArgumentException("too few objects in input vector", "v");
|
||||
|
||||
return v[index].ToAsn1Object();
|
||||
}
|
||||
|
||||
private static void WriteEncodable(MemoryStream ms, Asn1Encodable e)
|
||||
{
|
||||
if (e != null)
|
||||
{
|
||||
byte[] bs = e.GetDerEncoded();
|
||||
ms.Write(bs, 0, bs.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/DERExternal.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/DERExternal.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3c3ea8b0950d4b4eaf345b86c589be0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/BestHTTP/SecureProtocol/asn1/DERExternalParser.cs
Normal file
29
Assets/BestHTTP/SecureProtocol/asn1/DERExternalParser.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerExternalParser
|
||||
: Asn1Encodable
|
||||
{
|
||||
private readonly Asn1StreamParser _parser;
|
||||
|
||||
public DerExternalParser(Asn1StreamParser parser)
|
||||
{
|
||||
this._parser = parser;
|
||||
}
|
||||
|
||||
public IAsn1Convertible ReadObject()
|
||||
{
|
||||
return _parser.ReadObject();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerExternal(_parser.ReadVector());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ff0278f30e8b4517a34eecee185cbe4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
110
Assets/BestHTTP/SecureProtocol/asn1/DERGenerator.cs
Normal file
110
Assets/BestHTTP/SecureProtocol/asn1/DERGenerator.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public abstract class DerGenerator
|
||||
: Asn1Generator
|
||||
{
|
||||
private bool _tagged = false;
|
||||
private bool _isExplicit;
|
||||
private int _tagNo;
|
||||
|
||||
protected DerGenerator(
|
||||
Stream outStream)
|
||||
: base(outStream)
|
||||
{
|
||||
}
|
||||
|
||||
protected DerGenerator(
|
||||
Stream outStream,
|
||||
int tagNo,
|
||||
bool isExplicit)
|
||||
: base(outStream)
|
||||
{
|
||||
_tagged = true;
|
||||
_isExplicit = isExplicit;
|
||||
_tagNo = tagNo;
|
||||
}
|
||||
|
||||
private static void WriteLength(
|
||||
Stream outStr,
|
||||
int length)
|
||||
{
|
||||
if (length > 127)
|
||||
{
|
||||
int size = 1;
|
||||
int val = length;
|
||||
|
||||
while ((val >>= 8) != 0)
|
||||
{
|
||||
size++;
|
||||
}
|
||||
|
||||
outStr.WriteByte((byte)(size | 0x80));
|
||||
|
||||
for (int i = (size - 1) * 8; i >= 0; i -= 8)
|
||||
{
|
||||
outStr.WriteByte((byte)(length >> i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outStr.WriteByte((byte)length);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void WriteDerEncoded(
|
||||
Stream outStream,
|
||||
int tag,
|
||||
byte[] bytes)
|
||||
{
|
||||
outStream.WriteByte((byte) tag);
|
||||
WriteLength(outStream, bytes.Length);
|
||||
outStream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
internal void WriteDerEncoded(
|
||||
int tag,
|
||||
byte[] bytes)
|
||||
{
|
||||
if (_tagged)
|
||||
{
|
||||
int tagNum = _tagNo | Asn1Tags.Tagged;
|
||||
|
||||
if (_isExplicit)
|
||||
{
|
||||
int newTag = _tagNo | Asn1Tags.Constructed | Asn1Tags.Tagged;
|
||||
MemoryStream bOut = new MemoryStream();
|
||||
WriteDerEncoded(bOut, tag, bytes);
|
||||
WriteDerEncoded(Out, newTag, bOut.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((tag & Asn1Tags.Constructed) != 0)
|
||||
{
|
||||
tagNum |= Asn1Tags.Constructed;
|
||||
}
|
||||
|
||||
WriteDerEncoded(Out, tagNum, bytes);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteDerEncoded(Out, tag, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void WriteDerEncoded(
|
||||
Stream outStr,
|
||||
int tag,
|
||||
Stream inStr)
|
||||
{
|
||||
WriteDerEncoded(outStr, tag, Streams.ReadAll(inStr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/DERGenerator.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/DERGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb3540685282b48649ffd363009479ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/BestHTTP/SecureProtocol/asn1/DEROctetStringParser.cs
Normal file
39
Assets/BestHTTP/SecureProtocol/asn1/DEROctetStringParser.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerOctetStringParser
|
||||
: Asn1OctetStringParser
|
||||
{
|
||||
private readonly DefiniteLengthInputStream stream;
|
||||
|
||||
internal DerOctetStringParser(
|
||||
DefiniteLengthInputStream stream)
|
||||
{
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public Stream GetOctetStream()
|
||||
{
|
||||
return stream;
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new DerOctetString(stream.ToArray());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new InvalidOperationException("IOException converting stream to byte array: " + e.Message, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51226b006c03a4f45875b7678fc9470f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/BestHTTP/SecureProtocol/asn1/DERSequenceParser.cs
Normal file
27
Assets/BestHTTP/SecureProtocol/asn1/DERSequenceParser.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerSequenceParser
|
||||
: Asn1SequenceParser
|
||||
{
|
||||
private readonly Asn1StreamParser _parser;
|
||||
|
||||
internal DerSequenceParser(
|
||||
Asn1StreamParser parser)
|
||||
{
|
||||
this._parser = parser;
|
||||
}
|
||||
|
||||
public IAsn1Convertible ReadObject()
|
||||
{
|
||||
return _parser.ReadObject();
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(_parser.ReadVector());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 438ca6650e73c49c18f5ad3e5ef8a40d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/BestHTTP/SecureProtocol/asn1/DERSetGenerator.cs
Normal file
43
Assets/BestHTTP/SecureProtocol/asn1/DERSetGenerator.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerSetGenerator
|
||||
: DerGenerator
|
||||
{
|
||||
private readonly MemoryStream _bOut = new MemoryStream();
|
||||
|
||||
public DerSetGenerator(
|
||||
Stream outStream)
|
||||
: base(outStream)
|
||||
{
|
||||
}
|
||||
|
||||
public DerSetGenerator(
|
||||
Stream outStream,
|
||||
int tagNo,
|
||||
bool isExplicit)
|
||||
: base(outStream, tagNo, isExplicit)
|
||||
{
|
||||
}
|
||||
|
||||
public override void AddObject(
|
||||
Asn1Encodable obj)
|
||||
{
|
||||
new DerOutputStream(_bOut).WriteObject(obj);
|
||||
}
|
||||
|
||||
public override Stream GetRawOutputStream()
|
||||
{
|
||||
return _bOut;
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
WriteDerEncoded(Asn1Tags.Constructed | Asn1Tags.Set, _bOut.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/DERSetGenerator.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/DERSetGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42d24178f58334135a18a71bfd33d4a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/BestHTTP/SecureProtocol/asn1/DERSetParser.cs
Normal file
27
Assets/BestHTTP/SecureProtocol/asn1/DERSetParser.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerSetParser
|
||||
: Asn1SetParser
|
||||
{
|
||||
private readonly Asn1StreamParser _parser;
|
||||
|
||||
internal DerSetParser(
|
||||
Asn1StreamParser parser)
|
||||
{
|
||||
this._parser = parser;
|
||||
}
|
||||
|
||||
public IAsn1Convertible ReadObject()
|
||||
{
|
||||
return _parser.ReadObject();
|
||||
}
|
||||
|
||||
public Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSet(_parser.ReadVector(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/DERSetParser.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/DERSetParser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 676179d5f275246228619cc5e81b9156
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
103
Assets/BestHTTP/SecureProtocol/asn1/DefiniteLengthInputStream.cs
Normal file
103
Assets/BestHTTP/SecureProtocol/asn1/DefiniteLengthInputStream.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
class DefiniteLengthInputStream
|
||||
: LimitedInputStream
|
||||
{
|
||||
private static readonly byte[] EmptyBytes = new byte[0];
|
||||
|
||||
private readonly int _originalLength;
|
||||
private int _remaining;
|
||||
|
||||
internal DefiniteLengthInputStream(
|
||||
Stream inStream,
|
||||
int length)
|
||||
: base(inStream, length)
|
||||
{
|
||||
if (length < 0)
|
||||
throw new ArgumentException("negative lengths not allowed", "length");
|
||||
|
||||
this._originalLength = length;
|
||||
this._remaining = length;
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
SetParentEofDetect(true);
|
||||
}
|
||||
}
|
||||
|
||||
internal int Remaining
|
||||
{
|
||||
get { return _remaining; }
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
if (_remaining == 0)
|
||||
return -1;
|
||||
|
||||
int b = _in.ReadByte();
|
||||
|
||||
if (b < 0)
|
||||
throw new EndOfStreamException("DEF length " + _originalLength + " object truncated by " + _remaining);
|
||||
|
||||
if (--_remaining == 0)
|
||||
{
|
||||
SetParentEofDetect(true);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public override int Read(
|
||||
byte[] buf,
|
||||
int off,
|
||||
int len)
|
||||
{
|
||||
if (_remaining == 0)
|
||||
return 0;
|
||||
|
||||
int toRead = System.Math.Min(len, _remaining);
|
||||
int numRead = _in.Read(buf, off, toRead);
|
||||
|
||||
if (numRead < 1)
|
||||
throw new EndOfStreamException("DEF length " + _originalLength + " object truncated by " + _remaining);
|
||||
|
||||
if ((_remaining -= numRead) == 0)
|
||||
{
|
||||
SetParentEofDetect(true);
|
||||
}
|
||||
|
||||
return numRead;
|
||||
}
|
||||
|
||||
internal void ReadAllIntoByteArray(byte[] buf)
|
||||
{
|
||||
if (_remaining != buf.Length)
|
||||
throw new ArgumentException("buffer length not right for data");
|
||||
|
||||
if ((_remaining -= Streams.ReadFully(_in, buf)) != 0)
|
||||
throw new EndOfStreamException("DEF length " + _originalLength + " object truncated by " + _remaining);
|
||||
SetParentEofDetect(true);
|
||||
}
|
||||
|
||||
internal byte[] ToArray()
|
||||
{
|
||||
if (_remaining == 0)
|
||||
return EmptyBytes;
|
||||
|
||||
byte[] bytes = new byte[_remaining];
|
||||
if ((_remaining -= Streams.ReadFully(_in, bytes)) != 0)
|
||||
throw new EndOfStreamException("DEF length " + _originalLength + " object truncated by " + _remaining);
|
||||
SetParentEofDetect(true);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c93a878be84b4ce0b1859bd0bcfd94c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
240
Assets/BestHTTP/SecureProtocol/asn1/DerApplicationSpecific.cs
Normal file
240
Assets/BestHTTP/SecureProtocol/asn1/DerApplicationSpecific.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
/**
|
||||
* Base class for an application specific object
|
||||
*/
|
||||
public class DerApplicationSpecific
|
||||
: Asn1Object
|
||||
{
|
||||
private readonly bool isConstructed;
|
||||
private readonly int tag;
|
||||
private readonly byte[] octets;
|
||||
|
||||
internal DerApplicationSpecific(
|
||||
bool isConstructed,
|
||||
int tag,
|
||||
byte[] octets)
|
||||
{
|
||||
this.isConstructed = isConstructed;
|
||||
this.tag = tag;
|
||||
this.octets = octets;
|
||||
}
|
||||
|
||||
public DerApplicationSpecific(
|
||||
int tag,
|
||||
byte[] octets)
|
||||
: this(false, tag, octets)
|
||||
{
|
||||
}
|
||||
|
||||
public DerApplicationSpecific(
|
||||
int tag,
|
||||
Asn1Encodable obj)
|
||||
: this(true, tag, obj)
|
||||
{
|
||||
}
|
||||
|
||||
public DerApplicationSpecific(
|
||||
bool isExplicit,
|
||||
int tag,
|
||||
Asn1Encodable obj)
|
||||
{
|
||||
Asn1Object asn1Obj = obj.ToAsn1Object();
|
||||
|
||||
byte[] data = asn1Obj.GetDerEncoded();
|
||||
|
||||
this.isConstructed = Asn1TaggedObject.IsConstructed(isExplicit, asn1Obj);
|
||||
this.tag = tag;
|
||||
|
||||
if (isExplicit)
|
||||
{
|
||||
this.octets = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
int lenBytes = GetLengthOfHeader(data);
|
||||
byte[] tmp = new byte[data.Length - lenBytes];
|
||||
Array.Copy(data, lenBytes, tmp, 0, tmp.Length);
|
||||
this.octets = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
public DerApplicationSpecific(
|
||||
int tagNo,
|
||||
Asn1EncodableVector vec)
|
||||
{
|
||||
this.tag = tagNo;
|
||||
this.isConstructed = true;
|
||||
MemoryStream bOut = new MemoryStream();
|
||||
|
||||
for (int i = 0; i != vec.Count; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] bs = vec[i].GetDerEncoded();
|
||||
bOut.Write(bs, 0, bs.Length);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new InvalidOperationException("malformed object", e);
|
||||
}
|
||||
}
|
||||
this.octets = bOut.ToArray();
|
||||
}
|
||||
|
||||
private int GetLengthOfHeader(
|
||||
byte[] data)
|
||||
{
|
||||
int length = data[1]; // TODO: assumes 1 byte tag
|
||||
|
||||
if (length == 0x80)
|
||||
{
|
||||
return 2; // indefinite-length encoding
|
||||
}
|
||||
|
||||
if (length > 127)
|
||||
{
|
||||
int size = length & 0x7f;
|
||||
|
||||
// Note: The invalid long form "0xff" (see X.690 8.1.3.5c) will be caught here
|
||||
if (size > 4)
|
||||
{
|
||||
throw new InvalidOperationException("DER length more than 4 bytes: " + size);
|
||||
}
|
||||
|
||||
return size + 2;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
public bool IsConstructed()
|
||||
{
|
||||
return isConstructed;
|
||||
}
|
||||
|
||||
public byte[] GetContents()
|
||||
{
|
||||
return octets;
|
||||
}
|
||||
|
||||
public int ApplicationTag
|
||||
{
|
||||
get { return tag; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enclosed object assuming explicit tagging.
|
||||
*
|
||||
* @return the resulting object
|
||||
* @throws IOException if reconstruction fails.
|
||||
*/
|
||||
public Asn1Object GetObject()
|
||||
{
|
||||
return FromByteArray(GetContents());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enclosed object assuming implicit tagging.
|
||||
*
|
||||
* @param derTagNo the type tag that should be applied to the object's contents.
|
||||
* @return the resulting object
|
||||
* @throws IOException if reconstruction fails.
|
||||
*/
|
||||
public Asn1Object GetObject(
|
||||
int derTagNo)
|
||||
{
|
||||
if (derTagNo >= 0x1f)
|
||||
throw new IOException("unsupported tag number");
|
||||
|
||||
byte[] orig = this.GetEncoded();
|
||||
byte[] tmp = ReplaceTagNumber(derTagNo, orig);
|
||||
|
||||
if ((orig[0] & Asn1Tags.Constructed) != 0)
|
||||
{
|
||||
tmp[0] |= Asn1Tags.Constructed;
|
||||
}
|
||||
|
||||
return FromByteArray(tmp);
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
int classBits = Asn1Tags.Application;
|
||||
if (isConstructed)
|
||||
{
|
||||
classBits |= Asn1Tags.Constructed;
|
||||
}
|
||||
|
||||
derOut.WriteEncoded(classBits, tag, octets);
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
DerApplicationSpecific other = asn1Object as DerApplicationSpecific;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return this.isConstructed == other.isConstructed
|
||||
&& this.tag == other.tag
|
||||
&& Arrays.AreEqual(this.octets, other.octets);
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
return isConstructed.GetHashCode() ^ tag.GetHashCode() ^ Arrays.GetHashCode(octets);
|
||||
}
|
||||
|
||||
private byte[] ReplaceTagNumber(
|
||||
int newTag,
|
||||
byte[] input)
|
||||
{
|
||||
int tagNo = input[0] & 0x1f;
|
||||
int index = 1;
|
||||
//
|
||||
// with tagged object tag number is bottom 5 bits, or stored at the start of the content
|
||||
//
|
||||
if (tagNo == 0x1f)
|
||||
{
|
||||
tagNo = 0;
|
||||
|
||||
int b = input[index++] & 0xff;
|
||||
|
||||
// X.690-0207 8.1.2.4.2
|
||||
// "c) bits 7 to 1 of the first subsequent octet shall not all be zero."
|
||||
if ((b & 0x7f) == 0) // Note: -1 will pass
|
||||
{
|
||||
throw new InvalidOperationException("corrupted stream - invalid high tag number found");
|
||||
}
|
||||
|
||||
while ((b >= 0) && ((b & 0x80) != 0))
|
||||
{
|
||||
tagNo |= (b & 0x7f);
|
||||
tagNo <<= 7;
|
||||
b = input[index++] & 0xff;
|
||||
}
|
||||
|
||||
tagNo |= (b & 0x7f);
|
||||
}
|
||||
|
||||
byte[] tmp = new byte[input.Length - index + 1];
|
||||
|
||||
Array.Copy(input, index, tmp, 1, tmp.Length - 1);
|
||||
|
||||
tmp[0] = (byte)newTag;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcb6f31bc088848908e4a920043f72be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
120
Assets/BestHTTP/SecureProtocol/asn1/DerBMPString.cs
Normal file
120
Assets/BestHTTP/SecureProtocol/asn1/DerBMPString.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
/**
|
||||
* Der BMPString object.
|
||||
*/
|
||||
public class DerBmpString
|
||||
: DerStringBase
|
||||
{
|
||||
private readonly string str;
|
||||
|
||||
/**
|
||||
* return a BMP string from the given object.
|
||||
*
|
||||
* @param obj the object we want converted.
|
||||
* @exception ArgumentException if the object cannot be converted.
|
||||
*/
|
||||
public static DerBmpString GetInstance(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null || obj is DerBmpString)
|
||||
{
|
||||
return (DerBmpString)obj;
|
||||
}
|
||||
|
||||
throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* return a BMP string from a tagged object.
|
||||
*
|
||||
* @param obj the tagged object holding the object we want
|
||||
* @param explicitly true if the object is meant to be explicitly
|
||||
* tagged false otherwise.
|
||||
* @exception ArgumentException if the tagged object cannot
|
||||
* be converted.
|
||||
*/
|
||||
public static DerBmpString GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool isExplicit)
|
||||
{
|
||||
Asn1Object o = obj.GetObject();
|
||||
|
||||
if (isExplicit || o is DerBmpString)
|
||||
{
|
||||
return GetInstance(o);
|
||||
}
|
||||
|
||||
return new DerBmpString(Asn1OctetString.GetInstance(o).GetOctets());
|
||||
}
|
||||
|
||||
/**
|
||||
* basic constructor - byte encoded string.
|
||||
*/
|
||||
public DerBmpString(
|
||||
byte[] str)
|
||||
{
|
||||
if (str == null)
|
||||
throw new ArgumentNullException("str");
|
||||
|
||||
char[] cs = new char[str.Length / 2];
|
||||
|
||||
for (int i = 0; i != cs.Length; i++)
|
||||
{
|
||||
cs[i] = (char)((str[2 * i] << 8) | (str[2 * i + 1] & 0xff));
|
||||
}
|
||||
|
||||
this.str = new string(cs);
|
||||
}
|
||||
|
||||
/**
|
||||
* basic constructor
|
||||
*/
|
||||
public DerBmpString(
|
||||
string str)
|
||||
{
|
||||
if (str == null)
|
||||
throw new ArgumentNullException("str");
|
||||
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public override string GetString()
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
DerBmpString other = asn1Object as DerBmpString;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return this.str.Equals(other.str);
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
char[] c = str.ToCharArray();
|
||||
byte[] b = new byte[c.Length * 2];
|
||||
|
||||
for (int i = 0; i != c.Length; i++)
|
||||
{
|
||||
b[2 * i] = (byte)(c[i] >> 8);
|
||||
b[2 * i + 1] = (byte)c[i];
|
||||
}
|
||||
|
||||
derOut.WriteEncoded(Asn1Tags.BmpString, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/DerBMPString.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/DerBMPString.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0be15e2f711e947cfa205ac401af28da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
279
Assets/BestHTTP/SecureProtocol/asn1/DerBitString.cs
Normal file
279
Assets/BestHTTP/SecureProtocol/asn1/DerBitString.cs
Normal file
@@ -0,0 +1,279 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerBitString
|
||||
: DerStringBase
|
||||
{
|
||||
private static readonly char[] table
|
||||
= { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
protected readonly byte[] mData;
|
||||
protected readonly int mPadBits;
|
||||
|
||||
/**
|
||||
* return a Bit string from the passed in object
|
||||
*
|
||||
* @exception ArgumentException if the object cannot be converted.
|
||||
*/
|
||||
public static DerBitString GetInstance(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null || obj is DerBitString)
|
||||
{
|
||||
return (DerBitString) obj;
|
||||
}
|
||||
if (obj is byte[])
|
||||
{
|
||||
try
|
||||
{
|
||||
return (DerBitString)FromByteArray((byte[])obj);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArgumentException("encoding error in GetInstance: " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* return a Bit string from a tagged object.
|
||||
*
|
||||
* @param obj the tagged object holding the object we want
|
||||
* @param explicitly true if the object is meant to be explicitly
|
||||
* tagged false otherwise.
|
||||
* @exception ArgumentException if the tagged object cannot
|
||||
* be converted.
|
||||
*/
|
||||
public static DerBitString GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool isExplicit)
|
||||
{
|
||||
Asn1Object o = obj.GetObject();
|
||||
|
||||
if (isExplicit || o is DerBitString)
|
||||
{
|
||||
return GetInstance(o);
|
||||
}
|
||||
|
||||
return FromAsn1Octets(((Asn1OctetString)o).GetOctets());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data the octets making up the bit string.
|
||||
* @param padBits the number of extra bits at the end of the string.
|
||||
*/
|
||||
public DerBitString(
|
||||
byte[] data,
|
||||
int padBits)
|
||||
{
|
||||
if (data == null)
|
||||
throw new ArgumentNullException("data");
|
||||
if (padBits < 0 || padBits > 7)
|
||||
throw new ArgumentException("must be in the range 0 to 7", "padBits");
|
||||
if (data.Length == 0 && padBits != 0)
|
||||
throw new ArgumentException("if 'data' is empty, 'padBits' must be 0");
|
||||
|
||||
this.mData = Arrays.Clone(data);
|
||||
this.mPadBits = padBits;
|
||||
}
|
||||
|
||||
public DerBitString(
|
||||
byte[] data)
|
||||
: this(data, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public DerBitString(
|
||||
int namedBits)
|
||||
{
|
||||
if (namedBits == 0)
|
||||
{
|
||||
this.mData = new byte[0];
|
||||
this.mPadBits = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int bits = BigInteger.BitLen(namedBits);
|
||||
int bytes = (bits + 7) / 8;
|
||||
|
||||
Debug.Assert(0 < bytes && bytes <= 4);
|
||||
|
||||
byte[] data = new byte[bytes];
|
||||
--bytes;
|
||||
|
||||
for (int i = 0; i < bytes; i++)
|
||||
{
|
||||
data[i] = (byte)namedBits;
|
||||
namedBits >>= 8;
|
||||
}
|
||||
|
||||
Debug.Assert((namedBits & 0xFF) != 0);
|
||||
|
||||
data[bytes] = (byte)namedBits;
|
||||
|
||||
int padBits = 0;
|
||||
while ((namedBits & (1 << padBits)) == 0)
|
||||
{
|
||||
++padBits;
|
||||
}
|
||||
|
||||
Debug.Assert(padBits < 8);
|
||||
|
||||
this.mData = data;
|
||||
this.mPadBits = padBits;
|
||||
}
|
||||
|
||||
public DerBitString(
|
||||
Asn1Encodable obj)
|
||||
: this(obj.GetDerEncoded())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the octets contained in this BIT STRING, checking that this BIT STRING really
|
||||
* does represent an octet aligned string. Only use this method when the standard you are
|
||||
* following dictates that the BIT STRING will be octet aligned.
|
||||
*
|
||||
* @return a copy of the octet aligned data.
|
||||
*/
|
||||
public virtual byte[] GetOctets()
|
||||
{
|
||||
if (mPadBits != 0)
|
||||
throw new InvalidOperationException("attempt to get non-octet aligned data from BIT STRING");
|
||||
|
||||
return Arrays.Clone(mData);
|
||||
}
|
||||
|
||||
public virtual byte[] GetBytes()
|
||||
{
|
||||
byte[] data = Arrays.Clone(mData);
|
||||
|
||||
// DER requires pad bits be zero
|
||||
if (mPadBits > 0)
|
||||
{
|
||||
data[data.Length - 1] &= (byte)(0xFF << mPadBits);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public virtual int PadBits
|
||||
{
|
||||
get { return mPadBits; }
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value of the bit string as an int (truncating if necessary)
|
||||
*/
|
||||
public virtual int IntValue
|
||||
{
|
||||
get
|
||||
{
|
||||
int value = 0, length = System.Math.Min(4, mData.Length);
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
value |= (int)mData[i] << (8 * i);
|
||||
}
|
||||
if (mPadBits > 0 && length == mData.Length)
|
||||
{
|
||||
int mask = (1 << mPadBits) - 1;
|
||||
value &= ~(mask << (8 * (length - 1)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
if (mPadBits > 0)
|
||||
{
|
||||
int last = mData[mData.Length - 1];
|
||||
int mask = (1 << mPadBits) - 1;
|
||||
int unusedBits = last & mask;
|
||||
|
||||
if (unusedBits != 0)
|
||||
{
|
||||
byte[] contents = Arrays.Prepend(mData, (byte)mPadBits);
|
||||
|
||||
/*
|
||||
* X.690-0207 11.2.1: Each unused bit in the final octet of the encoding of a bit string value shall be set to zero.
|
||||
*/
|
||||
contents[contents.Length - 1] = (byte)(last ^ unusedBits);
|
||||
|
||||
derOut.WriteEncoded(Asn1Tags.BitString, contents);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
derOut.WriteEncoded(Asn1Tags.BitString, (byte)mPadBits, mData);
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
return mPadBits.GetHashCode() ^ Arrays.GetHashCode(mData);
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
DerBitString other = asn1Object as DerBitString;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return this.mPadBits == other.mPadBits
|
||||
&& Arrays.AreEqual(this.mData, other.mData);
|
||||
}
|
||||
|
||||
public override string GetString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder("#");
|
||||
|
||||
byte[] str = GetDerEncoded();
|
||||
|
||||
for (int i = 0; i != str.Length; i++)
|
||||
{
|
||||
uint ubyte = str[i];
|
||||
buffer.Append(table[(ubyte >> 4) & 0xf]);
|
||||
buffer.Append(table[str[i] & 0xf]);
|
||||
}
|
||||
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
internal static DerBitString FromAsn1Octets(byte[] octets)
|
||||
{
|
||||
if (octets.Length < 1)
|
||||
throw new ArgumentException("truncated BIT STRING detected", "octets");
|
||||
|
||||
int padBits = octets[0];
|
||||
byte[] data = Arrays.CopyOfRange(octets, 1, octets.Length);
|
||||
|
||||
if (padBits > 0 && padBits < 8 && data.Length > 0)
|
||||
{
|
||||
int last = data[data.Length - 1];
|
||||
int mask = (1 << padBits) - 1;
|
||||
|
||||
if ((last & mask) != 0)
|
||||
{
|
||||
return new BerBitString(data, padBits);
|
||||
}
|
||||
}
|
||||
|
||||
return new DerBitString(data, padBits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/DerBitString.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/DerBitString.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbbbfdaffbe774904baee2e156ee0126
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
127
Assets/BestHTTP/SecureProtocol/asn1/DerBoolean.cs
Normal file
127
Assets/BestHTTP/SecureProtocol/asn1/DerBoolean.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerBoolean
|
||||
: Asn1Object
|
||||
{
|
||||
private readonly byte value;
|
||||
|
||||
public static readonly DerBoolean False = new DerBoolean(false);
|
||||
public static readonly DerBoolean True = new DerBoolean(true);
|
||||
|
||||
/**
|
||||
* return a bool from the passed in object.
|
||||
*
|
||||
* @exception ArgumentException if the object cannot be converted.
|
||||
*/
|
||||
public static DerBoolean GetInstance(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null || obj is DerBoolean)
|
||||
{
|
||||
return (DerBoolean) obj;
|
||||
}
|
||||
|
||||
throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* return a DerBoolean from the passed in bool.
|
||||
*/
|
||||
public static DerBoolean GetInstance(
|
||||
bool value)
|
||||
{
|
||||
return value ? True : False;
|
||||
}
|
||||
|
||||
/**
|
||||
* return a Boolean from a tagged object.
|
||||
*
|
||||
* @param obj the tagged object holding the object we want
|
||||
* @param explicitly true if the object is meant to be explicitly
|
||||
* tagged false otherwise.
|
||||
* @exception ArgumentException if the tagged object cannot
|
||||
* be converted.
|
||||
*/
|
||||
public static DerBoolean GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool isExplicit)
|
||||
{
|
||||
Asn1Object o = obj.GetObject();
|
||||
|
||||
if (isExplicit || o is DerBoolean)
|
||||
{
|
||||
return GetInstance(o);
|
||||
}
|
||||
|
||||
return FromOctetString(((Asn1OctetString)o).GetOctets());
|
||||
}
|
||||
|
||||
public DerBoolean(
|
||||
byte[] val)
|
||||
{
|
||||
if (val.Length != 1)
|
||||
throw new ArgumentException("byte value should have 1 byte in it", "val");
|
||||
|
||||
// TODO Are there any constraints on the possible byte values?
|
||||
this.value = val[0];
|
||||
}
|
||||
|
||||
private DerBoolean(
|
||||
bool value)
|
||||
{
|
||||
this.value = value ? (byte)0xff : (byte)0;
|
||||
}
|
||||
|
||||
public bool IsTrue
|
||||
{
|
||||
get { return value != 0; }
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
// TODO Should we make sure the byte value is one of '0' or '0xff' here?
|
||||
derOut.WriteEncoded(Asn1Tags.Boolean, new byte[]{ value });
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
DerBoolean other = asn1Object as DerBoolean;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return IsTrue == other.IsTrue;
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
return IsTrue.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return IsTrue ? "TRUE" : "FALSE";
|
||||
}
|
||||
|
||||
internal static DerBoolean FromOctetString(byte[] value)
|
||||
{
|
||||
if (value.Length != 1)
|
||||
{
|
||||
throw new ArgumentException("BOOLEAN value should have 1 byte in it", "value");
|
||||
}
|
||||
|
||||
byte b = value[0];
|
||||
|
||||
return b == 0 ? False : b == 0xFF ? True : new DerBoolean(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/DerBoolean.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/DerBoolean.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 845736dca47ff414bacfbff16aef0c24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
127
Assets/BestHTTP/SecureProtocol/asn1/DerEnumerated.cs
Normal file
127
Assets/BestHTTP/SecureProtocol/asn1/DerEnumerated.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerEnumerated
|
||||
: Asn1Object
|
||||
{
|
||||
private readonly byte[] bytes;
|
||||
|
||||
/**
|
||||
* return an integer from the passed in object
|
||||
*
|
||||
* @exception ArgumentException if the object cannot be converted.
|
||||
*/
|
||||
public static DerEnumerated GetInstance(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null || obj is DerEnumerated)
|
||||
{
|
||||
return (DerEnumerated)obj;
|
||||
}
|
||||
|
||||
throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* return an Enumerated from a tagged object.
|
||||
*
|
||||
* @param obj the tagged object holding the object we want
|
||||
* @param explicitly true if the object is meant to be explicitly
|
||||
* tagged false otherwise.
|
||||
* @exception ArgumentException if the tagged object cannot
|
||||
* be converted.
|
||||
*/
|
||||
public static DerEnumerated GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool isExplicit)
|
||||
{
|
||||
Asn1Object o = obj.GetObject();
|
||||
|
||||
if (isExplicit || o is DerEnumerated)
|
||||
{
|
||||
return GetInstance(o);
|
||||
}
|
||||
|
||||
return FromOctetString(((Asn1OctetString)o).GetOctets());
|
||||
}
|
||||
|
||||
public DerEnumerated(
|
||||
int val)
|
||||
{
|
||||
bytes = BigInteger.ValueOf(val).ToByteArray();
|
||||
}
|
||||
|
||||
public DerEnumerated(
|
||||
BigInteger val)
|
||||
{
|
||||
bytes = val.ToByteArray();
|
||||
}
|
||||
|
||||
public DerEnumerated(
|
||||
byte[] bytes)
|
||||
{
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public BigInteger Value
|
||||
{
|
||||
get { return new BigInteger(bytes); }
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
derOut.WriteEncoded(Asn1Tags.Enumerated, bytes);
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
DerEnumerated other = asn1Object as DerEnumerated;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Arrays.AreEqual(this.bytes, other.bytes);
|
||||
}
|
||||
|
||||
protected override int Asn1GetHashCode()
|
||||
{
|
||||
return Arrays.GetHashCode(bytes);
|
||||
}
|
||||
|
||||
private static readonly DerEnumerated[] cache = new DerEnumerated[12];
|
||||
|
||||
internal static DerEnumerated FromOctetString(byte[] enc)
|
||||
{
|
||||
if (enc.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("ENUMERATED has zero length", "enc");
|
||||
}
|
||||
|
||||
if (enc.Length == 1)
|
||||
{
|
||||
int value = enc[0];
|
||||
if (value < cache.Length)
|
||||
{
|
||||
DerEnumerated cached = cache[value];
|
||||
if (cached != null)
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
return cache[value] = new DerEnumerated(Arrays.Clone(enc));
|
||||
}
|
||||
}
|
||||
|
||||
return new DerEnumerated(Arrays.Clone(enc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/asn1/DerEnumerated.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/asn1/DerEnumerated.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d73c4998fa2814a6eb76e7accc1e7cea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Assets/BestHTTP/SecureProtocol/asn1/DerGeneralString.cs
Normal file
84
Assets/BestHTTP/SecureProtocol/asn1/DerGeneralString.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1
|
||||
{
|
||||
public class DerGeneralString
|
||||
: DerStringBase
|
||||
{
|
||||
private readonly string str;
|
||||
|
||||
public static DerGeneralString GetInstance(
|
||||
object obj)
|
||||
{
|
||||
if (obj == null || obj is DerGeneralString)
|
||||
{
|
||||
return (DerGeneralString) obj;
|
||||
}
|
||||
|
||||
throw new ArgumentException("illegal object in GetInstance: "
|
||||
+ Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
public static DerGeneralString GetInstance(
|
||||
Asn1TaggedObject obj,
|
||||
bool isExplicit)
|
||||
{
|
||||
Asn1Object o = obj.GetObject();
|
||||
|
||||
if (isExplicit || o is DerGeneralString)
|
||||
{
|
||||
return GetInstance(o);
|
||||
}
|
||||
|
||||
return new DerGeneralString(((Asn1OctetString)o).GetOctets());
|
||||
}
|
||||
|
||||
public DerGeneralString(
|
||||
byte[] str)
|
||||
: this(Strings.FromAsciiByteArray(str))
|
||||
{
|
||||
}
|
||||
|
||||
public DerGeneralString(
|
||||
string str)
|
||||
{
|
||||
if (str == null)
|
||||
throw new ArgumentNullException("str");
|
||||
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public override string GetString()
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
public byte[] GetOctets()
|
||||
{
|
||||
return Strings.ToAsciiByteArray(str);
|
||||
}
|
||||
|
||||
internal override void Encode(
|
||||
DerOutputStream derOut)
|
||||
{
|
||||
derOut.WriteEncoded(Asn1Tags.GeneralString, GetOctets());
|
||||
}
|
||||
|
||||
protected override bool Asn1Equals(
|
||||
Asn1Object asn1Object)
|
||||
{
|
||||
DerGeneralString other = asn1Object as DerGeneralString;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return this.str.Equals(other.str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user