SignatureSubpacket
using Org.BouncyCastle.Crypto.Utilities;
using Org.BouncyCastle.Utilities;
using System;
using System.IO;
namespace Org.BouncyCastle.Bcpg
{
public class SignatureSubpacket
{
private readonly SignatureSubpacketTag type;
private readonly bool critical;
private readonly bool isLongLength;
internal byte[] data;
public SignatureSubpacketTag SubpacketType => type;
protected internal SignatureSubpacket(SignatureSubpacketTag type, bool critical, bool isLongLength, byte[] data)
{
this.type = type;
this.critical = critical;
this.isLongLength = isLongLength;
this.data = data;
}
public bool IsCritical()
{
return critical;
}
public bool IsLongLength()
{
return isLongLength;
}
public byte[] GetData()
{
return (byte[])data.Clone();
}
public unsafe void Encode(Stream os)
{
int num = data.Length + 1;
if (isLongLength || num > 8383) {
Span<byte> span = new Span<byte>(stackalloc byte[5], 5);
span[0] = byte.MaxValue;
Pack.UInt32_To_BE((uint)num, span, 1);
os.Write(span);
} else if (num < 192) {
os.WriteByte((byte)num);
} else {
num -= 192;
os.WriteByte((byte)(((num >> 8) & 255) + 192));
os.WriteByte((byte)num);
}
if (critical)
os.WriteByte((byte)((SignatureSubpacketTag)128 | type));
else
os.WriteByte((byte)type);
os.Write(data, 0, data.Length);
}
public override int GetHashCode()
{
return (critical ? 1 : 0) + 7 * (int)type + 49 * Arrays.GetHashCode(data);
}
public override bool Equals(object obj)
{
if (obj == this)
return true;
SignatureSubpacket signatureSubpacket = obj as SignatureSubpacket;
if (signatureSubpacket == null)
return false;
if (type == signatureSubpacket.type && critical == signatureSubpacket.critical)
return Arrays.AreEqual(data, signatureSubpacket.data);
return false;
}
}
}