eerimoq / asn1tools

ASN.1 parsing, encoding and decoding.
MIT License
289 stars 98 forks source link

Missing support for BCDString in BER #145

Open Jelmoh opened 2 years ago

Jelmoh commented 2 years ago

Hi,

I am trying to decode a BER encoded file using a specification which also specifies several fields as being of BCDString type. The specification provides the following comments for this type:

-- The BCDString data type (Binary Coded Decimal String) is used to represent -- several digits from 0 through 9, a, b, c, d, e. -- Two digits are encoded per octet. The four leftmost bits of the octet represent -- the first digit while the four remaining bits represent the following digit. -- A single f must be used as a filler when the total number of digits to be -- encoded is odd. -- No other filler is allowed.

And an example of one of the fields as it is in the specification: Imsi ::= [APPLICATION 129] BCDString --(SIZE(3..8))

The provides SIZE value differs per field.

I am currently using the following code to decode these fields in my own script:

for char in field_value:
    for val in (char >> 4, char & 0xF):
        if val == 0xF:
            return
        yield str(val)

Let me know if this is enough information to go on, if not, which information do you need?

Cheers, Jelmoh

eerimoq commented 2 years ago

Hi!

I don't work on this project actively anymore. Feel free to implement support for it yourself and submit a PR and I can merge.

Thanks, Erik