Target.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 » Target.cs
using System;

namespace Org.BouncyCastle.Asn1.X509{
  /**
   * Target structure used in target information extension for attribute
   * certificates from RFC 3281.
   * 
   * <pre>
   *     Target  ::= CHOICE {
   *       targetName          [0] GeneralName,
   *       targetGroup         [1] GeneralName,
   *       targetCert          [2] TargetCert
   *     }
   * </pre>
   * 
   * <p>
   * The targetCert field is currently not supported and must not be used
   * according to RFC 3281.</p>
   */
  public class Target
    : Asn1Encodable, IAsn1Choice
  {
    public enum Choice
    {
      Name = 0,
      Group = 1
    };

    private readonly GeneralName targetName;
    private readonly GeneralName targetGroup;

    /**
    * Creates an instance of a Target from the given object.
    * <p>
    * <code>obj</code> can be a Target or a {@link Asn1TaggedObject}</p>
    * 
    * @param obj The object.
    * @return A Target instance.
    * @throws ArgumentException if the given object cannot be
    *             interpreted as Target.
    */
    public static Target GetInstance(
      object obj)
    {
      if (obj is Target)
      {
        return (Target) obj;
      }

      if (obj is Asn1TaggedObject)
      {
        return new Target((Asn1TaggedObject) obj);
      }

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

    /**
     * Constructor from Asn1TaggedObject.
     * 
     * @param tagObj The tagged object.
     * @throws ArgumentException if the encoding is wrong.
     */
    private Target(
      Asn1TaggedObject tagObj)
    {
      switch ((Choice) tagObj.TagNo)
      {
        case Choice.Name:  // GeneralName is already a choice so explicit
          targetName = GeneralName.GetInstance(tagObj, true);
          break;
        case Choice.Group:
          targetGroup = GeneralName.GetInstance(tagObj, true);
          break;
        default:
          throw new ArgumentException("unknown tag: " + tagObj.TagNo);
      }
    }

    /**
     * Constructor from given details.
     * <p>
     * Exactly one of the parameters must be not <code>null</code>.</p>
     *
     * @param type the choice type to apply to the name.
     * @param name the general name.
     * @throws ArgumentException if type is invalid.
     */
    public Target(
      Choice    type,
      GeneralName  name)
      : this(new DerTaggedObject((int) type, name))
    {
    }

    /**
     * @return Returns the targetGroup.
     */
    public virtual GeneralName TargetGroup
    {
      get { return targetGroup; }
    }

    /**
     * @return Returns the targetName.
     */
    public virtual GeneralName TargetName
    {
      get { return targetName; }
    }

    /**
     * Produce an object suitable for an Asn1OutputStream.
     * 
     * Returns:
     * 
     * <pre>
     *     Target  ::= CHOICE {
     *       targetName          [0] GeneralName,
     *       targetGroup         [1] GeneralName,
     *       targetCert          [2] TargetCert
     *     }
     * </pre>
     * 
     * @return an Asn1Object
     */
    public override Asn1Object ToAsn1Object()
    {
      // GeneralName is a choice already so most be explicitly tagged
      if (targetName != null)
      {
        return new DerTaggedObject(true, 0, targetName);
      }

      return new DerTaggedObject(true, 1, targetGroup);
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.