CertificatePair.cs :  » PDF » iTextSharp » Org » BouncyCastle » Asn1 » X509 » 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 » Asn1 » X509 » CertificatePair.cs
using System;

namespace Org.BouncyCastle.Asn1.X509{
  /**
  * This class helps to support crossCerfificatePairs in a LDAP directory
  * according RFC 2587
  *
  * <pre>
  *     crossCertificatePairATTRIBUTE::={
  *       WITH SYNTAX   CertificatePair
  *       EQUALITY MATCHING RULE certificatePairExactMatch
  *       ID joint-iso-ccitt(2) ds(5) attributeType(4) crossCertificatePair(40)}
  * </pre>
  *
  * <blockquote> The forward elements of the crossCertificatePair attribute of a
  * CA's directory entry shall be used to store all, except self-issued
  * certificates issued to this CA. Optionally, the reverse elements of the
  * crossCertificatePair attribute, of a CA's directory entry may contain a
  * subset of certificates issued by this CA to other CAs. When both the forward
  * and the reverse elements are present in a single attribute value, issuer name
  * in one certificate shall match the subject name in the other and vice versa,
  * and the subject public key in one certificate shall be capable of verifying
  * the digital signature on the other certificate and vice versa.
  *
  * When a reverse element is present, the forward element value and the reverse
  * element value need not be stored in the same attribute value; in other words,
  * they can be stored in either a single attribute value or two attribute
  * values. </blockquote>
  *
  * <pre>
  *       CertificatePair ::= SEQUENCE {
  *         forward    [0]  Certificate OPTIONAL,
  *         reverse    [1]  Certificate OPTIONAL,
  *         -- at least one of the pair shall be present -- }
  * </pre>
  */
  public class CertificatePair
    : Asn1Encodable
  {
    private X509CertificateStructure forward, reverse;

    public static CertificatePair GetInstance(
      object obj)
    {
      if (obj == null || obj is CertificatePair)
      {
        return (CertificatePair) obj;
      }

      if (obj is Asn1Sequence)
      {
        return new CertificatePair((Asn1Sequence) obj);
      }

      throw new ArgumentException("unknown object in factory: " + obj.GetType().Name, "obj");
    }

    /**
    * Constructor from Asn1Sequence.
    * <p/>
    * The sequence is of type CertificatePair:
    * <p/>
    * <pre>
    *       CertificatePair ::= SEQUENCE {
    *         forward    [0]  Certificate OPTIONAL,
    *         reverse    [1]  Certificate OPTIONAL,
    *         -- at least one of the pair shall be present -- }
    * </pre>
    *
    * @param seq The ASN.1 sequence.
    */
    private CertificatePair(
      Asn1Sequence seq)
    {
      if (seq.Count != 1 && seq.Count != 2)
      {
        throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
      }

      foreach (object obj in seq)
      {
        Asn1TaggedObject o = Asn1TaggedObject.GetInstance(obj);
        if (o.TagNo == 0)
        {
          forward = X509CertificateStructure.GetInstance(o, true);
        }
        else if (o.TagNo == 1)
        {
          reverse = X509CertificateStructure.GetInstance(o, true);
        }
        else
        {
          throw new ArgumentException("Bad tag number: " + o.TagNo);
        }
      }
    }

    /**
    * Constructor from a given details.
    *
    * @param forward Certificates issued to this CA.
    * @param reverse Certificates issued by this CA to other CAs.
    */
    public CertificatePair(
      X509CertificateStructure  forward,
      X509CertificateStructure  reverse)
    {
      this.forward = forward;
      this.reverse = reverse;
    }

    /**
    * Produce an object suitable for an Asn1OutputStream.
    * <p/>
    * Returns:
    * <p/>
    * <pre>
    *       CertificatePair ::= SEQUENCE {
    *         forward    [0]  Certificate OPTIONAL,
    *         reverse    [1]  Certificate OPTIONAL,
    *         -- at least one of the pair shall be present -- }
    * </pre>
    *
    * @return a DERObject
    */
    public override Asn1Object ToAsn1Object()
    {
      Asn1EncodableVector vec = new Asn1EncodableVector();

      if (forward != null)
      {
        vec.Add(new DerTaggedObject(0, forward));
      }

      if (reverse != null)
      {
        vec.Add(new DerTaggedObject(1, reverse));
      }

      return new DerSequence(vec);
    }

    /**
    * @return Returns the forward.
    */
    public X509CertificateStructure Forward
    {
      get { return forward; }
    }

    /**
    * @return Returns the reverse.
    */
    public X509CertificateStructure Reverse
    {
      get { return reverse; }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.