FileDocCategorySizeDatePackage
CMSUtils.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)5290Wed Oct 01 10:55:30 BST 2008org.bouncycastle.cms

CMSUtils

public class CMSUtils extends Object

Fields Summary
private static final Runtime
RUNTIME
Constructors Summary
Methods Summary
static org.bouncycastle.asn1.ASN1SetcreateBerSetFromList(java.util.List derObjects)

        ASN1EncodableVector v = new ASN1EncodableVector();

        for (Iterator it = derObjects.iterator(); it.hasNext();)
        {
            v.add((DEREncodable)it.next());
        }

        return new BERSet(v);
    
static org.bouncycastle.asn1.ASN1SetcreateDerSetFromList(java.util.List derObjects)

        ASN1EncodableVector v = new ASN1EncodableVector();

        for (Iterator it = derObjects.iterator(); it.hasNext();)
        {
            v.add((DEREncodable)it.next());
        }

        return new DERSet(v);
    
static java.util.ListgetCRLsFromStore(java.security.cert.CertStore certStore)

        List crls = new ArrayList();

        try
        {
            for (Iterator it = certStore.getCRLs(null).iterator(); it.hasNext();)
            {
                X509CRL c = (X509CRL)it.next();

                crls.add(CertificateList.getInstance(ASN1Object.fromByteArray(c.getEncoded())));
            }

            return crls;
        }
        catch (IllegalArgumentException e)
        {
            throw new CMSException("error processing crls", e);
        }
        catch (IOException e)
        {
            throw new CMSException("error processing crls", e);
        }
        catch (CRLException e)
        {
            throw new CMSException("error encoding crls", e);
        }
    
static java.util.ListgetCertificatesFromStore(java.security.cert.CertStore certStore)

        List certs = new ArrayList();

        try
        {
            for (Iterator it = certStore.getCertificates(null).iterator(); it.hasNext();)
            {
                X509Certificate c = (X509Certificate)it.next();

                certs.add(X509CertificateStructure.getInstance(
                                                       ASN1Object.fromByteArray(c.getEncoded())));
            }

            return certs;
        }
        catch (IllegalArgumentException e)
        {
            throw new CMSException("error processing certs", e);
        }
        catch (IOException e)
        {
            throw new CMSException("error processing certs", e);
        }
        catch (CertificateEncodingException e)
        {
            throw new CMSException("error encoding certs", e);
        }
    
static intgetMaximumMemory()

    
      
    
        long maxMem = RUNTIME.maxMemory();
        
        if (maxMem > Integer.MAX_VALUE)
        {
            return Integer.MAX_VALUE;
        }
        
        return (int)maxMem;
    
public static java.security.ProvidergetProvider(java.lang.String providerName)

        if (providerName != null)
        {
            Provider prov = Security.getProvider(providerName);

            if (prov != null)
            {
                return prov;
            }

            throw new NoSuchProviderException("provider " + providerName + " not found.");
        }

        return null; 
    
static org.bouncycastle.asn1.cms.ContentInforeadContentInfo(byte[] input)

        // enforce limit checking as from a byte array
        return readContentInfo(new ASN1InputStream(input));
    
static org.bouncycastle.asn1.cms.ContentInforeadContentInfo(java.io.InputStream input)

        // enforce some limit checking
        return readContentInfo(new ASN1InputStream(input, getMaximumMemory()));
    
private static org.bouncycastle.asn1.cms.ContentInforeadContentInfo(org.bouncycastle.asn1.ASN1InputStream in)

        try
        {
            return ContentInfo.getInstance(in.readObject());
        }
        catch (IOException e)
        {
            throw new CMSException("IOException reading content.", e);
        }
        catch (ClassCastException e)
        {
            throw new CMSException("Malformed content.", e);
        }
        catch (IllegalArgumentException e)
        {
            throw new CMSException("Malformed content.", e);
        }
    
public static byte[]streamToByteArray(java.io.InputStream in)

        return Streams.readAll(in);