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

namespace Org.BouncyCastle.Asn1.IsisMtt.X509{
  /**
  * A declaration of majority.
  * <p/>
  * <pre>
  *           DeclarationOfMajoritySyntax ::= CHOICE
  *           {
  *             notYoungerThan [0] IMPLICIT INTEGER,
  *             fullAgeAtCountry [1] IMPLICIT SEQUENCE
  *             {
  *               fullAge BOOLEAN DEFAULT TRUE,
  *               country PrintableString (SIZE(2))
  *             }
  *             dateOfBirth [2] IMPLICIT GeneralizedTime
  *           }
  * </pre>
  * <p/>
  * fullAgeAtCountry indicates the majority of the owner with respect to the laws
  * of a specific country.
  */
  public class DeclarationOfMajority
    : Asn1Encodable, IAsn1Choice
  {
    public enum Choice
    {
      NotYoungerThan = 0,
      FullAgeAtCountry = 1,
      DateOfBirth = 2
    };

    private readonly Asn1TaggedObject declaration;

    public DeclarationOfMajority(
      int notYoungerThan)
    {
      declaration = new DerTaggedObject(false, 0, new DerInteger(notYoungerThan));
    }

    public DeclarationOfMajority(
      bool  fullAge,
      string  country)
    {
      if (country.Length > 2)
        throw new ArgumentException("country can only be 2 characters");

      DerPrintableString countryString = new DerPrintableString(country, true);

      DerSequence seq;
      if (fullAge)
      {
        seq = new DerSequence(countryString);
      }
      else
      {
        seq = new DerSequence(DerBoolean.False, countryString);
      }

      this.declaration = new DerTaggedObject(false, 1, seq);
    }

    public DeclarationOfMajority(
      DerGeneralizedTime dateOfBirth)
    {
      this.declaration = new DerTaggedObject(false, 2, dateOfBirth);
    }

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

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

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

    private DeclarationOfMajority(
      Asn1TaggedObject o)
    {
      if (o.TagNo > 2)
        throw new ArgumentException("Bad tag number: " + o.TagNo);

      this.declaration = o;
    }

    /**
    * Produce an object suitable for an Asn1OutputStream.
    * <p/>
    * Returns:
    * <p/>
    * <pre>
    *           DeclarationOfMajoritySyntax ::= CHOICE
    *           {
    *             notYoungerThan [0] IMPLICIT INTEGER,
    *             fullAgeAtCountry [1] IMPLICIT SEQUENCE
    *             {
    *               fullAge BOOLEAN DEFAULT TRUE,
    *               country PrintableString (SIZE(2))
    *             }
    *             dateOfBirth [2] IMPLICIT GeneralizedTime
    *           }
    * </pre>
    *
    * @return an Asn1Object
    */
    public override Asn1Object ToAsn1Object()
    {
      return declaration;
    }

    public Choice Type
    {
      get { return (Choice) declaration.TagNo; }
    }

    /**
    * @return notYoungerThan if that's what we are, -1 otherwise
    */
    public virtual int NotYoungerThan
    {
      get
      {
        switch ((Choice) declaration.TagNo)
        {
          case Choice.NotYoungerThan:
            return DerInteger.GetInstance(declaration, false).Value.IntValue;
          default:
            return -1;
        }
      }
    }

    public virtual Asn1Sequence FullAgeAtCountry
    {
      get
      {
        switch ((Choice) declaration.TagNo)
        {
          case Choice.FullAgeAtCountry:
            return Asn1Sequence.GetInstance(declaration, false);
          default:
            return null;
        }
      }
    }

    public virtual DerGeneralizedTime DateOfBirth
    {
      get
      {
        switch ((Choice) declaration.TagNo)
        {
          case Choice.DateOfBirth:
            return DerGeneralizedTime.GetInstance(declaration, false);
          default:
            return null;
        }
      }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.