PgpSignatureSubpacketVector.cs :  » PDF » iTextSharp » Org » BouncyCastle » Bcpg » OpenPgp » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » PDF » iTextSharp 
iTextSharp » Org » BouncyCastle » Bcpg » OpenPgp » PgpSignatureSubpacketVector.cs
using System;
using System.Collections;

using Org.BouncyCastle.Bcpg.Sig;

namespace Org.BouncyCastle.Bcpg.OpenPgp{
  /// <remarks>Container for a list of signature subpackets.</remarks>
    public class PgpSignatureSubpacketVector
    {
        private readonly SignatureSubpacket[] packets;

    internal PgpSignatureSubpacketVector(
            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];
                }
            }

      return null;
        }

    /**
     * Return true if a particular subpacket type exists.
     *
     * @param type type to look for.
     * @return true if present, false otherwise.
     */
    public bool 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 = new ArrayList();

      for (int i = 0; i != packets.Length; i++)
      {
        if (packets[i].SubpacketType == type)
        {
          list.Add(packets[i]);
        }
      }

      return (SignatureSubpacket[]) list.ToArray(typeof(SignatureSubpacket));
    }

    public NotationData[] GetNotationDataOccurences()
    {
      SignatureSubpacket[] notations = GetSubpackets(SignatureSubpacketTag.NotationData);
      NotationData[] vals = new NotationData[notations.Length];

      for (int i = 0; i < notations.Length; i++)
      {
        vals[i] = (NotationData) notations[i];
      }

      return vals;
    }

    public long GetIssuerKeyId()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.IssuerKeyId);

            return p == null ? 0 : ((IssuerKeyId) p).KeyId;
        }

    public bool HasSignatureCreationTime()
    {
      return GetSubpacket(SignatureSubpacketTag.CreationTime) != null;
    }

    public DateTime GetSignatureCreationTime()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.CreationTime);

            if (p == null)
            {
                throw new PgpException("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>
        public long 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>
        public long GetKeyExpirationTime()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.KeyExpireTime);

      return p == null ? 0 : ((KeyExpirationTime) p).Time;
        }

    public int[] GetPreferredHashAlgorithms()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.PreferredHashAlgorithms);

      return p == null ? null : ((PreferredAlgorithms) p).GetPreferences();
        }

    public int[] GetPreferredSymmetricAlgorithms()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.PreferredSymmetricAlgorithms);

            return p == null ? null : ((PreferredAlgorithms) p).GetPreferences();
        }

    public int[] GetPreferredCompressionAlgorithms()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.PreferredCompressionAlgorithms);

            return p == null ? null : ((PreferredAlgorithms) p).GetPreferences();
        }

    public int GetKeyFlags()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.KeyFlags);

            return p == null ? 0 : ((KeyFlags) p).Flags;
        }

    public string GetSignerUserId()
        {
            SignatureSubpacket p = GetSubpacket(SignatureSubpacketTag.SignerUserId);

      return p == null ? null : ((SignerUserId) p).GetId();
        }

    public bool IsPrimaryUserId()
    {
      PrimaryUserId primaryId = (PrimaryUserId)
        this.GetSubpacket(SignatureSubpacketTag.PrimaryUserId);

      if (primaryId != null)
      {
        return primaryId.IsPrimaryUserId();
      }

      return false;
    }

    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")]
    public int Size
    {
      get { return packets.Length; }
    }

    /// <summary>Return the number of packets this vector contains.</summary>
    public int Count
    {
      get { return packets.Length; }
    }

    internal SignatureSubpacket[] ToSubpacketArray()
        {
            return packets;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.