python 2.7 - Pyasn1 how do decoder.decode works? -


i have little part of code:

from pyasn1.type import univ pyasn1.codec.ber import decoder  decoder.decode(binary_file.read(5)) 

my binary_file variable it's particular binary file encoded (cdr)

if try decode readed part gives me error:

pyasn1.error.pyasn1error: [128:0:0]+[128:32:79] not in asn1spec: none 

how can fix?

unless decoding data structure contains base asn.1 types (such integer, sequence etc.), need pass top-level asn.1 data structure object decoder. way decoder match custom tags (of tlv tuples in ber/der/cer serialization) same tags present in data structure object. example:

custom_int_type = integer().subtype(implicittag=tag(tagclasscontext, tagformatsimple, 40))  custom_int_instance = custom_int_type.clone(12345) serialization = encode(custom_int_instance)  # fail on unknown custom asn.1 type tag custom_int_instance, rest_of_serialization = decode(serialization)  # succeed custom asn.1 type (containing tag) provided custom_int_instance, rest_of_serialization = decode(serialization, asn1spec=custom_int_type) 

here link pyasn1 documentation on decoders.

to pass asn.1 grammar pyasn1 decoder have first turn grammar pyasn1/python tree of objects. one-time operation can automated asn1late tool.

my other concern possibly reading fraction of serialized data (5 octets). valid operation if data serialized using "indefinite length encoding mode", otherwise decoder may fail on insufficient input.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -