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

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

Introduction

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

Prototype

public ASN1ObjectIdentifier getContentType() 

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.
 * /*from www.  j  a va  2 s .  c om*/
 * 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;
}