Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions libmich/asn1/PER.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ class PER(ASN1.ASN1Codec):
# CODEC customizations:
# to build dictionnary for encoded ENUMERATED, CHOICE, ...
_ENUM_BUILD_DICT = True

# add specific option in order to choose displaying ASN1 code or string
# label for enum and choice type
_DISPLAY_LABEL = True

# to pad BIT STRING with CONTAINING object to octet-align it
_U_BITSTR_CONTAIN_PAD = True
#
Expand Down Expand Up @@ -1413,7 +1418,12 @@ def decode_enum(self, obj, buf):
if ind >= root_num:
raise(ASN1_PER_DECODER('%s: invalid enumerated index (%s)'\
% (obj.get_fullname(), ind)))
obj._val = obj._cont.keys()[ind]

if self._DISPLAY_LABEL :
obj._val = obj._cont.keys()[ind]
else:
obj._val = obj._cont[obj._cont.keys()[ind]]

return buf

#--------------------------------------------------------------------------#
Expand Down Expand Up @@ -1637,6 +1647,8 @@ def decode_choice(self, obj, buf):
return self._decode_choice_ext(obj, buf)
else:
root_names = obj._cont.keys()

idx = 0
#
# for CHOICE in the root
# 3) get choice's name
Expand Down Expand Up @@ -1664,6 +1676,7 @@ def decode_choice(self, obj, buf):
% (obj.get_fullname(), ind._val)))
cho_name = obj._cont.keys()[ind._val]
cho = obj._cont[cho_name]
idx = ind._val
#
# 3bis) get potential padding
#if self.is_aligned():
Expand All @@ -1674,7 +1687,11 @@ def decode_choice(self, obj, buf):
obj._msg.append(cho._msg)
self._off += cho._msg.bit_len()
#
obj._val = (cho_name, cho._val)
if self._DISPLAY_LABEL:
obj._val = (cho_name, cho._val)
else:
obj._val = (idx, cho._val)

# clean up content object
cho._val = None
return buf
Expand Down