usingSystem;
usingSystem.Collections;
usingOrg.BouncyCastle.Bcpg.Sig;
namespace Org.BouncyCastle.Bcpg.OpenPgp{
/// <remarks>Container for a list of signature subpackets.</remarks>
publicclassPgpSignatureSubpacketVector
{
privatereadonly SignatureSubpacket[] packets;
internalPgpSignatureSubpacketVector(
SignatureSubpacket[] packets)
{
this.packets = packets;
}
public SignatureSubpacket GetSubpacket(
SignatureSubpacketTag type)
{
for (int i = 0; i != packets.Length; i++)
{
if (packets[i].SubpacketType == type)
{
return packets[i];
}
}
returnnull;
}
/**
* Return true if a particular subpacket type exists.
*
* @param type type to look for.
* @return true if present, false otherwise.
*/
publicbool HasSubpacket(
SignatureSubpacketTag type)
{
return GetSubpacket(type) != null;
}
/**
* Return all signature subpackets of the passed in type.
* @param type subpacket type code
* @return an array of zero or more matching subpackets.
*/
public SignatureSubpacket[] GetSubpackets(
SignatureSubpacketTag type)
{
ArrayList list = newArrayList();
for (int i = 0; i != packets.Length; i++)
{
if (packets[i].SubpacketType == type)
{
list.Add(packets[i]);
}
}
return (SignatureSubpacket[]) list.ToArray(typeof(SignatureSubpacket));
}
publicNotationData[] GetNotationDataOccurences()
{
SignatureSubpacket[] notations = GetSubpackets(SignatureSubpacketTag.NotationData);
NotationData[] vals = newNotationData[notations.Length];
for (int i = 0; i < notations.Length; i++)
{
vals[i] = (NotationData) notations[i];
}
return vals;
}
publiclong GetIssuerKeyId()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.IssuerKeyId);
return p == null ? 0 : ((IssuerKeyId) p).KeyId;
}
publicbool HasSignatureCreationTime()
{
return GetSubpacket(SignatureSubpacketTag.CreationTime) != null;
}
publicDateTime GetSignatureCreationTime()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.CreationTime);
if (p == null)
{
thrownewPgpException("SignatureCreationTime not available");
}
return ((SignatureCreationTime)p).GetTime();
}
/// <summary>
/// Return the number of seconds a signature is valid for after its creation date.
/// A value of zero means the signature never expires.
/// </summary>
/// <returns>Seconds a signature is valid for.</returns>
publiclong GetSignatureExpirationTime()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.ExpireTime);
return p == null ? 0 : ((SignatureExpirationTime) p).Time;
}
/// <summary>
/// Return the number of seconds a key is valid for after its creation date.
/// A value of zero means the key never expires.
/// </summary>
/// <returns>Seconds a signature is valid for.</returns>
publiclong GetKeyExpirationTime()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.KeyExpireTime);
return p == null ? 0 : ((KeyExpirationTime) p).Time;
}
publicint[] GetPreferredHashAlgorithms()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.PreferredHashAlgorithms);
return p == null ? null : ((PreferredAlgorithms) p).GetPreferences();
}
publicint[] GetPreferredSymmetricAlgorithms()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.PreferredSymmetricAlgorithms);
return p == null ? null : ((PreferredAlgorithms) p).GetPreferences();
}
publicint[] GetPreferredCompressionAlgorithms()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.PreferredCompressionAlgorithms);
return p == null ? null : ((PreferredAlgorithms) p).GetPreferences();
}
publicint GetKeyFlags()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.KeyFlags);
return p == null ? 0 : ((KeyFlags) p).Flags;
}
publicstring GetSignerUserId()
{
SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.SignerUserId);
return p == null ? null : ((SignerUserId) p).GetId();
}
publicbool IsPrimaryUserId()
{
PrimaryUserId primaryId = (PrimaryUserId)
this.GetSubpacket(SignatureSubpacketTag.PrimaryUserId);
if (primaryId != null)
{
return primaryId.IsPrimaryUserId();
}
returnfalse;
}
public SignatureSubpacketTag[] GetCriticalTags()
{
int count = 0;
for (int i = 0; i != packets.Length; i++)
{
if (packets[i].IsCritical())
{
count++;
}
}
SignatureSubpacketTag[] list = new SignatureSubpacketTag[count];
count = 0;
for (int i = 0; i != packets.Length; i++)
{
if (packets[i].IsCritical())
{
list[count++] = packets[i].SubpacketType;
}
}
return list;
}
[Obsolete("Use 'Count' property instead")]
publicint Size
{
get { return packets.Length; }
}
/// <summary>Return the number of packets this vector contains.</summary>
publicint Count
{
get { return packets.Length; }
}
internal SignatureSubpacket[] ToSubpacketArray()
{
return packets;
}
}
}