Commit 24144b0f authored by Sam Rushing's avatar Sam Rushing

more careful segregation of UNIVERSAL/STRUCTURED.

parent 1cbbf5df
...@@ -626,8 +626,6 @@ cdef object _decode (unsigned char * s, long * pos, long eos, bint just_tlv): ...@@ -626,8 +626,6 @@ cdef object _decode (unsigned char * s, long * pos, long eos, bint just_tlv):
# 1) get tag # 1) get tag
tag = _decode_tag (s, pos, eos, &flags) tag = _decode_tag (s, pos, eos, &flags)
# 2) get length # 2) get length
print 'tag', tag
print 'flags', flags
check_pos (pos, eos) check_pos (pos, eos)
if s[pos[0]] < 0x80: if s[pos[0]] < 0x80:
# one-byte length # one-byte length
...@@ -656,7 +654,6 @@ cdef object _decode (unsigned char * s, long * pos, long eos, bint just_tlv): ...@@ -656,7 +654,6 @@ cdef object _decode (unsigned char * s, long * pos, long eos, bint just_tlv):
elif just_tlv: elif just_tlv:
return (tag, flags, length) return (tag, flags, length)
elif flags == FLAGS_UNIVERSAL: elif flags == FLAGS_UNIVERSAL:
# these are builtin types
if tag == TAGS_OCTET_STRING: if tag == TAGS_OCTET_STRING:
return decode_string (s, pos, length) return decode_string (s, pos, length)
elif tag == TAGS_UTF8STRING: elif tag == TAGS_UTF8STRING:
...@@ -668,10 +665,6 @@ cdef object _decode (unsigned char * s, long * pos, long eos, bint just_tlv): ...@@ -668,10 +665,6 @@ cdef object _decode (unsigned char * s, long * pos, long eos, bint just_tlv):
return decode_integer (s, pos, length) return decode_integer (s, pos, length)
elif tag == TAGS_BOOLEAN: elif tag == TAGS_BOOLEAN:
return decode_boolean (s, pos, length) return decode_boolean (s, pos, length)
elif tag == TAGS_SEQUENCE:
return decode_structured (s, pos, length)
elif tag == TAGS_SET:
return decode_structured (s, pos, length)
elif tag == TAGS_ENUMERATED: elif tag == TAGS_ENUMERATED:
return decode_integer (s, pos, length) return decode_integer (s, pos, length)
elif tag == TAGS_OBJID: elif tag == TAGS_OBJID:
...@@ -680,24 +673,26 @@ cdef object _decode (unsigned char * s, long * pos, long eos, bint just_tlv): ...@@ -680,24 +673,26 @@ cdef object _decode (unsigned char * s, long * pos, long eos, bint just_tlv):
return (kind_bitstring, decode_bitstring (s, pos, length)) return (kind_bitstring, decode_bitstring (s, pos, length))
elif tag == TAGS_NULL: elif tag == TAGS_NULL:
return None return None
elif TAG_TABLE.has_key (tag):
return (TAG_TABLE[tag], tag, decode_raw (s, pos, length))
else: else:
return (kind_unknown, tag, decode_raw (s, pos, length)) return (kind_unknown, tag, decode_raw (s, pos, length))
else: else:
if flags & FLAGS_CONTEXT: if tag == TAGS_SEQUENCE and flags == FLAGS_STRUCTURED:
# union discriminator return decode_structured (s, pos, length)
kind = kind_context elif tag == TAGS_SET and flags == FLAGS_STRUCTURED:
elif flags & FLAGS_APPLICATION: return decode_structured (s, pos, length)
# user type tags
kind = kind_application
elif TAG_TABLE.has_key (tag):
# unsupported
kind = TAG_TABLE[tag]
else:
kind = kind_unknown
if flags & FLAGS_STRUCTURED:
return (kind, tag, decode_structured (s, pos, length))
else: else:
return (kind, tag, decode_raw (s, pos, length)) if flags & FLAGS_CONTEXT:
kind = kind_context
elif flags & FLAGS_APPLICATION:
kind = kind_application
else:
kind = kind_unknown
if flags & FLAGS_STRUCTURED:
return (kind, tag, decode_structured (s, pos, length))
else:
return (kind, tag, decode_raw (s, pos, length))
def decode (bytes s, long pos=0, just_tlv=0): def decode (bytes s, long pos=0, just_tlv=0):
return _decode ( return _decode (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment