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

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Cmp;
using Org.BouncyCastle.Asn1.Tsp;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;

namespace Org.BouncyCastle.Tsp{
  /**
   * Base class for an RFC 3161 Time Stamp Request.
   */
  public class TimeStampRequest
    : X509ExtensionBase
  {
    private TimeStampReq req;

    public TimeStampRequest(
      TimeStampReq req)
    {
      this.req = req;
    }

    /**
    * Create a TimeStampRequest from the past in byte array.
    *
    * @param req byte array containing the request.
    * @throws IOException if the request is malformed.
    */
    public TimeStampRequest(
      byte[] req)
      : this(new Asn1InputStream(req))
    {
    }

    /**
    * Create a TimeStampRequest from the past in input stream.
    *
    * @param in input stream containing the request.
    * @throws IOException if the request is malformed.
    */
    public TimeStampRequest(
      Stream input)
      : this(new Asn1InputStream(input))
    {
    }

    private TimeStampRequest(
      Asn1InputStream str)
    {
      try
      {
        this.req = TimeStampReq.GetInstance(str.ReadObject());
      }
      catch (InvalidCastException e)
      {
        throw new IOException("malformed request: " + e);
      }
      catch (ArgumentException e)
      {
        throw new IOException("malformed request: " + e);
      }
    }

    public int Version
    {
      get { return req.Version.Value.IntValue; }
    }

    public string MessageImprintAlgOid
    {
      get { return req.MessageImprint.HashAlgorithm.ObjectID.Id; }
    }

    public byte[] GetMessageImprintDigest()
    {
      return req.MessageImprint.GetHashedMessage();
    }

    public string ReqPolicy
    {
      get
      {
        return req.ReqPolicy == null
          ?  null
          :  req.ReqPolicy.Id;
      }
    }

    public BigInteger Nonce
    {
      get
      {
        return req.Nonce == null
          ?  null
          :  req.Nonce.Value;
      }
    }

    public bool CertReq
    {
      get
      {
        return req.CertReq == null
          ?  false
          :  req.CertReq.IsTrue;
      }
    }

    /**
    * Validate the timestamp request, checking the digest to see if it is of an
    * accepted type and whether it is of the correct length for the algorithm specified.
    *
    * @param algorithms a set of string OIDS giving accepted algorithms.
    * @param policies if non-null a set of policies we are willing to sign under.
    * @param extensions if non-null a set of extensions we are willing to accept.
    * @throws TspException if the request is invalid, or processing fails.
    */
    public void Validate(
      IList algorithms,
      IList policies,
      IList extensions)
    {
      if (!algorithms.Contains(this.MessageImprintAlgOid))
      {
        throw new TspValidationException("request contains unknown algorithm.", PkiFailureInfo.BadAlg);
      }

      if (policies != null && this.ReqPolicy != null && !policies.Contains(this.ReqPolicy))
      {
        throw new TspValidationException("request contains unknown policy.", PkiFailureInfo.UnacceptedPolicy);
      }

      if (this.Extensions != null && extensions != null)
      {
        foreach (DerObjectIdentifier oid in this.Extensions.ExtensionOids)
        {
          if (!extensions.Contains(oid.Id))
          {
            throw new TspValidationException("request contains unknown extension.",
              PkiFailureInfo.UnacceptedExtension);
          }
        }
      }

      int digestLength = TspUtil.GetDigestLength(this.MessageImprintAlgOid);

      if (digestLength != this.GetMessageImprintDigest().Length)
      {
        throw new TspValidationException("imprint digest the wrong length.",
          PkiFailureInfo.BadDataFormat);
      }
    }

    /**
     * return the ASN.1 encoded representation of this object.
     */
    public byte[] GetEncoded()
    {
      return req.GetEncoded();
    }

    internal X509Extensions Extensions
    {
      get { return req.Extensions; }
    }

    protected override X509Extensions GetX509Extensions()
    {
      return Extensions;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.