UserAttributeSubpacket
Basic type for a user attribute subpacket.
using Org.BouncyCastle.Utilities;
using System.IO;
namespace Org.BouncyCastle.Bcpg
{
public class UserAttributeSubpacket
{
private readonly UserAttributeSubpacketTag m_type;
private readonly bool m_longLength;
protected readonly byte[] data;
internal byte[] Data => data;
public virtual UserAttributeSubpacketTag SubpacketType => m_type;
protected internal UserAttributeSubpacket(UserAttributeSubpacketTag type, byte[] data)
: this(type, false, data)
{
}
protected internal UserAttributeSubpacket(UserAttributeSubpacketTag type, bool longLength, byte[] data)
{
m_type = type;
m_longLength = longLength;
this.data = data;
}
public virtual byte[] GetData()
{
return Arrays.Clone(data);
}
public virtual void Encode(Stream os)
{
StreamUtilities.WriteNewPacketLength(os, 1 + data.Length, m_longLength);
os.WriteByte((byte)m_type);
os.Write(data, 0, data.Length);
}
public override bool Equals(object obj)
{
UserAttributeSubpacket userAttributeSubpacket = obj as UserAttributeSubpacket;
if (userAttributeSubpacket != null && m_type == userAttributeSubpacket.m_type)
return Arrays.AreEqual(data, userAttributeSubpacket.data);
return false;
}
public override int GetHashCode()
{
return m_type.GetHashCode() ^ Arrays.GetHashCode(data);
}
}
}