UserAttributeSubpacket
using Org.BouncyCastle.Crypto.Utilities;
using Org.BouncyCastle.Utilities;
using System;
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 unsafe virtual void Encode(Stream os)
{
int num = data.Length + 1;
if (longLength || 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);
}
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);
}
}
}