Skip to content

Fix: Support BER long-form length encoding in AARE parsing - #115

Open
marco92 wants to merge 1 commit into
u9n:masterfrom
marco92:fix-BER-length-long-form
Open

Fix: Support BER long-form length encoding in AARE parsing#115
marco92 wants to merge 1 commit into
u9n:masterfrom
marco92:fix-BER-length-long-form

Conversation

@marco92

@marco92 marco92 commented Apr 7, 2026

Copy link
Copy Markdown

In the Application Association Response (AARE, aare.py), only ASN.1 BER short-form length encoding was previously supported. This caused parsing to fail for responses using long-form length encoding.

This change adds automatic detection of BER short-form vs long-form length encoding and correctly parses the length in both cases.

Reference (ASN.1 BER length encoding):
https://www.oss.com/asn1/resources/asn1-made-simple/asn1-quick-reference/basic-encoding-rules.html

This improves compatibility with DLMS/COSEM devices that encode AARE APDUs using BER long-form lengths.

Issue observed on "Kamstrup OMNIA® e-meter" and fix tested successfully.

@Krolken

Krolken commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Nice catch. Are you using Public keys?

We have a simillar function for x-adr:

def get_axdr_length(data: bytearray):

It would be nice if you could open an issue and provide some sample PDUs so I can write tests for it. I should also implement the same handling on all ASCE-services.

@marco92

marco92 commented Apr 7, 2026

Copy link
Copy Markdown
Author

@Krolken I'm using HLS GMAC with symmetric keys. I created the following issue and also added HDLC PDUs:
#116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants