x690¶
Encode and decode ASN.1 values in BER (ITU-T X.690).
decode() reads one value from a bytes object and returns it with the
index of the next value:
>>> from x690 import decode
>>> decode(b"")
(Integer(1), 3)
The type classes live in x690.types. The usage guide in the
documentation covers streams, enforce_type and strict.
-
x690.decode(data, start_index=
0, enforce_type=None, strict=False, types=())¶ Convert a X.690 bytes object into a Python instance, and the location of the next object.
Given a
bytesobject and any start-index, inspects and parses the octets starting at the given index (as many as required) to determine variable type (and corresponding Python class), and length. That class is then used to parse the object located indataat the given index. The location of the start of the next (subsequent) object is also determined.The return value is a tuple with the decoded object and the start-index of the next object.
Example:
>>> data = b'\x02\x01\x05\x11' >>> decode(data) (Integer(5), 3) >>> data = b'some-skippable-bytes\x02\x01\x05\x11' >>> decode(data, 20) (Integer(5), 23)- Parameters:¶
- data¶
The buffer to read from. It is never copied.
- start_index=
0¶ The position of the value in data.
- enforce_type=
None¶ Raise
UnexpectedTypeunless the value is an instance of this class.- strict=
False¶ Raise
IncompleteDecodingif data is left after the value.- types=
()¶ Classes to try before the global registry for this value, as
CHILD_TYPESdoes for the items of a constructed type. Use it to decode a context-specific value on its own.
- Return type:¶
- Returns:¶
The value and the index of the next value.