(content_block, tm_, privkey=None, pubkey=None)
Given a content_block, parse its data based on its content_binding.
    Decrypt the content_block if it is encrypted as x-pkcs7-mime.

    :param content_block: The TAXII content_block of data to be processed
    :type content_block: :class:`libtaxii.messages_10.ContentBlock`
    :param tm_: One of two possible libtaxii messages modules
    :type tm_:  :module:`libtaxii.messages` or :module:`libtaxii.messages_11`
    :param privkey: Path to a key file used for decryption of TAXII content
    :type privkey: string
    :param pubkey: Path to a certificate file used for decryption of TAXII content
    :type pubkey: string
    :returns: tuple: (parsed_data or None, error_message or None)
Given a content_block, parse its data based on its content_binding.
    Decrypt the content_block if it is encrypted as x-pkcs7-mime.
Given a content_block parse its data based on its content_binding . Decrypt the content_block if it is encrypted as x - pkcs7 - mime .
def parse_content_block(content_block, tm_, privkey=None, pubkey=None):
    """
    Given a content_block, parse its data based on its content_binding.
    Decrypt the content_block if it is encrypted as x-pkcs7-mime.

    :param content_block: The TAXII content_block of data to be processed
    :type content_block: :class:`libtaxii.messages_10.ContentBlock`
    :param tm_: One of two possible libtaxii messages modules
    :type tm_:  :module:`libtaxii.messages` or :module:`libtaxii.messages_11`
    :param privkey: Path to a key file used for decryption of TAXII content
    :type privkey: string
    :param pubkey: Path to a certificate file used for decryption of TAXII content
    :type pubkey: string
    :returns: tuple: (parsed_data or None, error_message or None)
    """
    stix_bindings = (t.CB_STIX_XML_10,
                     t.CB_STIX_XML_101,
                     t.CB_STIX_XML_11,
                     t.CB_STIX_XML_111,
                     t.CB_STIX_XML_12)

    binding = str(content_block.content_binding)
    if binding == 'application/x-pkcs7-mime':
        if not privkey or not pubkey:
            msg = "Encrypted data found, but certificate or key not provided"
            return (None, msg)

        inbuf = BIO.MemoryBuffer(BytesIO(content_block.content).read())
        s = SMIME.SMIME()
        try:
            s.load_key(str(privkey), str(pubkey))
            p7, data = SMIME.smime_load_pkcs7_bio(inbuf)
            buf = s.decrypt(p7)
        except SMIME.PKCS7_Error:
            return (None, "Decryption Failed")
        f = BytesIO(buf)
        new_block = f.read()
        f.close()
        return parse_content_block(tm_.ContentBlock.from_xml(new_block),
                                   tm_, privkey, pubkey)
    elif binding in stix_bindings:
        f = BytesIO(content_block.content)
        data = f.read()
        f.close()
        return (data, None)
    else:
        msg = 'Unknown content binding "%s"' % binding
        return (None, msg)
def parse_content_block ( content_block , tm_ , privkey = None , pubkey = None ) : stix_bindings = ( t . CB_STIX_XML_10 , t . CB_STIX_XML_101 , t . CB_STIX_XML_11 , t . CB_STIX_XML_111 , t . CB_STIX_XML_12 ) binding = str ( content_block . content_binding ) if binding == 'application/x-pkcs7-mime' : if not privkey or not pubkey : msg = "Encrypted data found, but certificate or key not provided" return ( None , msg ) inbuf = BIO . MemoryBuffer ( BytesIO ( content_block . content ) . read ( ) ) s = SMIME . SMIME ( ) try : s . load_key ( str ( privkey ) , str ( pubkey ) ) p7 , data = SMIME . smime_load_pkcs7_bio ( inbuf ) buf = s . decrypt ( p7 ) except SMIME . PKCS7_Error : return ( None , "Decryption Failed" ) f = BytesIO ( buf ) new_block = f . read ( ) f . close ( ) return parse_content_block ( tm_ . ContentBlock . from_xml ( new_block ) , tm_ , privkey , pubkey ) elif binding in stix_bindings : f = BytesIO ( content_block . content ) data = f . read ( ) f . close ( ) return ( data , None ) else : msg = 'Unknown content binding "%s"' % binding return ( None , msg )