#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls
{
public sealed class DigitallySigned
{
private readonly SignatureAndHashAlgorithm algorithm;
private readonly byte[] signature;
public DigitallySigned(SignatureAndHashAlgorithm algorithm, byte[] signature)
{
if (signature == null)
throw new ArgumentNullException("signature");
this.algorithm = algorithm;
this.signature = signature;
}
/// a (or null before TLS 1.2).
public SignatureAndHashAlgorithm Algorithm
{
get { return algorithm; }
}
public byte[] Signature
{
get { return signature; }
}
/// Encode this to a .
/// the to encode to.
///
public void Encode(Stream output)
{
if (algorithm != null)
{
algorithm.Encode(output);
}
TlsUtilities.WriteOpaque16(signature, output);
}
/// Parse a from a .
/// the of the current connection.
/// the to parse from.
/// a object.
///
public static DigitallySigned Parse(TlsContext context, Stream input)
{
SignatureAndHashAlgorithm algorithm = null;
if (TlsUtilities.IsTlsV12(context))
{
algorithm = SignatureAndHashAlgorithm.Parse(input);
if (SignatureAlgorithm.anonymous == algorithm.Signature)
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
byte[] signature = TlsUtilities.ReadOpaque16(input);
return new DigitallySigned(algorithm, signature);
}
}
}
#pragma warning restore
#endif