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

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509.Store;

namespace Org.BouncyCastle.X509{
  /**
   * Carrying class for an attribute certificate issuer.
   */
  public class AttributeCertificateIssuer
    //: CertSelector, Selector
    : IX509Selector
  {
    internal readonly Asn1Encodable form;

    /**
     * Set the issuer directly with the ASN.1 structure.
     * 
     * @param issuer The issuer
     */
    public AttributeCertificateIssuer(
      AttCertIssuer issuer)
    {
      form = issuer.Issuer;
    }

    public AttributeCertificateIssuer(
      X509Name principal)
    {
//      form = new V2Form(GeneralNames.GetInstance(new DerSequence(new GeneralName(principal))));
      form = new V2Form(new GeneralNames(new GeneralName(principal)));
    }

    private object[] GetNames()
    {
      GeneralNames name;
      if (form is V2Form)
      {
        name = ((V2Form)form).IssuerName;
      }
      else
      {
        name = (GeneralNames)form;
      }

      GeneralName[] names = name.GetNames();

      ArrayList l = new ArrayList(names.Length);

      for (int i = 0; i != names.Length; i++)
      {
        if (names[i].TagNo == GeneralName.DirectoryName)
        {
          l.Add(X509Name.GetInstance(names[i].Name));
        }
      }

      return l.ToArray();
    }

    /// <summary>Return any principal objects inside the attribute certificate issuer object.</summary>
    /// <returns>An array of IPrincipal objects (usually X509Principal).</returns>
    public X509Name[] GetPrincipals()
    {
      object[] p = this.GetNames();
      ArrayList l = new ArrayList(p.Length);

      for (int i = 0; i != p.Length; i++)
      {
        if (p[i] is X509Name)
        {
          l.Add(p[i]);
        }
      }

      return (X509Name[]) l.ToArray(typeof(X509Name));
    }

    private bool MatchesDN(
      X509Name    subject,
      GeneralNames  targets)
    {
      GeneralName[] names = targets.GetNames();

      for (int i = 0; i != names.Length; i++)
      {
        GeneralName gn = names[i];

        if (gn.TagNo == GeneralName.DirectoryName)
        {
          try
          {
            if (X509Name.GetInstance(gn.Name).Equivalent(subject))
            {
              return true;
            }
          }
          catch (Exception)
          {
          }
        }
      }

      return false;
    }

    public object Clone()
    {
      return new AttributeCertificateIssuer(AttCertIssuer.GetInstance(form));
    }

    public bool Match(
//      Certificate cert)
      X509Certificate x509Cert)
    {
//      if (!(cert is X509Certificate))
//      {
//        return false;
//      }
//
//      X509Certificate x509Cert = (X509Certificate)cert;

      if (form is V2Form)
      {
        V2Form issuer = (V2Form) form;
        if (issuer.BaseCertificateID != null)
        {
          return issuer.BaseCertificateID.Serial.Value.Equals(x509Cert.SerialNumber)
            && MatchesDN(x509Cert.IssuerDN, issuer.BaseCertificateID.Issuer);
        }

        return MatchesDN(x509Cert.SubjectDN, issuer.IssuerName);
      }

      return MatchesDN(x509Cert.SubjectDN, (GeneralNames) form);
    }

    public override bool Equals(
      object obj)
    {
      if (obj == this)
      {
        return true;
      }

      if (!(obj is AttributeCertificateIssuer))
      {
        return false;
      }

      AttributeCertificateIssuer other = (AttributeCertificateIssuer)obj;

      return this.form.Equals(other.form);
    }

    public override int GetHashCode()
    {
      return this.form.GetHashCode();
    }

    public bool Match(
      object obj)
    {
      if (!(obj is X509Certificate))
      {
        return false;
      }

      //return Match((Certificate)obj);
      return Match((X509Certificate)obj);
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.