You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.5 KiB
101 lines
2.5 KiB
8 months ago
|
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||
|
#pragma warning disable
|
||
|
using System;
|
||
|
|
||
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||
|
|
||
|
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
|
||
|
{
|
||
|
public class MacData
|
||
|
: Asn1Encodable
|
||
|
{
|
||
|
internal DigestInfo digInfo;
|
||
|
internal byte[] salt;
|
||
|
internal BigInteger iterationCount;
|
||
|
|
||
|
public static MacData GetInstance(
|
||
|
object obj)
|
||
|
{
|
||
|
if (obj is MacData)
|
||
|
{
|
||
|
return (MacData) obj;
|
||
|
}
|
||
|
|
||
|
if (obj is Asn1Sequence)
|
||
|
{
|
||
|
return new MacData((Asn1Sequence) obj);
|
||
|
}
|
||
|
|
||
|
throw new ArgumentException("Unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
|
||
|
}
|
||
|
|
||
|
private MacData(
|
||
|
Asn1Sequence seq)
|
||
|
{
|
||
|
this.digInfo = DigestInfo.GetInstance(seq[0]);
|
||
|
this.salt = ((Asn1OctetString) seq[1]).GetOctets();
|
||
|
|
||
|
if (seq.Count == 3)
|
||
|
{
|
||
|
this.iterationCount = ((DerInteger) seq[2]).Value;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
this.iterationCount = BigInteger.One;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public MacData(
|
||
|
DigestInfo digInfo,
|
||
|
byte[] salt,
|
||
|
int iterationCount)
|
||
|
{
|
||
|
this.digInfo = digInfo;
|
||
|
this.salt = (byte[]) salt.Clone();
|
||
|
this.iterationCount = BigInteger.ValueOf(iterationCount);
|
||
|
}
|
||
|
|
||
|
public DigestInfo Mac
|
||
|
{
|
||
|
get { return digInfo; }
|
||
|
}
|
||
|
|
||
|
public byte[] GetSalt()
|
||
|
{
|
||
|
return (byte[]) salt.Clone();
|
||
|
}
|
||
|
|
||
|
public BigInteger IterationCount
|
||
|
{
|
||
|
get { return iterationCount; }
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* <pre>
|
||
|
* MacData ::= SEQUENCE {
|
||
|
* mac DigestInfo,
|
||
|
* macSalt OCTET STRING,
|
||
|
* iterations INTEGER DEFAULT 1
|
||
|
* -- Note: The default is for historic reasons and its use is deprecated. A
|
||
|
* -- higher value, like 1024 is recommended.
|
||
|
* </pre>
|
||
|
* @return the basic DERObject construction.
|
||
|
*/
|
||
|
public override Asn1Object ToAsn1Object()
|
||
|
{
|
||
|
Asn1EncodableVector v = new Asn1EncodableVector(digInfo, new DerOctetString(salt));
|
||
|
|
||
|
if (!iterationCount.Equals(BigInteger.One))
|
||
|
{
|
||
|
v.Add(new DerInteger(iterationCount));
|
||
|
}
|
||
|
|
||
|
return new DerSequence(v);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#pragma warning restore
|
||
|
#endif
|