def _ParseOpusInfo(self, opus_info_asn1):
spc_opus_info, rest = decoder.decode(opus_info_asn1,
asn1Spec=spc.SpcSpOpusInfo())
if rest: raise Asn1Error('Extra unparsed content.')
if spc_opus_info['programName']:
# According to spec, this should always be a Unicode string. However,
# the ASN.1 syntax allows both ASCII and Unicode. So, let's be careful.
opus_prog_name = spc_opus_info['programName']
uni_name = opus_prog_name['unicode']
ascii_name = opus_prog_name['ascii']
if ascii_name and uni_name:
# WTF? This is supposed to be a CHOICE
raise Asn1Error('Both elements of a choice are present.')
elif uni_name:
program_name = str(uni_name).decode('utf-16-be')
elif ascii_name:
program_name = str(ascii_name)
else:
raise Asn1Error('No element of opusInfo choice is present.')
else:
# According to spec, there should always be a program name,
# and be it zero-length. But let's be gentle, since ASN.1 marks
# this field als optional.
program_name = None
# Again, according to Authenticode spec, the moreInfo field should always
# be there and point to an ASCII string with a URL.
if spc_opus_info['moreInfo']:
more_info = spc_opus_info['moreInfo']
if more_info['url']:
more_info_link = str(more_info['url'])
else:
raise Asn1Error('Expected a URL in moreInfo.')
else:
more_info_link = None
return program_name, more_info_link
评论列表
文章目录