Example usage for org.bouncycastle.asn1.cms ContentInfoParser ContentInfoParser

List of usage examples for org.bouncycastle.asn1.cms ContentInfoParser ContentInfoParser

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.cms ContentInfoParser ContentInfoParser.

Prototype

public ContentInfoParser(ASN1SequenceParser seq) throws IOException 

Source Link

Usage

From source file:mitm.common.security.cms.CMSContentTypeClassifier.java

License:Open Source License

/**
 * Returns the CMS content type of the provided sequence.
 * //  w  ww.  ja  v  a  2 s  . c  o  m
 * See RFC3852 for content types
 * 
 * @param sequenceParser
 * @return
 */
public static CMSContentType getContentType(ASN1SequenceParser sequenceParser) {
    CMSContentType contentType = CMSContentType.UNKNOWN;

    try {
        ContentInfoParser contentInfoParser = new ContentInfoParser(sequenceParser);

        DERObjectIdentifier derContentType = contentInfoParser.getContentType();

        if (CMSObjectIdentifiers.data.equals(derContentType)) {
            contentType = CMSContentType.DATA;
        } else if (CMSObjectIdentifiers.signedData.equals(derContentType)) {
            contentType = CMSContentType.SIGNEDDATA;
        } else if (CMSObjectIdentifiers.envelopedData.equals(derContentType)) {
            contentType = CMSContentType.ENVELOPEDDATA;
        } else if (CMSObjectIdentifiers.signedAndEnvelopedData.equals(derContentType)) {
            contentType = CMSContentType.SIGNEDANDENVELOPEDDATA;
        } else if (CMSObjectIdentifiers.digestedData.equals(derContentType)) {
            contentType = CMSContentType.DIGESTEDDATA;
        } else if (CMSObjectIdentifiers.encryptedData.equals(derContentType)) {
            contentType = CMSContentType.ENCRYPTEDDATA;
        } else if (CMSObjectIdentifiers.compressedData.equals(derContentType)) {
            contentType = CMSContentType.COMPRESSEDDATA;
        }
    } catch (IOException e) {
        logger.error("IOException retrieving CMS content type", e);
    }
    return contentType;
}