UserAttributeSubpacket
using Org.BouncyCastle.Utilities;
using System.IO;
namespace Org.BouncyCastle.Bcpg
{
public class UserAttributeSubpacket
{
internal readonly UserAttributeSubpacketTag type;
private readonly bool longLength;
protected readonly byte[] data;
public virtual UserAttributeSubpacketTag SubpacketType => type;
protected internal UserAttributeSubpacket(UserAttributeSubpacketTag type, byte[] data)
: this(type, false, data)
{
}
protected internal UserAttributeSubpacket(UserAttributeSubpacketTag type, bool forceLongLength, byte[] data)
{
this.type = type;
longLength = forceLongLength;
this.data = data;
}
public virtual byte[] GetData()
{
return data;
}
public virtual void Encode(Stream os)
{
int num = data.Length + 1;
if (longLength || num > 8383) {
os.WriteByte(byte.MaxValue);
os.WriteByte((byte)(num >> 24));
os.WriteByte((byte)(num >> 16));
os.WriteByte((byte)(num >> 8));
os.WriteByte((byte)num);
} else if (num < 192) {
os.WriteByte((byte)num);
} else {
num -= 192;
os.WriteByte((byte)(((num >> 8) & 255) + 192));
os.WriteByte((byte)num);
}
os.WriteByte((byte)type);
os.Write(data, 0, data.Length);
}
public override bool Equals(object obj)
{
if (obj == this)
return true;
UserAttributeSubpacket userAttributeSubpacket = obj as UserAttributeSubpacket;
if (userAttributeSubpacket == null)
return false;
if (type == userAttributeSubpacket.type)
return Arrays.AreEqual(data, userAttributeSubpacket.data);
return false;
}
public override int GetHashCode()
{
return type.GetHashCode() ^ Arrays.GetHashCode(data);
}
}
}