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

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Security.Certificates;
using Org.BouncyCastle.Utilities.IO;
using Org.BouncyCastle.X509;
using Org.BouncyCastle.X509.Store;

namespace Org.BouncyCastle.Cms{
    internal class CmsUtilities
    {
    // TODO Is there a .NET equivalent to this?
//    private static readonly Runtime RUNTIME = Runtime.getRuntime();

    internal static int MaximumMemory
    {
      get
      {
        // TODO Is there a .NET equivalent to this?
        long maxMem = int.MaxValue;//RUNTIME.maxMemory();

        if (maxMem > int.MaxValue)
        {
          return int.MaxValue;
        }

        return (int)maxMem;
      }
    }

    internal static ContentInfo ReadContentInfo(
      byte[] input)
    {
      // enforce limit checking as from a byte array
      return ReadContentInfo(new Asn1InputStream(input));
    }

    internal static ContentInfo ReadContentInfo(
      Stream input)
    {
      // enforce some limit checking
      return ReadContentInfo(new Asn1InputStream(input, MaximumMemory));
    }

    private static ContentInfo ReadContentInfo(
      Asn1InputStream aIn)
    {
      try
      {
        return ContentInfo.GetInstance(aIn.ReadObject());
      }
      catch (IOException e)
      {
        throw new CmsException("IOException reading content.", e);
      }
      catch (InvalidCastException e)
      {
        throw new CmsException("Malformed content.", e);
      }
      catch (ArgumentException e)
      {
        throw new CmsException("Malformed content.", e);
      }
    }

    public static byte[] StreamToByteArray(
            Stream inStream)
        {
      return Streams.ReadAll(inStream);
        }

    public static byte[] StreamToByteArray(
            Stream  inStream,
      int    limit)
        {
      return Streams.ReadAllLimited(inStream, limit);
        }

    public static IList GetCertificatesFromStore(
      IX509Store certStore)
    {
      try
      {
        IList certs = new ArrayList();

        if (certStore != null)
        {
          foreach (X509Certificate c in certStore.GetMatches(null))
          {
            certs.Add(
              X509CertificateStructure.GetInstance(
                Asn1Object.FromByteArray(c.GetEncoded())));
          }
        }

        return certs;
      }
      catch (CertificateEncodingException e)
      {
        throw new CmsException("error encoding certs", e);
      }
      catch (Exception e)
      {
        throw new CmsException("error processing certs", e);
      }
    }

    public static IList GetCrlsFromStore(
      IX509Store crlStore)
    {
      try
      {
        IList crls = new ArrayList();

        if (crlStore != null)
        {
          foreach (X509Crl c in crlStore.GetMatches(null))
          {
            crls.Add(
              CertificateList.GetInstance(
                Asn1Object.FromByteArray(c.GetEncoded())));
          }
        }

        return crls;
      }
      catch (CrlException e)
      {
        throw new CmsException("error encoding crls", e);
      }
      catch (Exception e)
      {
        throw new CmsException("error processing crls", e);
      }
    }

    public static Asn1Set CreateBerSetFromList(
      IList berObjects)
    {
      Asn1EncodableVector v = new Asn1EncodableVector();

      foreach (Asn1Encodable ae in berObjects)
      {
        v.Add(ae);
      }

      return new BerSet(v);
    }

    public static Asn1Set CreateDerSetFromList(
      IList derObjects)
    {
      Asn1EncodableVector v = new Asn1EncodableVector();

      foreach (Asn1Encodable ae in derObjects)
      {
        v.Add(ae);
      }

      return new DerSet(v);
    }

    internal static Stream CreateBerOctetOutputStream(Stream s, int tagNo, bool isExplicit, int bufferSize)
    {
      BerOctetStringGenerator octGen = new BerOctetStringGenerator(s, tagNo, isExplicit);
      return octGen.GetOctetOutputStream(bufferSize);
    }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.