Protocol Utilities

icspacket.proto.iso_pres.util.build_connect_ppdu(user_data: bytes, pres_context_id: int | None = None, *, calling_presentation_selector: bytes | None = None, called_presentation_selector: bytes | None = None, use_version_1: bool = False, requirements: Presentation_requirements | None = None, pres_context_items: list[Member_TYPE] | None = None) CP_type[source]

Construct a CP-type (CONNECT PPDU) for initiating a COPP session.

Assembles a presentation-layer connection request including version, selectors, requirements, context definitions, and user data (ASN.1 payloads wrapped in PDV-lists).

Parameters:
  • user_data (bytes) – Encoded ASN.1 payload to embed into the user data field.

  • pres_context_id (int | None) – Identifier for the presentation context associated with the user_data. Defaults to 1 if not provided.

  • calling_presentation_selector (bytes | None) – Optional selector identifying the calling presentation entity.

  • called_presentation_selector (bytes | None) – Optional selector identifying the called presentation entity.

  • use_version_1 (bool) – If True, explicitly requests version 1 of the Presentation protocol. Defaults to False (version negotiation left open).

  • requirements (Presentation_requirements | None) – Presentation requirements field. If not set, a default empty Presentation_requirements instance is used.

  • pres_context_items (list[PresentaionContextItem] | None) – Optional list of presentation context definitions (e.g., abstract syntax + transfer syntax pairs).

Returns:

A fully-formed CP-type connect PDU.

Return type:

CP_type

Note

This constructs only a normal-mode connect PDU. X.226 also defines other connection modes and negotiation structures that may be added in future extensions.

icspacket.proto.iso_pres.util.build_user_data(user_data: bytes, presentation_context_id: int) User_data[source]

Build a User_data structure wrapping raw ASN.1 data.

This creates a PDV-list entry with the given presentation context identifier, assigning the payload as a single-ASN1-type.

Parameters:
  • user_data (bytes) – Encoded ASN.1 payload to embed.

  • presentation_context_id (int) – Identifier for the presentation context under which the payload is interpreted.

Returns:

A User_data element containing fully encoded data.

Return type:

User_data

Note

This helper assumes single ASN.1 type encoding. If multiple PDVs or different encodings (octet-aligned, arbitrary) are needed, the construction must be extended.

icspacket.proto.iso_pres.util.user_data_get_single_asn1(user_data: User_data, *, context: dict[int, type] | None = None) Any[source]

Extract and decode a single ASN.1 object from User_data.

Validates that the input is fully encoded, contains exactly one PDV-list, and that the encoding is of type single-ASN1-type. The payload is then decoded using the ASN.1 class mapped to the presentation context identifier.

Parameters:
  • user_data (User_data) – The presentation user data structure to inspect.

  • context (dict[int, type[Any]] | None) – Mapping of presentation context identifiers to ASN.1 classes that implement a ber_decode method. If not provided, defaults to an empty map (error if lookup fails).

Raises:

ValueError – If the data is not fully encoded, contains multiple PDVs, has an unexpected data type, or references an unknown context id.

Returns:

The decoded ASN.1 object.

Return type:

Any

Warning

This function assumes that the context dictionary correctly maps presentation context identifiers to decodable ASN.1 types. Incorrect mappings may lead to misinterpretation of payloads.