def __assemble_hmac_block(self, content, key):
""" Produce HMAC block ASN.1 structure (MPHMACContainer)
@developer: vsmysle
:param content: string DER-encoded content generate HMAC of and
encapsulate into HMAC FLOD block
:param key: bytes key to use for HMAC generation
:return: DER-encoded ASN.1 structure that encapsulates HMAC
block
"""
# TODO: add exceptions
self.logger.debug("producing HMAC block with ASN.1 structure")
# calculating hmac digest of content
digest = self.__generate_hmac(content, key)
# oid for SHA1 hash function
oid = const.SHA1_OID
# creating instance of AlgorithmIdentifier class
ai = asn1_dec.AlgorithmIdentifier()
# setting corresponding parameters
ai['algorithm'] = oid
ai['parameters'] = univ.Null()
# creating instance of MPHMACContainer class
hmac_block = asn1_dec.MPHMACContainer()
# setting corresponding parameters
hmac_block['digestAlgorithm'] = ai
hmac_block['digest'] = digest
return hmac_block
评论列表
文章目录